Chop ::paint into more managable pieces ( using big axe ) as it was getting really...
[amarok.git] / supplementary_scripts / rbot / bug.rb
blob16caac34ab065bdfa6b9df0e9a37447f3a652787
1 #(C) Berkus Madfire
2 #Needs xmlsimple from http://www.maik-schmidt.de/xml-simple.html
4 require 'net/http'
5 require 'xmlsimple'
8 class KDEBugPlugin < Plugin
9     def riphtml s
10         s.gsub(/<[^>]+>/, '').gsub(/&amp;/,'&').gsub(/&quot;/,'"').gsub(/&lt;/,'<').gsub(/&gt;/,'>').gsub(/&ellip;/,'...').gsub(/&apos;/, "'").gsub("\n",'')
11         return s
12     end
14     def help(plugin,topic="")
15         "bug #<number> - displays bugs.kde.org information for given bug number"
16     end
18     def privmsg(m)
19         unless m.params
20             m.reply("incorrect usage: "+help(m.plugin))
21             return
22         end
23         a = m.params.scan(/^#?([0-9]+)/)
24         if a.length == 0
25             m.reply("You called the wrong number...")
26             return
27         end
28 #       m.reply("Please wait, querying...")
29         begin
30             h = Net::HTTP.new("bugs.kde.org", 80)
31             resp = h.get("/xml.cgi?id=#{a}", nil)
32             if resp.message == "OK"
33                 bug = XmlSimple.xml_in(resp.body)
34                 if bug['bug'][0]['error'] == 'NotFound'
35                     m.reply("Bug #{a} was not found in Bugzilla.")
36                 else
37                     str = "PRODUCT: #{bug['bug'][0]['product']}"
38                     str += " / #{bug['bug'][0]['component']}" if bug['bug'][0]['component']
39                     str += " | STATUS: #{bug['bug'][0]['bug_status']}"
40                     str += " | RESOLUTION: #{bug['bug'][0]['resolution']}" if bug['bug'][0]['resolution']
41                     str += " | URL: http://bugs.kde.org/show_bug.cgi?id=#{a} | DESCRIPTION: #{riphtml(bug['bug'][0]['short_desc'].to_s)}"
42                     m.reply(str)
43                 end
44             else
45                 m.reply("Request to bugs.kde.org failed. Message not OK.")
46             end
47         rescue
48             m.reply("Request to bugs.kde.org failed")
49         end
50     end
51 end
53 plugin = KDEBugPlugin.new
54 plugin.register("bug")