4 # :title: Grouphug Plugin for rbot
6 # Author:: Mark Kretschmann <markey@web.de>
7 # Author:: Casey Link <unnamedrambler@gmail.com>
8 # Copyright:: (C) 2005 Mark Kretschmann
9 # Copyright:: (C) 2008 Casey Link
12 class GrouphugPlugin < Plugin
15 @confessions = Array.new
18 def help( plugin, topic="" )
19 return "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess <number>' for specific one."
22 def confess(m, params)
23 opts = { :cache => false }
26 # Fetch a specific question - separate from cache
28 path = "confessions/#{params[:num]}"
30 data = @bot.httputil.get("http://grouphug.us/#{path}", opts)
32 reg = Regexp.new('<div class="content">.*?<p>(.*?)</p>', Regexp::MULTILINE)
34 confession = res[0][0].ircify_html
35 confession = "no confession ##{params[:num]} found" if confession.empty? and params[:num]
37 else # Cache random confessions
38 if @confessions.empty?
39 data = @bot.httputil.get("http://grouphug.us/#{path}", opts)
40 reg = Regexp.new('<div class="content">.*?<p>(.*?)</p>', Regexp::MULTILINE)
43 @confessions << quote[0].ircify_html
46 confession = @confessions.pop
50 m.reply "failed to connect to grouphug.us"
56 plugin = GrouphugPlugin.new
58 plugin.map "grouphug [:num]",
59 :thread => true, :action => :confess, :requirements => { :num => /\d+/ }
60 plugin.map "confess [:num]",
61 :thread => true, :action => :confess, :requirements => { :num => /\d+/ }