def cmd_whois(currentServer, currentChannel, args): """ Query a user's identity on the current server. Usage: /whois <user mask> """ def whois_cb(time, server, nick, message): """ message = "" => end of whois """ server_tab = gui.tabs.search_tab(server) if message: server_tab.write(time, _(u"[%(nick)s] %(message)s") % { "nick": markup.escape(nick), "message": markup.escape(message) }) else: server_tab.write(time, _(u"[%(nick)s] End of whois.") % { "nick": markup.escape(nick) }) # begin of command function if not args: return gui.mgmt.myPrint("No server activated.") def handler(time, server, nick, message): if message: whois_cb(time, server, nick, message) else: signals.disconnect_signal("whois", handler) signals.connect_signal("whois", handler) sushi.whois(currentServer.name, args[0])
def connect_signal(self, signal, func): if signals.connect_signal(signal, func): if self.__signals.has_key(signal): self.__signals[signal].append(func) else: self.__signals[signal] = [func] return True return False
def maki_connected_cb(sushi): global init if init == False: # Message-Signals connect_signal("message", userMessage_cb) connect_signal("notice", userNotice_cb) connect_signal("action", userAction_cb) connect_signal("away_message", userAwayMessage_cb) connect_signal("ctcp", userCTCP_cb) connect_signal("error", userError_cb) # action signals connect_signal("part", userPart_cb) connect_signal("join", userJoin_cb) connect_signal("names", userNames_cb) connect_signal("quit", userQuit_cb) connect_signal("kick", userKick_cb) connect_signal("nick", userNick_cb) connect_signal("user_away", userAway_cb) connect_signal("mode", userMode_cb) connect_signal("oper", userOper_cb) # Server-Signals connect_signal("connect", serverConnect_cb) connect_signal("connected", serverConnected_cb) connect_signal("motd", serverMOTD_cb) connect_signal("dcc_send", dcc_send_cb) # Channel-Signals connect_signal("topic", channelTopic_cb) connect_signal("banlist", channelBanlist_cb) # Maki signals connect_signal("shutdown", makiShutdown_cb) init = True _add_servers()
def cmd_list(serverTab, channelTab, args): """ Start a channel listing. If channel is given, only the channel is listed. Usage: /list [<channel>] """ import gobject def channelList_cb(time, server, channel, users, topic): """ Signal for /list command. Prints content of the listing. """ self = code.init_function_attrs(channelList_cb, _text=[], _line=0, _tab=gui.tabs.search_tab(server)) def print_listing(): self._tab.write_raw("<br/>".join(self._text)) self._text = [] self._line = 0 return False if not channel and not topic and users == -1: # listing ended, reset variables def print_end(): self._tab.write(time, "End of list.") return False if self._line > 0: # print rest gobject.idle_add(print_listing) gobject.idle_add(print_end) code.reset_function_attrs(channelList_cb) signals.disconnect_signal("list", channelList_cb) else: self._text.append(("• <b>%s</b><br/>\t%d "+_("User")+"<br/>"+ "\t"+_("Topic")+": \"%s\"") % ( markup.escape(channel), users, markup.escape(topic))) self._line += 1 if self._line == 10: gobject.idle_add(print_listing) # cmd_list: # make the callback accessible for cmd_stop_list cmd_list.list_cb = channelList_cb if not serverTab: return gui.mgmt.myPrint("Could not determine server.") try: # channel specific listing? channel = args[0] except IndexError: # start a complete list.. channel = "" serverTab.write(time.time(), "Start of list.") signals.connect_signal("list", channelList_cb) sushi.list(serverTab.name, channel)
def request(server,channel): """ print the name listing in the queried tab (if it's active) or in the current tab """ def names_cb(time, server, channel, nicks, prefixes): self = names_cb def print_message(message): if self.tab.is_active(): # print in the channel we query self.tab.write(time, message, "action") elif self.tab.is_server(): self.tab.current_write(time, message, "action") else: # print in the current channel self.tab.server.current_write(time, message, "action") if self.first: print_message(_("• Begin of names")) self.first = False if not nicks: # eol signals.disconnect_signal("names", self) print_message(_("• End of names")) else: max_nicklen = max([len(n)+len(p) for (p,n) in self.tab.nickList.get_nicks_mode()]) message = "" for i in xrange(len(nicks)): nick_color = color.get_nick_color(nicks[i]) c_start = "<font foreground='%s'>" % (nick_color) c_end = "</font>" tmp = "[{prefix}{cstart}{nick}{cend}]".format( prefix=prefixes[i], nick=nicks[i], cstart=c_start, cend=c_end) overhead = len(tmp) - len(nicks[i]) - len(prefixes[i]) message += "{0:{align}<{fill}}".format(tmp, align=" ", fill=max_nicklen + overhead) if (i+1) % self.max_col == 0: print_message(message) message = "" else: message += " " print_message(message) names_cb.first = True names_cb.max_col = int(config.get("tekka","names_columns")) s,c = gui.tabs.search_tabs(server, channel) names_cb.tab = c or s signals.connect_signal("names", names_cb) sushi.names(server, channel)