]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/grouphug.rb
Plugin header boilerplating.
[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     path = "random"
17     path = "confessions/#{params[:num]}" if params[:num]
18     begin
19       data = @bot.httputil.get_cached(URI.parse("http://grouphug.us/#{path}"))
20
21       reg = Regexp.new( '(<td class="conf-text")(.*?)(<p>)(.*?)(</p>)', Regexp::MULTILINE )
22       confession = reg.match( data )[4].ircify_html
23       confession = "no confession ##{params[:num]} found" if confession.empty? and params[:num]
24
25       m.reply confession
26     rescue
27       m.reply "failed to connect to grouphug.us"
28     end
29   end
30 end
31
32
33 plugin = GrouphugPlugin.new
34
35 plugin.map "grouphug [:num]", :action => :confess, :requirements => { :num => /\d+/ }
36 plugin.map "confess [:num]", :action => :confess, :requirements => { :num => /\d+/ }
37