From 05082f879f25814b1b9e951b0b9141252f4f0b2d Mon Sep 17 00:00:00 2001 From: kaliko Date: Fri, 23 Oct 2015 15:27:12 +0200 Subject: [PATCH] Add Debian BTS plugin --- sid/bts.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 sid/bts.py diff --git a/sid/bts.py b/sid/bts.py new file mode 100644 index 0000000..efe7033 --- /dev/null +++ b/sid/bts.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2010, 2011 Anaël Verrier +# Copyright (C) 2015 kaliko + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 only. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +from re import compile as re_compile + +import debianbts + +from .plugin import Plugin, botcmd + + +class Bugs(Plugin): + re_bugs = re_compile('(?<=#)(\d{6,7})') + + def __init__(self, bot): + Plugin.__init__(self, bot) + bot.add_event_handler("muc::%s::message" % self.bot.room, self.muc_message) + + def muc_message(self, msg): + # Does not reply to myself + if msg['mucnick'] == self.bot.nick: + return + if '#' not in msg['body']: + return + bugs = list() + for bug_id in set(Bugs.re_bugs.findall(msg['body'].strip())): + self.log.debug('got bug id: %s' % bug_id) + query = debianbts.get_status(bug_id) + if len(query) == 1: + bug = query[0] + url = debianbts.BTS_URL + bug_id + bugs.append({'id': bug_id, + 'package': bug.package, + 'summary': bug.subject, + 'url': url}) + else: + self.log.warning('Wrong bug number "%s"?', bug_id) + bugs.append({'id': bug_id}) + for bug in bugs: + if len(bug) == 1: + message = 'Invalid bug id: {id}'.format(**bug) + self.reply(msg, message) + else: + message = {'mhtml': '#%(id)s: %(package)s « %(summary)s »' % bug, + 'mbody': '#%(id)s: %(package)s « %(summary)s » %(url)s' % bug} + self.reply(msg, message) + + @botcmd + def bugs(self, message, args): + """ intercepts bugs number in any message, looking for string like #629234 + !bugs : nothing yet. + """ + return None -- 2.39.2