Commit 959705b7 authored by Benjamin Graillot's avatar Benjamin Graillot

Gestion du renommage de page

parent 1734bcc5
......@@ -13,6 +13,11 @@ def write_subs(subs):
with open('subs.py', 'w') as s:
s.write('subs = { ' + ',\n'.join([repr(nick) + ':{' + ',\n'.join([repr(channel) + ': [' + ','.join([repr(patt) for patt in subs[nick][channel]]) + ']' for channel in subs[nick]]) + '}' for nick in subs]) + ' }\n')
class Update:
edit = 0
attachment = 1
rename = 2
class Bot(irc.bot.SingleServerIRCBot):
def __init__(self, nickname, channel="#bot", server="irc.crans.org", port=6667):
......@@ -142,7 +147,7 @@ class Ninja(Bot):
conn.privmsg(source, ' + {i}. {patt}'.format(i=i, patt=patt))
write_subs(subs)
def push_update(self, page, user, revision, comment, attachment=False):
def push_update(self, page, user, revision, comment, type=Update.edit):
global subs
patts = {}
for nick in subs:
......@@ -152,13 +157,15 @@ class Ninja(Bot):
for channel in patts:
if any(re.fullmatch(patt, page) for patt in patts[channel]):
t = time.time()
if not attachment:
if type == Update.edit:
if comment:
self.connection.privmsg(channel, '\x0310,99{page}\x0f \x033,99{user}\x0f \x0399,99{comment}\x0f \x0315,99(r{revision})'.format(page=page, user=user, revision=revision, comment=comment))
else:
self.connection.privmsg(channel, '\x0310,99{page}\x0f \x033,99{user}\x0f \x0315,99(r{revision})\x0f'.format(page=page, user=user, revision=revision))
else:
elif type == Update.attachment:
self.connection.privmsg(channel, '\x0310,99{page}\x0f \x033,99{user}\x0f \x0399,99{comment}\x0f : \x0310,99{revision}\x0f'.format(page=page, user=user, comment=comment, revision=revision))
elif type == Update.rename:
self.connection.privmsg(channel, '\x0310,99{page}\x0f \x033,99{user}\x0f \x0399,99rename -->\x0f \x0310,99{revision}\x0f \x0399,99{comment}\x0f'.format(page=page, user=user, comment=comment, revision=revision))
while t + 5 > time.time():
time.sleep(1)
......@@ -185,11 +192,14 @@ def idle_loop(host, user, password, ninja):
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)
page_new_user = re.search(r'La page « (?P<page>.*) » a été renommée « (?P<new>.*) » par (?P<user>.*) :')
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)
else:
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', attachment=True)
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)
if __name__ == '__main__':
......
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