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
"""
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):
"""
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')
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):
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],
# 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
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]
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:
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()
!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)
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))
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):
"""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:
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: