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
13 REG = Regexp.new('<div class="content">\s*<p>(.*?)</p>\s+</div>', Regexp::MULTILINE)
16 @confessions = Array.new
19 def help( plugin, topic="" )
20 return "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess <number>' for specific one."
23 def confess(m, params)
24 opts = { :cache => false }
27 # Fetch a specific question - separate from cache
29 path = "confessions/#{params[:num]}"
31 data = @bot.httputil.get("http://grouphug.us/#{path}", opts)
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)
42 @confessions << quote[0].ircify_html
45 confession = @confessions.pop
49 m.reply "failed to connect to grouphug.us"
55 plugin = GrouphugPlugin.new
57 plugin.map "grouphug [:num]",
58 :thread => true, :action => :confess, :requirements => { :num => /\d+/ }
59 plugin.map "confess [:num]",
60 :thread => true, :action => :confess, :requirements => { :num => /\d+/ }