From 8d02f7db31a8587f1cd9bb31bcdffd517f6c144e Mon Sep 17 00:00:00 2001 From: kaliko Date: Sat, 24 Oct 2015 13:02:12 +0200 Subject: [PATCH] Fixed tell "purge" command Some code convention cleanup (pylint) --- sid/__init__.py | 2 +- sid/bts.py | 5 ++++- sid/echo.py | 12 ++++++++---- sid/feeds.py | 18 ++++++++---------- sid/ping.py | 6 ++---- sid/sid.py | 4 +++- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/sid/__init__.py b/sid/__init__.py index 144c7bf..5f99c7c 100644 --- a/sid/__init__.py +++ b/sid/__init__.py @@ -3,6 +3,6 @@ """ __author__ = 'Kaliko' -__email__ = 'kaliko@azylum.org' +__email__ = 'kaliko@azylum.org' __version__ = '0.1' __url__ = 'http://git.kaliko.me/?p=sid.git' diff --git a/sid/bts.py b/sid/bts.py index a19259a..254a923 100644 --- a/sid/bts.py +++ b/sid/bts.py @@ -24,13 +24,16 @@ from .plugin import Plugin, botcmd class Bugs(Plugin): - re_bugs = re_compile('(?<=#)(\d{6,7})') + """Gets bugs info from the BTS + """ + re_bugs = re_compile(r'(?<=#)(\d{6,7})') def __init__(self, bot): Plugin.__init__(self, bot) bot.add_event_handler("muc::%s::message" % self.bot.room, self.muc_message) def muc_message(self, msg): + """Handler method dealing with MUC incoming messages""" # Does not reply to myself if msg['mucnick'] == self.bot.nick: return diff --git a/sid/echo.py b/sid/echo.py index 94836d0..534163c 100644 --- a/sid/echo.py +++ b/sid/echo.py @@ -18,6 +18,8 @@ from .plugin import Plugin, botcmd class Echo(Plugin): + """Drop a message to be sent when someone gets online. + """ def __init__(self, bot): Plugin.__init__(self, bot) @@ -31,6 +33,7 @@ class Echo(Plugin): bot.add_event_handler("muc::%s::presence" % self.bot.room, self.log_presence) def log_presence(self, pres): + """Register presence""" self.log.debug('%s: %s', pres['muc']['nick'], pres['type']) nick = pres['muc']['nick'] self.presence.update({nick: (pres['muc']['role'], pres['type'])}) @@ -54,13 +57,13 @@ class Echo(Plugin): if len(args) == 1: if args[0] == 'queue': msg = '\n'.join(['{0}:\n\t{1}'.format(k, '\n'.join(v)) - for k, v in self.inbox.items()]) + for k, v in self.inbox.items()]) self.reply(message, msg) return if args[0] == 'purge': sender = message['from'].resource if self.presence[sender][0] == 'moderator': - self.online = set() + self.inbox = dict() return if len(args) < 2: msg = 'Please provide a message:\n{}'.format(self.tell.__doc__) @@ -69,6 +72,7 @@ class Echo(Plugin): self._handle_msg(message) def _handle_msg(self, message): + """Format and drop message in the inbox""" sender = message['from'].resource recipient = message['body'].split()[1] tell_msg = ' '.join(message['body'].split()[2:]) @@ -78,9 +82,9 @@ class Echo(Plugin): self.presence[recipient][1] == 'available'): return if recipient in self.inbox.keys(): - self.inbox[recipient].append(letter) + self.inbox[recipient].append(letter) else: - self.inbox[recipient] = [letter] + self.inbox[recipient] = [letter] # VIM MODLINE diff --git a/sid/feeds.py b/sid/feeds.py index a40f766..5a33d6d 100644 --- a/sid/feeds.py +++ b/sid/feeds.py @@ -137,13 +137,13 @@ class Feeds(Plugin): # 'http://www.debian.org/News/news', # DPN in french - 'http://www.debian.org/News/weekly/dwn.fr.rdf', + 'http://www.debian.org/News/weekly/dwn.fr.rdf', # Misc - 'http://rss.gmane.org/topics/excerpts/gmane.linux.debian.devel.announce', - 'http://rss.gmane.org/gmane.linux.debian.user.security.announce', - 'http://planet-fr.debian.net/users/rss20.xml', - 'http://planet.debian.org/atom.xml', + 'http://rss.gmane.org/topics/excerpts/gmane.linux.debian.devel.announce', + 'http://rss.gmane.org/gmane.linux.debian.user.security.announce', + 'http://planet-fr.debian.net/users/rss20.xml', + 'http://planet.debian.org/atom.xml', ] def __init__(self, bot): @@ -165,9 +165,7 @@ class Feeds(Plugin): return html = ['{1}'.format(html_escape(u), html_escape(u[7:]) - ) for u in Feeds.FEEDS] - msg = { - 'mbody': 'Feeds:\n' + '\n'.join(Feeds.FEEDS), - 'mhtml': 'Feeds:
' + '
'.join(html), - } + ) for u in Feeds.FEEDS] + msg = {'mbody': 'Feeds:\n' + '\n'.join(Feeds.FEEDS), + 'mhtml': 'Feeds:
' + '
'.join(html),} self.reply(rcv, msg) diff --git a/sid/ping.py b/sid/ping.py index 96d92c7..9fbab84 100644 --- a/sid/ping.py +++ b/sid/ping.py @@ -27,10 +27,8 @@ class Ping(Plugin): """ping's answering a pong showing the bot is alive. !ping : You'll get back "pong"! """ - msg = { - 'mhtml':'!pong'.format(self), - 'mbody':'!pong', - } + msg = {'mhtml':'!pong'.format(self), + 'mbody':'!pong',} self.reply(rcv, msg) # VIM MODLINE diff --git a/sid/sid.py b/sid/sid.py index 373209d..604a63a 100644 --- a/sid/sid.py +++ b/sid/sid.py @@ -46,7 +46,7 @@ class MUCBot(sleekxmpp.ClientXMPP): prefix = '!' def __init__(self, jid, password, room, nick, log_file=None, - log_level=logging.INFO): + log_level=logging.INFO): super(MUCBot, self).__init__(jid, password) self.log = logging.getLogger(__package__) @@ -90,6 +90,7 @@ class MUCBot(sleekxmpp.ClientXMPP): self.log.debug('set logger, log level : %s', log_level) def message(self, msg): + """Messages handler""" if msg['type'] not in ('groupchat', 'chat'): self.log.warning('Unhandled message') return @@ -117,6 +118,7 @@ class MUCBot(sleekxmpp.ClientXMPP): self.send_message(mto=msg['from'].bare, mbody=reply, mtype='groupchat') def _view(self, pres): + """Track known nick""" nick = pres['from'] status = (pres['type'], pres['status']) self.__seen.update({nick: status}) -- 2.39.5