support python-irclib >= 3 and minor changes

This commit is contained in:
Romain Bignon 2013-04-11 20:32:33 +02:00
commit fb3d2655a9

View file

@ -23,13 +23,14 @@ import logging
import re import re
import sys import sys
from threading import Thread, Event from threading import Thread, Event
from ircbot import SingleServerIRCBot from irc.bot import SingleServerIRCBot
from weboob.core import Weboob from weboob.core import Weboob
from weboob.tools.misc import get_backtrace
from weboob.tools.storage import StandardStorage from weboob.tools.storage import StandardStorage
IRC_CHANNEL = '#weboob' IRC_CHANNEL = '#weboob'
IRC_NICKNAME = 'boobot' IRC_NICKNAME = 'booboot'
IRC_SERVER = 'irc.freenode.org' IRC_SERVER = 'irc.freenode.org'
STORAGE_FILE = 'boobot.storage' STORAGE_FILE = 'boobot.storage'
@ -51,10 +52,11 @@ class MyThread(Thread):
self.weboob.loop() self.weboob.loop()
def find_keywords(self, text): def find_keywords(self, text):
for word in ['weboob', 'videoob', 'havesex', 'havedate', 'monboob', 'boobmsg', for word in ['weboob', 'videoob', 'havesex', 'havedate', 'monboob', 'boobmsg', \
'flatboob', 'boobill', 'pastoob', 'radioob', 'translaboob', 'traveloob', 'flatboob', 'boobill', 'pastoob', 'radioob', 'translaboob', 'traveloob', \
'boobathon', 'boobank', 'boobtracker', 'comparoob', 'wetboobs', 'boobathon', 'boobank', 'boobtracker', 'comparoob', 'wetboobs', \
'webcontentedit', 'weboorrents', 'capabilit', u'sàt', u'salut à toi']: 'webcontentedit', 'weboorrents', u'sàt', u'salut à toi', 'ass2m', \
'budget insight', 'budget-insight', 'budgetinsight', 'budgea']:
if word in text.lower(): if word in text.lower():
return word return word
return None return None
@ -74,7 +76,7 @@ class MyThread(Thread):
for backend, msg in self.weboob.do(iter_messages, backends=['dlfp']): for backend, msg in self.weboob.do(iter_messages, backends=['dlfp']):
word = self.find_keywords(msg.message) word = self.find_keywords(msg.message)
if word is not None: if word is not None and msg.login != 'moules':
message = msg.message.replace(word, '\002%s\002' % word) message = msg.message.replace(word, '\002%s\002' % word)
self.bot.send_message('[DLFP] <%s> %s' % (msg.login, message)) self.bot.send_message('[DLFP] <%s> %s' % (msg.login, message))
@ -84,7 +86,11 @@ class MyThread(Thread):
class TestBot(SingleServerIRCBot): class TestBot(SingleServerIRCBot):
def __init__(self, channel, nickname, server, port=6667): def __init__(self, channel, nickname, server, port=6667):
SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname + "`") SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
#self.connection.add_global_handler('pubmsg', self.on_pubmsg)
self.connection.add_global_handler('join', self.on_join)
self.connection.add_global_handler('welcome', self.on_welcome)
self.channel = channel self.channel = channel
self.joined = Event() self.joined = Event()
self.weboob = None self.weboob = None
@ -96,9 +102,9 @@ class TestBot(SingleServerIRCBot):
self.joined.set() self.joined.set()
def send_message(self, msg): def send_message(self, msg):
self.connection.privmsg(self.channel, msg.encode("UTF-8")) self.connection.privmsg(self.channel, msg)
def on_pubmsg(self, channel, event): def on_pubmsg(self, c, event):
text = ' '.join(event.arguments()) text = ' '.join(event.arguments())
for m in re.findall('([\w\d_\-]+@\w+)', text): for m in re.findall('([\w\d_\-]+@\w+)', text):
id, backend_name = m.split('@', 1) id, backend_name = m.split('@', 1)
@ -110,6 +116,7 @@ class TestBot(SingleServerIRCBot):
try: try:
getattr(self, func)(backend, id) getattr(self, func)(backend, id)
except Exception, e: except Exception, e:
print get_backtrace()
self.send_message('Oops: [%s] %s' % (type(e).__name__, e)) self.send_message('Oops: [%s] %s' % (type(e).__name__, e))
break break