From 20037ec392589716cc10c3e5f3bac9706438f0f0 Mon Sep 17 00:00:00 2001 From: GLolol Date: Thu, 13 Nov 2014 18:32:33 -0800 Subject: [PATCH] SupyMisc: code cleanup & rewrite serverlist --- SupyMisc/plugin.py | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/SupyMisc/plugin.py b/SupyMisc/plugin.py index 34ffc33..47b0247 100644 --- a/SupyMisc/plugin.py +++ b/SupyMisc/plugin.py @@ -28,7 +28,6 @@ ### import random -# import itertools import supybot.conf as conf import supybot.utils as utils @@ -129,28 +128,24 @@ class SupyMisc(callbacks.Plugin): irc.reply(".{} appears to be a valid TLD, see {}{}".format(text, db, s)) tld = wrap(tld, ['something']) -## Fill this in later, try to prevent forkbombs and stuff. -# def permutations(self, irc, msg, args, length, text): -# """[] -# -# Returns []-length permutations of . If not specified, [] -# defaults to the length of .""" -# s = ' '.join(''.join(p) for p in itertools.permutations(text, length or None)) -# irc.reply(s) -# permutations = wrap(permutations, [additional('int'), 'text']) - ### Generic informational commands (ident fetcher, channel counter, etc.) - def serverlist(self, irc, msg, args): - """A command similar to the 'networks' command, but showing configured servers instead - of the connected one.""" - L = [] + """takes no arguments. + A command similar to the 'networks' command, but showing configured servers + instead of the connected one.""" + L, res = {}, [] for ircd in world.ircs: - # fetch a list of tuples in the format (server, port) - for server in conf.supybot.networks.get(ircd.network).servers(): - # list every server configured for every network connected - L.append("%s: %s" % (ircd.network, server[0])) - irc.reply(', '.join(L)) # finally, join them up in a comma-separated list + net = ircd.network + # Get a list of server:port strings for every network, and put this + # into a dictionary (netname -> list of servers) + L[net] = (':'.join(str(x) for x in s) for s in \ + conf.supybot.networks.get(net).servers()) + for k, v in L.items(): + # Check SSL status and format response + sslstatus = "\x0303on\x03" if conf.supybot.networks.get(k).ssl() else \ + "\x0304off\x03" + res.append("\x02%s\x02 (%s) [SSL: %s]" % (k, ', '.join(v), sslstatus)) + irc.reply(', '.join(res)) serverlist = wrap(serverlist) def netcount(self, irc, msg, args): @@ -168,7 +163,7 @@ class SupyMisc(callbacks.Plugin): def chancount(self, irc, msg, args): """takes no arguments. Counts the amount of channels the bot is on. """ - irc.reply(len(irc.state.channels.keys())) + irc.reply(len(irc.state.channels)) chancount = wrap(chancount) def getchan(self, irc, msg, args):