Commit 1bc199bb authored by Maxime Bombar's avatar Maxime Bombar

rename Ninja to Nsa

parent 27773568
......@@ -76,9 +76,9 @@ class Bot(irc.bot.SingleServerIRCBot):
else:
self.do_command_ext(conn, command, level, source)
class Ninja(Bot):
class Nsa(Bot):
def __init__(self):
Bot.__init__(self, "NinjaBot")
Bot.__init__(self, "NsaBot")
def on_welcome_ext(self, conn, e):
conn.join('#wikistalk')
......@@ -172,7 +172,7 @@ class Ninja(Bot):
@asyncio.coroutine
def idle_loop(host, user, password, ninja):
def idle_loop(host, user, password, nsa):
imap_client = aioimaplib.IMAP4_SSL(host=host, timeout=30)
yield from imap_client.wait_hello_from_server()
yield from imap_client.login(user, password)
......@@ -192,25 +192,25 @@ def idle_loop(host, user, password, ninja):
comment = re.search(r'\s*Commentaire :\s*\n\s*(?P<comment>[^\n]*)\n', body)
if comment: comment = comment.group('comment')
if page_user:
ninja.push_update(page_user.group('page'), page_user.group('user'), int(revision.group('rev')), comment)
nsa.push_update(page_user.group('page'), page_user.group('user'), int(revision.group('rev')), comment)
continue
page_new_user = re.search(r'La page « (?P<page>.*) » a été renommée « (?P<new>.*) » par (?P<user>.*) :', body)
if page_new_user:
ninja.push_update(page_new_user.group('page'), page_user.group('user'), page_new_user.group('new'), comment, type=Update.rename)
nsa.push_update(page_new_user.group('page'), page_user.group('user'), page_new_user.group('new'), comment, type=Update.rename)
continue
page_user = re.search(r'vous vous êtes abonné aux notifications de changements pour la page "(?P<page>.*)"\.Une pièce jointe (?P<add>(?:vient d\'y être ajouté)|(?:de cette page vient d\'être supprimée)) par (?P<user>.*)\. Quelques détails sur la pièce jointe :', body)
piece = re.search(r'Nom\s*:\s*(?P<name>[^\n]*)\n', body)
if page_user:
ninja.push_update(page_user.group('page'), page_user.group('user'), piece.group('name'), "ajout d'une pièce jointe" if page_user.group('add').startswith('v') else 'suppression de la pièce jointe', type=Update.attachment)
nsa.push_update(page_user.group('page'), page_user.group('user'), piece.group('name'), "ajout d'une pièce jointe" if page_user.group('add').startswith('v') else 'suppression de la pièce jointe', type=Update.attachment)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
ninja = Ninja()
t = threading.Thread(target=ninja.start)
nsa = Nsa()
t = threading.Thread(target=nsa.start)
t.start()
while True:
try:
loop.run_until_complete(idle_loop(secrets.host, secrets.user, secrets.password, ninja))
loop.run_until_complete(idle_loop(secrets.host, secrets.user, secrets.password, nsa))
except:
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment