|
| 1 | +#!/usr/bin/python |
| 2 | +# (C) Legoktm, 2013 |
| 3 | +# (C) Pywikipediabot team, 2013 |
| 4 | +# Released under the MIT License |
| 5 | +from __future__ import unicode_literals |
| 6 | +import re |
| 7 | +import requests |
| 8 | +from mtirc import bot, hooks, settings |
| 9 | + |
| 10 | +config = dict(settings.config) |
| 11 | +config['nick'] = 'pywikibugs' |
| 12 | +config['debug'] = False |
| 13 | +config['disable_on_errors'] = None |
| 14 | +config['connections']['card.freenode.net']['channels'] = ['#mediawiki', '#pywikipediabot', '##legoktm-bots-chatter'] |
| 15 | + |
| 16 | +COLOR_RE = re.compile(r'(?:\x02|\x03(?:\d{1,2}(?:,\d{1,2})?)?)') |
| 17 | +THINGY = re.compile('bugzilla\.wikimedia\.org/(\d*?) ') |
| 18 | + |
| 19 | + |
| 20 | +def on_msg(**kw): |
| 21 | + if kw['sender'].nick.startswith('wikibugs'): |
| 22 | + if 'Pywikibot' in kw['text']: |
| 23 | + kw['bot'].queue_msg('#pywikipediabot', kw['text']) |
| 24 | + else: |
| 25 | + de_colored = COLOR_RE.sub('', kw['text']) |
| 26 | + match = THINGY.search(de_colored) |
| 27 | + if match: |
| 28 | + bug_id = match.group(1) |
| 29 | + url = 'http://bugzilla.wikimedia.org/show_bug.cgi?id=' + bug_id.strip() |
| 30 | + r = requests.get(url) |
| 31 | + if 'describecomponents.cgi?product=Pywikibot' in r.text: |
| 32 | + kw['bot'].queue_msg('#pywikipediabot', kw['text']) |
| 33 | + |
| 34 | + |
| 35 | +hooks.add_hook('on_msg', 'pywikibugs', on_msg) |
| 36 | +if __name__ == '__main__': |
| 37 | + b = bot.Bot(config) |
| 38 | + b.run() |
0 commit comments