summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/grouphug.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-14 22:00:08 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-14 22:00:08 +0000
commitd29df50ddaf32536b105decefb135a0b86ee937f (patch)
treeeaf5505ba5a8b569aefdb157eff80cf902fe444d /data/rbot/plugins/grouphug.rb
parentad78fb47422664c9ce24a3b62194e42974274af7 (diff)
Modernize/optimize/cleanup a bunch of plugins
Remove some unnecessary plugin.register() calls, replace other by plugin.map() calls. Also use e.g. Array#pick_one instead of ar[rand(ar.length)]
Diffstat (limited to 'data/rbot/plugins/grouphug.rb')
-rw-r--r--data/rbot/plugins/grouphug.rb41
1 files changed, 20 insertions, 21 deletions
diff --git a/data/rbot/plugins/grouphug.rb b/data/rbot/plugins/grouphug.rb
index 53fc7f0a..87a7e32c 100644
--- a/data/rbot/plugins/grouphug.rb
+++ b/data/rbot/plugins/grouphug.rb
@@ -6,31 +6,30 @@ require "net/http"
class GrouphugPlugin < Plugin
- def help( plugin, topic="" )
- "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess <number>' for specific one."
+ def help( plugin, topic="" )
+ return "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess <number>' for specific one."
+ end
+
+ def confess(m, params)
+ path = "random"
+ path = "confessions/#{params[:num]}" if params[:num]
+ begin
+ data = bot.httputil.get_cached(URI.parse("http://grouphug.us/#{path}"))
+
+ reg = Regexp.new( '(<td class="conf-text")(.*?)(<p>)(.*?)(</p>)', Regexp::MULTILINE )
+ confession = reg.match( data )[4].ircify_html
+ confession = "no confession ##{params[:num]} found" if confession.empty? and params[:num]
+
+ m.reply confession
+ rescue
+ m.reply "failed to connect to grouphug.us"
end
-
- def privmsg( m )
- path = "/random"
- path = "/confessions/#{m.params()}" if m.params()
- begin
- data = bot.httputil.get_cached(URI.parse("http://grouphug.us/#{path}"))
-
- reg = Regexp.new( '(<td class="conf-text")(.*?)(<p>)(.*?)(</p>)', Regexp::MULTILINE )
- confession = reg.match( data )[4]
- confession.gsub!( /<.*?>/, "" ) # Remove html tags
- confession.gsub!( "\t", "" ) # Remove tab characters
-
- @bot.say(m.replyto, confession)
- rescue
- m.reply "failed to connect to grouphug.us"
- end
- end
+ end
end
plugin = GrouphugPlugin.new
-plugin.register("grouphug")
-plugin.register("confess")
+plugin.map "grouphug [:num]", :action => :confess, :requirements => { :num => /\d+/ }
+plugin.map "confess [:num]", :action => :confess, :requirements => { :num => /\d+/ }