]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/grouphug.rb
Make sure the bot doesn't tell to itself
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / grouphug.rb
index 73c21eee54aba6fd88de5e32aad3cb08e06e72e5..aa3bf6d784e96fdf4cebf300c07ca3f6c35ca20d 100644 (file)
@@ -11,17 +11,20 @@ class GrouphugPlugin < Plugin
     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}"))
-
-        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)
+        begin
+          data = bot.httputil.get(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