From 1d5d7c371bdecaf42cd6785f8c8ab152f0eaec48 Mon Sep 17 00:00:00 2001 From: kaliko Date: Fri, 14 Nov 2014 14:52:39 +0100 Subject: [PATCH] Some cleanup --- sid/echo.py | 6 +++--- sid/feeds.py | 25 ++++++++++++------------- sid/sid.py | 7 +------ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/sid/echo.py b/sid/echo.py index eae5b56..a9cc400 100644 --- a/sid/echo.py +++ b/sid/echo.py @@ -21,7 +21,7 @@ class Echo(Plugin): def __init__(self, bot): Plugin.__init__(self, bot) - bot.add_event_handler("groupchat_message", self.muc_message) + bot.add_event_handler('groupchat_message', self.muc_message) # The groupchat_presence event is triggered whenever a # presence stanza is received from any chat room, including # any presences you send yourself. To limit event handling @@ -53,7 +53,7 @@ class Echo(Plugin): """ if msg['mucnick'] != self.bot.nick and self.bot.nick in msg['body']: self.bot.send_message(mto=msg['from'].bare, - mbody="I heard that, %s." % msg['mucnick'], + mbody='I heard that, %s.' % msg['mucnick'], mtype='groupchat') def muc_online(self, presence): @@ -70,7 +70,7 @@ class Echo(Plugin): """ if presence['muc']['nick'] != self.bot.nick: self.bot.send_message(mto=presence['from'].bare, - mbody="Hello, %s %s" % (presence['muc']['role'], + mbody='Hello, %s %s' % (presence['muc']['role'], presence['muc']['nick']), mtype='groupchat') diff --git a/sid/feeds.py b/sid/feeds.py index 7291af2..043c784 100644 --- a/sid/feeds.py +++ b/sid/feeds.py @@ -34,7 +34,7 @@ html_escape_table = { def html_escape(text): """Produce entities within text.""" - return "".join(html_escape_table.get(c, c) for c in text) + return ''.join(html_escape_table.get(c, c) for c in text) def strtm_to_dtm(struc_time): @@ -52,8 +52,7 @@ class FeedMonitor(threading.Thread): self.thread_killed = False def send(self, message): - """simple wrapper around JabberBot().send()""" - self.bot.log.debug(self.bot.room) + """simple wrapper around bot send_message method""" self.bot.send_message(mto=self.bot.room, mbody=message[1], mhtml=message[0], @@ -65,14 +64,14 @@ class FeedMonitor(threading.Thread): # Cannot resolve address if 'status' not in parsed_feed: - self.bot.log.error(u'Error from "%s": %s.' % + self.bot.log.error('Error from "%s": %s.' % (feed, parsed_feed.bozo_exception.__repr__())) return # unusual return http code if parsed_feed.status != 200: self.bot.log.error( - u'Got code %(status)d from "%(href)s" (please update).' % + 'Got code %(status)d from "%(href)s" (please update).' % parsed_feed) return @@ -84,8 +83,8 @@ class FeedMonitor(threading.Thread): self.bot.log.debug('last check: %s' % self.last_check) return - title = u'"%s":' % parsed_feed.feed.get('title', 'n/a') - xtitle = u'%s:' % html_escape( + title = '"%s":' % parsed_feed.feed.get('title', 'n/a') + xtitle = '%s:' % html_escape( parsed_feed.feed.get('title', 'n/a')) text = [title] xhtml = [xtitle] @@ -101,12 +100,12 @@ class FeedMonitor(threading.Thread): self.seen[feed_id].append(post.id) self.bot.log.info(post.title) - body = u'%(title)s %(link)s' % post + body = '%(title)s %(link)s' % post text.append(body) xpost = dict(**post) xpost['title'] = html_escape(xpost.get('title', 'n/a')) - xbody = u'%(title)s' % xpost + xbody = '%(title)s' % xpost xhtml.append(xbody) if len(text) > 1: @@ -114,12 +113,12 @@ class FeedMonitor(threading.Thread): def run(self): while not self.thread_killed: - self.bot.log.info(u'feeds check') + self.bot.log.debug('feeds check') for feed in self.feeds_list: try: self.new_posts(feed) except Exception as err: - self.bot.log.error(u'feeds thread crashed') + self.bot.log.error('feeds thread crashed') self.bot.log.error(err) self.thread_killed = True self.last_check = datetime.datetime.utcnow() @@ -163,5 +162,5 @@ class Feeds(Plugin): !feeds : registred feeds list !feeds last : last check time""" if 'last' in args: - return u'Last feeds check: %s' % self.th_mon.last_check - return u'\n'.join(Feeds.FEEDS) + return 'Last feeds check: %s' % self.th_mon.last_check + return '\n'.join(Feeds.FEEDS) diff --git a/sid/sid.py b/sid/sid.py index 24f543f..dd768c1 100644 --- a/sid/sid.py +++ b/sid/sid.py @@ -92,12 +92,11 @@ class MUCBot(sleekxmpp.ClientXMPP): body = msg['body'] mucfrom = msg['mucnic'] if msg['mucnick'] == self.nick: - self.log.debug('ignoring message from me') return if not body.startswith(MUCBot.prefix): return args = body[1:].split() - cmd= args.pop(0) + cmd = args.pop(0) if cmd not in self.commands: return self.log.debug('cmd: {0}'.format(cmd)) @@ -108,7 +107,6 @@ class MUCBot(sleekxmpp.ClientXMPP): except Exception as err: reply = traceback.format_exc(err) self.log.exception('An error occurred processing: {0}: {1}'.format(body, reply)) - self.log.debug(reply) self.send_message(mto=msg['from'].bare, mbody=reply, mtype='groupchat') def start(self, event): @@ -158,7 +156,6 @@ class MUCBot(sleekxmpp.ClientXMPP): """Returns a help string listing available options. Automatically assigned to the "help" command.""" - self.log.info(args) help_cmd = ('Type {}help '.format(self.prefix) + ' to get more info about that specific command.') if not args: @@ -178,8 +175,6 @@ class MUCBot(sleekxmpp.ClientXMPP): usage = usage + '\n\n' + help_cmd text = '{}\n\n{}'.format(description, usage) else: - self.log.debug(args[0]) - self.log.debug(args[0] in self.commands.keys()) if args[0] in self.commands.keys(): text = self.commands[args[0]].__doc__.strip() or 'undocumented' else: -- 2.39.5