]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/grouphug.rb
search plugin: fix gcalc
[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     begin
24       data = @bot.httputil.get("http://grouphug.us/#{path}", opts)
25
26       reg = Regexp.new('(<div class="content")(.*?)(<p>)(.*?)(</p>)',
27                        Regexp::MULTILINE)
28       confession = reg.match( data )[4].ircify_html
29       confession = "no confession ##{params[:num]} found" if confession.empty? and params[:num]
30
31       m.reply confession
32     rescue
33       m.reply "failed to connect to grouphug.us"
34     end
35   end
36 end
37
38
39 plugin = GrouphugPlugin.new
40
41 plugin.map "grouphug [:num]",
42   :thread => true, :action => :confess, :requirements => { :num => /\d+/ }
43 plugin.map "confess [:num]",
44   :thread => true, :action => :confess, :requirements => { :num => /\d+/ }
45