]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/grouphug.rb
32a6e55ecd2b39293bd7f6824d0125d8f3b73049
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / grouphug.rb
1 #-- vim:sw=2:et
2 #++
3 #
4 # :title: Grouphug Plugin for rbot
5 #
6 # Author:: Mark Kretschmann <markey@web.de>
7 # Copyright:: (C) 2005 Mark Kretschmann
8 # License:: GPL v2
9
10 class GrouphugPlugin < Plugin
11   def help( plugin, topic="" )
12     return "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess <number>' for specific one."
13   end
14
15   def confess(m, params)
16     opts = { :cache => false }
17     path = "random"
18     if params[:num]
19       path = "confessions/#{params[:num]}"
20       opts.delete(:cache)
21     end
22
23     Thread.start do
24       begin
25         data = @bot.httputil.get("http://grouphug.us/#{path}", opts)
26
27         reg = Regexp.new('(<td class="conf-text")(.*?)(<p>)(.*?)(</p>)',
28                          Regexp::MULTILINE)
29         confession = reg.match( data )[4].ircify_html
30         confession = "no confession ##{params[:num]} found" if confession.empty? and params[:num]
31
32         m.reply confession
33       rescue
34         m.reply "failed to connect to grouphug.us"
35       end
36     end
37   end
38 end
39
40
41 plugin = GrouphugPlugin.new
42
43 plugin.map "grouphug [:num]", :action => :confess, :requirements => { :num => /\d+/ }
44 plugin.map "confess [:num]", :action => :confess, :requirements => { :num => /\d+/ }
45