# -*- coding: utf-8 -*-
#
#   Debian Changes Bot
#   Copyright (C) 2008 Chris Lamb <chris@chris-lamb.co.uk>
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as
#   published by the Free Software Foundation, either version 3 of the
#   License, or (at your option) any later version.
#
#   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 Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

from supybot.commands import wrap
import supybot.callbacks as callbacks

from DebianDevelChangesBot.utils import colourise

import urllib2

class DebianUtils(callbacks.Plugin):
    threaded = True

    def madison(self, irc, msg, args, package):
        args = {
            'package': package,
            's': 'stable,testing,unstable,experimental',
            'text': 'on',
        }
        querystr = '&'.join(['%s=%s' % (k, v) for k, v in args.iteritems()])
        fileobj = urllib2.urlopen('http://qa.debian.org/madison.php?%s' % querystr)

        lines = fileobj.readlines()
        if not lines:
            irc.reply('Did not get a response -- is "%s" a valid package?' % package)
            return

        field_styles = ('package', 'version', 'distribution', 'section')
        for line in lines:
            out = []
            fields = line.strip().split('|', len(field_styles))
            for style, data in zip(field_styles, fields):
                out.append('[%s]%s' % (style, data))
            irc.reply(colourise('[reset]|'.join(out)))

    madison = wrap(madison, ['text'])

Class = DebianUtils

@@ -906,23 +906,170 @@
 ise%0A
-%0Aimport urllib2
+from DebianDevelChangesBot.messages import BugSynopsis%0A%0Aimport re%0Aimport urllib2%0Afrom btsutils.debbugs import debbugs%0A%0ABUG_NUMBER_PATTERN = re.compile(r'%5Cd%7B2,7%7D')
 %0A%0Acl
@@ -2031,16 +2031,751 @@
 ext'%5D)%0A%0A
+    def bug(self, irc, msg, args, bug_string):%0A        try:%0A            m = BUG_NUMBER_PATTERN.search(bug_string)%0A            bug_number = int(m.group(0))%0A        except:%0A            irc.reply('Could not parse bug number')%0A            return%0A%0A        try:%0A            bts = debbugs()%0A            entry = bts.get(bug_number)%0A        except:%0A            irc.reply('Could not get bug info -- is #%25d a valid bug number?' %25 bug_number)%0A            return%0A%0A        msg = BugSynopsis()%0A        msg.bug_number = bug_number%0A%0A        msg.status = entry.status%0A        msg.package = entry.package%0A        msg.title = entry.summary%0A        msg.severity = entry.severity%0A%0A        irc.reply(colourise(msg.for_irc()))%0A%0A    bug = wrap(bug, %5B'text'%5D)%0A%0A
 Class = 

Add !bug command