X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fgrouphug.rb;h=bf246b4c7f7fa23b3911dbf4169b4c01d59071a5;hb=de9ddb8a7eb436c0cb8db81289373dc169f484ba;hp=73c21eee54aba6fd88de5e32aad3cb08e06e72e5;hpb=5e8ddb21367309624a05ce45c7facee6620b5edf;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/grouphug.rb b/data/rbot/plugins/grouphug.rb index 73c21eee..bf246b4c 100644 --- a/data/rbot/plugins/grouphug.rb +++ b/data/rbot/plugins/grouphug.rb @@ -1,33 +1,45 @@ -# Plugin for the Ruby IRC bot (http://linuxbrit.co.uk/rbot/) -# (c) 2005 Mark Kretschmann -# Licensed under GPL V2. - -require "net/http" - +#-- vim:sw=2:et +#++ +# +# :title: Grouphug Plugin for rbot +# +# Author:: Mark Kretschmann +# Copyright:: (C) 2005 Mark Kretschmann +# License:: GPL v2 class GrouphugPlugin < Plugin - def help( plugin, topic="" ) - "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess ' for specific one." + def help( plugin, topic="" ) + return "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess ' for specific one." + end + + def confess(m, params) + opts = { :cache => false } + path = "random" + if params[:num] + path = "confessions/#{params[:num]}" + opts.delete(:cache) end - def privmsg( m ) - h = Net::HTTP.new( "grouphug.us", 80 ) - path = "/random" - path = "/confessions/#{m.params()}" if m.params() - data = bot.httputil.get(URI.parse("http://grouphug.us/#{path}")) + begin + data = @bot.httputil.get("http://grouphug.us/#{path}", opts) - reg = Regexp.new( '()(.*?)(

)', Regexp::MULTILINE ) - confession = reg.match( data )[4] - confession.gsub!( /<.*?>/, "" ) # Remove html tags - confession.gsub!( "\t", "" ) # Remove tab characters + reg = Regexp.new('()(.*?)(

)', + Regexp::MULTILINE) + confession = reg.match( data )[4].ircify_html + confession = "no confession ##{params[:num]} found" if confession.empty? and params[:num] - @bot.say(m.replyto, confession) - end + m.reply confession + rescue + m.reply "failed to connect to grouphug.us" + end + end end plugin = GrouphugPlugin.new -plugin.register("grouphug") -plugin.register("confess") +plugin.map "grouphug [:num]", + :thread => true, :action => :confess, :requirements => { :num => /\d+/ } +plugin.map "confess [:num]", + :thread => true, :action => :confess, :requirements => { :num => /\d+/ }