summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-08-06 23:53:47 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-08-06 23:53:47 +0200
commitc55aef76a4298c70667ebe932c579ec2497ee191 (patch)
tree7e871051598d000df2f98ed6b438ac7f1942903f /data/rbot/plugins
parent963283386a5772b089452f1524dc8307d00cdaa7 (diff)
wow plugin: rbotify XML retrieval
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/wow.rb63
1 files changed, 31 insertions, 32 deletions
diff --git a/data/rbot/plugins/wow.rb b/data/rbot/plugins/wow.rb
index ec4a19d7..caf3925b 100644
--- a/data/rbot/plugins/wow.rb
+++ b/data/rbot/plugins/wow.rb
@@ -8,7 +8,6 @@
#
# Requires:: insatiable appetite for World of Warcraft
-require 'open-uri'
require 'rexml/document'
class Realm
@@ -19,25 +18,6 @@ class Realm
self.type = pretty_type(type)
self.pop = pretty_pop(pop)
end
- def Realm.get_realm_status(realm_name)
- begin
- open("http://www.worldofwarcraft.com/realmstatus/status.xml") do |xmldoc|
- realm_list = (REXML::Document.new xmldoc).root
- realm_data = realm_list.elements["r[@n=\"#{realm_name}\"]"]
- if realm_data and realm_data.attributes.any? then
- realm = Realm.new(
- realm_data.attributes['n'],
- realm_data.attributes['s'].to_i,
- realm_data.attributes['t'].to_i,
- realm_data.attributes['l'].to_i)
- else
- "Realm, #{realm_name}, not found."
- end
- end
- rescue => err
- "Error retrieving realm status: #{err}"
- end
- end
def to_s
"#{name} (#{type}) Status: #{status} Population: #{pop}"
end
@@ -105,21 +85,40 @@ class RealmPlugin < Plugin
def usage(m,params={})
m.reply USAGE
end
+ def get_realm_status(realm_name)
+ begin
+ xmldoc = @bot.httputil.get("http://www.worldofwarcraft.com/realmstatus/status.xml", :cache => false)
+ raise "unable to retrieve realm status" unless xmldoc
+ realm_list = (REXML::Document.new xmldoc).root
+ realm_data = realm_list.elements["r[@n=\"#{realm_name}\"]"]
+ if realm_data and realm_data.attributes.any? then
+ realm = Realm.new(
+ realm_data.attributes['n'],
+ realm_data.attributes['s'].to_i,
+ realm_data.attributes['t'].to_i,
+ realm_data.attributes['l'].to_i)
+ else
+ "Realm, #{realm_name}, not found."
+ end
+ rescue => err
+ "Error retrieving realm status: #{err}"
+ end
+ end
def realm(m,params)
- if params[:realm_name] and params[:realm_name].any?
- realm_name = params[:realm_name].collect{|tok|
- tok.capitalize
- }.join(' ')
- @registry[m.sourcenick] = realm_name
- m.reply Realm.get_realm_status(realm_name)
+ if params[:realm_name] and params[:realm_name].any?
+ realm_name = params[:realm_name].collect{|tok|
+ tok.capitalize
+ }.join(' ')
+ @registry[m.sourcenick] = realm_name
+ m.reply get_realm_status(realm_name)
+ else
+ if @registry.has_key?(m.sourcenick)
+ realm_name = @registry[m.sourcenick]
+ m.reply get_realm_status(realm_name)
else
- if @registry.has_key?(m.sourcenick)
- realm_name = @registry[m.sourcenick]
- m.reply Realm.get_realm_status(realm_name)
- else
- m.reply "I don't know which realm you want.\n#{USAGE}"
- end
+ m.reply "I don't know which realm you want.\n#{USAGE}"
end
+ end
end
end
plugin = RealmPlugin.new