-
Notifications
You must be signed in to change notification settings - Fork 4
/
quote.rb
31 lines (24 loc) · 929 Bytes
/
quote.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'open-uri'
require 'hpricot'
class Quote < CampfireBot::Plugin
on_command 'quote', :quote
def quote(msg)
# Get our quotes from the web
url = "http://quotes4all.net/rss/000010110/quotes.xml"
response = ''
begin
# open-uri RDoc: http://stdlib.rubyonrails.org/libdoc/open-uri/rdoc/index.html
open(url, "User-Agent" => "Ruby/#{RUBY_VERSION}",
"From" => "Campfire") { |f|
# Save the response body
response = f.read
}
# HPricot RDoc: http://code.whytheluckystiff.net/hpricot/
doc = Hpricot(response)
msg.speak((doc/"*/item/description").inner_html.gsub(/<\/?[^>]*>/,"").gsub(/\s+/," ").gsub(/\"e;/,"'").gsub(/\&[\#|\w]\w+\;/,"").gsub(/\#39\;/,"'"))
msg.speak((doc/"*/item/title").inner_html)
rescue Exception => e
msg.speak(e, "\n")
end
end
end