]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/grouphug.rb
aa3bf6d784e96fdf4cebf300c07ca3f6c35ca20d
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / grouphug.rb
1 # Plugin for the Ruby IRC bot (http://linuxbrit.co.uk/rbot/)
2 # (c) 2005 Mark Kretschmann <markey@web.de>
3 # Licensed under GPL V2.
4
5 require "net/http"
6
7
8 class GrouphugPlugin < Plugin
9     def help( plugin, topic="" )
10         "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess <number>' for specific one."
11     end
12
13     def privmsg( m )
14         path = "/random"
15         path = "/confessions/#{m.params()}" if m.params()
16         begin
17           data = bot.httputil.get(URI.parse("http://grouphug.us/#{path}"))
18
19           reg = Regexp.new( '(<td class="conf-text")(.*?)(<p>)(.*?)(</p>)', Regexp::MULTILINE )
20           confession = reg.match( data )[4]
21           confession.gsub!( /<.*?>/, "" ) # Remove html tags
22           confession.gsub!( "\t", "" ) # Remove tab characters
23
24           @bot.say(m.replyto, confession)
25         rescue
26           m.reply "failed to connect to grouphug.us"
27         end
28    end
29 end
30
31
32 plugin = GrouphugPlugin.new
33
34 plugin.register("grouphug")
35 plugin.register("confess")
36