From 691db08e50146d17d0fc474735b7af2b5f3b1ea9 Mon Sep 17 00:00:00 2001 From: urlbot Date: Sun, 9 Nov 2014 16:52:22 +0100 Subject: [PATCH] add plugin parse_debbug --- plugins.py | 32 ++++++++++++++++++++++++++++++-- urlbot.py | 16 ++++++++-------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/plugins.py b/plugins.py index c30ee11..5f28e19 100644 --- a/plugins.py +++ b/plugins.py @@ -5,9 +5,10 @@ if '__main__' == __name__: print('''this is a plugin file, which is not meant to be executed''') exit(-1) -import time, random, unicodedata +import time, random, unicodedata, re from local_config import conf from common import * +from urlbot import extract_title joblist = [] @@ -58,6 +59,33 @@ def parse_mental_ill(args): 'msg': '''Multiple exclamation/question marks are a sure sign of mental disease, with %s as a living example.''' % args['reply_user'] } +def parse_debbug(args): + if 'register' == args: + return { + 'name': 'parse Debian bug numbers', + 'args': ('data',), + 'ratelimit_class': RATE_NO_SILENCE | RATE_GLOBAL + } + + bugs = re.findall(r'#(\d{4,})', args['data']) + if not bugs: + return None + + url = 'https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s' % bugs[0] + status, title = extract_title(url) + + if 0 == status: + title = 'Debian Bug: ' + title + elif 3 == status: + pass + else: + return None + + logger('plugin', 'detected Debian bug') + return { + 'msg': title + } + def parse_skynet(args): if 'register' == args: return { @@ -461,7 +489,7 @@ def data_parse_commands(data): chat_write(ret['msg']) funcs = {} -funcs['parse'] = (parse_mental_ill, parse_skynet) +funcs['parse'] = (parse_mental_ill, parse_skynet, parse_debbug) funcs['command'] = ( command_command, command_help, command_version, command_unicode, command_source, command_dice, command_uptime, command_ping, command_info, diff --git a/urlbot.py b/urlbot.py index 9f80fd1..37b077d 100755 --- a/urlbot.py +++ b/urlbot.py @@ -239,15 +239,15 @@ def parse_delete(filepath): plugins.data_parse_other(content) return -import plugins - -plugins.chat_write = chat_write -plugins.ratelimit_exceeded = ratelimit_exceeded -plugins.ratelimit_touch = ratelimit_touch - -plugins.register_all() - if '__main__' == __name__: + import plugins + + plugins.chat_write = chat_write + plugins.ratelimit_exceeded = ratelimit_exceeded + plugins.ratelimit_touch = ratelimit_touch + + plugins.register_all() + print(sys.argv[0] + ' ' + VERSION) if not os.path.exists(fifo_path):