]> kaliko git repositories - sid.git/commitdiff
Some cleanup
authorkaliko <kaliko@azylum.org>
Fri, 14 Nov 2014 13:52:39 +0000 (14:52 +0100)
committerkaliko <kaliko@azylum.org>
Fri, 14 Nov 2014 13:52:39 +0000 (14:52 +0100)
sid/echo.py
sid/feeds.py
sid/sid.py

index eae5b56d240c04dc553a2325ccba32c7a3e22638..a9cc400ec730593941f670f98e1c14c108e8ffc9 100644 (file)
@@ -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')
 
index 7291af27cc72dae9bf22644466b8c2757bc5ef92..043c784dcb23f4cf0484bee46badee0f2e370e27 100644 (file)
@@ -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'<strong>%s</strong>:' % html_escape(
+        title = '"%s":' % parsed_feed.feed.get('title', 'n/a')
+        xtitle = '<strong>%s</strong>:' % 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'<a href="%(link)s">%(title)s</a>' % xpost
+                xbody = '<a href="%(link)s">%(title)s</a>' % 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)
index 24f543f6e60d6ed3cdd7efbd86f24b3e3d03bb3c..dd768c17c1f929664020c19564d1347b124f0c06 100644 (file)
@@ -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 <command name>'.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: