summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/grouphug.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-12-12 23:00:27 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-12-12 23:00:27 +0000
commit0a8521c9c11ef0de35de2ffaa84819ecbc44d3b7 (patch)
treeb243ece8db94632391f6db1abe83e1463c7bc1f7 /data/rbot/plugins/grouphug.rb
parent830258cd76adb3a40d1c2a854f140b3e1faf1615 (diff)
exception handling
Diffstat (limited to 'data/rbot/plugins/grouphug.rb')
-rw-r--r--data/rbot/plugins/grouphug.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/data/rbot/plugins/grouphug.rb b/data/rbot/plugins/grouphug.rb
index 73c21eee..aa3bf6d7 100644
--- a/data/rbot/plugins/grouphug.rb
+++ b/data/rbot/plugins/grouphug.rb
@@ -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