def cmd_server(self,window,server,params): if len(params) <= 0: help_list.grab_value("server") d = {} if len(params) == 1: d["server"] = params[0] if len(params) == 2: d["server"] = params[0] if type(params[1]) == int: d["port"] = params[1] elif type(params[1]) == str: try: d["port"] = int(params[1]) try: nickname = d['nickname'] = self.config["nickname"] except KeyError: result = dialogs.ask_nickname() if not result: window.server_event("Nickname defaulting to 'irc'.") nickname = d['nickname'] = 'irc' else: nickname = d['nickname'] = result except ValueError: nickname = d["nickname"] = params[1] d["port"] = 6667 if server.is_connected(): s = server.new_status_window() s.connect("server", window, **d) server.host = server s.statuswindow.enable_checking() channels = params[3:] if not channels: return server.connection.join(*channels) else: server.connect("server", window, **d) server.host = server # Ensures checking for new events is enabled. server.statuswindow.enable_checking() channels = params[3:] if not channels: return server.connection.join(*channels)
def check_events(self): """Redirects all received events to the correct windows.""" # Print events and display them in the rigth windows. for e in self.get_events(): etype = e.eventtype() # Skip raw messages. if etype == "all_raw_messages": continue elif etype == "action": target = e.target() source = irclib.nm_to_n(e.source()) action = e.arguments() if len(action) > 1: action = action[1:] action = " ".join(action) window = self.get_channel_window(target) if not window: continue to_server = "* %s %s" % (source, action) window.server_event(to_server) # Events to display in the status window. elif etype == "welcome": self.host = e.source() self.statuswindow.set_caption(self.host) for arg in e.arguments(): self.statuswindow.server_event(arg) elif etype == "privnotice": text = "" source = e.source() prefixes = ["Nick", "Memo", "Chan"] for prefix in prefixes: if source and source.startswith("%sServ" % prefix): text = "%sServ: %s" % (prefix, e.arguments()[0]) self.statuswindow.server_event(text) else: self.statuswindow.server_event(e.arguments()[0]) elif etype == "umode": self.statuswindow.server_event("umode: " + e.arguments()[0]) elif etype in ("motd", "motdstart", "endofmotd"): self.statuswindow.server_event(e.arguments()[0]) elif etype in ("info", "endofinfo"): self.statuswindow.server_event(e.arguments()[0]) # Events to display in the channel windows. elif etype in ("topic", "nochanmodes"): args = e.arguments() if len(args) > 1: chan = args.pop(0) # Channel name where the message comes # from. topic = [] # store topic in here # find out the corresponding window window = self.get_channel_window(chan) if window: args = " ".join(args) if etype == "topic": text = "Topic for %s is: %s" % (chan, args) else: text = "[%s] %s" % (etype, args) if etype == "topic": topic.append(text) else: window.server_event(text) else: window = self.get_channel_window("CURRENT") args = " ".join(args) if etype == "topic": text = "Topic for %s is: %s" % (chan, args) else: text = "[%s] %s" % (etype, args) topic.append(text) else: window = self.get_channel_window(e.target()) if window: window.server_event( "%s has changed the topic of %s to: %s" % (e.source().split("!")[0], e.target(), args[0]) ) elif etype == "topicinfo": sender = e.arguments()[1] timeago = int(e.arguments()[2]) date = time.asctime(time.gmtime(timeago)) window = self.get_channel_window(e.arguments()[0]) if window: text = "Topic for %s set by %s on %s" % (e.arguments()[0], sender, date) topic.append(text) window.server_event("\n".join(topic)) topic = [] elif etype == "namreply": chan = e.arguments()[1] window = self.get_channel_window(chan) if window: users = e.arguments()[2].split() window.users(users) elif etype == "pubmsg": chan = e.target() window = self.get_channel_window(chan) if window: source = e.source().split("!")[0] window.add_message(e.arguments()[0], source) elif etype == "privmsg": source = e.source().split("!")[0] target = e.target() if irclib.is_channel(target): win = self.get_channel_window(target) if win: win.add_message(text, source, target) else: self.statuswindow.server_event(text) elif etype == "join": chan = e.target() src = e.source() if irclib.nm_to_n(src) == self.connection.get_nickname(): self.new_channel_window(chan) # Ensures we get the topic info, users list,... self.connection.topic(chan) self.connection.names([chan]) return window = self.get_channel_window(chan) if window: source = irclib.nm_to_n(src) text = "%s has joined %s" % (source, chan) window.server_event(text) window.users([source]) elif etype == "part": chan = e.target() src = e.source() arguments = e.arguments() nickname = irclib.nm_to_n(src) window = self.get_channel_window(chan) if nickname == self.connection.get_nickname(): if window: self.remove_channel_window(chan) return if window: args = " ".join(arguments) if not args: text = "%s (%s) has left %s" % (nickname, src, chan) else: text = "%s (%s) has left %s: %s" % (nickname, src, chan, args) window.server_event(text) window.del_user([nickname]) elif etype == "quit": # Informs each channel that the user has quit. for chan in self.channels: chan.user_quit(e) elif etype == "nicknameinuse": nickname = e.arguments()[0] try: self.connection.nick(self.config["secondary_nickname"]) except KeyError: result = dialogs.ask_nickname(nickname) if result: self.connection.nick(result) else: self.connection.nick(nickname + "_") text = "%s: %s" % (nickname, e.arguments()[1]) self.statuswindow.server_event(text) elif etype == "nick": for chan in self.channels: chan.nick_changed(e) elif etype == "error": pass elif etype == "disconnect": text = "%s (%s)" % (e.arguments()[0], e.source()) self.statuswindow.server_event(text) self.statuswindow.evt_disconnect()