4 # :title: World of Warcraft Realm Status plugin for rbot
6 # Author:: MrChucho (mrchucho@mrchucho.net)
7 # Copyright:: (C) 2006 Ralph M. Churchill
9 # Requires:: insatiable appetite for World of Warcraft
11 require 'rexml/document'
14 attr_accessor :name,:status,:type,:pop
15 def initialize(name,status,type,pop)
16 self.name = pretty_realm(name)
17 self.status = pretty_status(status)
18 self.type = pretty_type(type)
19 self.pop = pretty_pop(pop)
22 "#{name} (#{type}) Status: #{status} Population: #{pop}"
24 # just a longer, tabluar format
25 # might be good if displaying multiple realms
27 sprintf("%-8s %-20s %-8s %-9s\n%-11s %-22s %-8s %-9s",
28 "Status","Realm","Type","Population",
32 def pretty_status(status)
52 def pretty_realm(realm)
69 class RealmPlugin < Plugin
70 USAGE="realm <realm> => determine the status of a Warcraft realm"
82 def help(plugin,topic="")
85 def usage(m,params={})
88 def get_realm_status(realm_name)
90 xmldoc = @bot.httputil.get("http://www.worldofwarcraft.com/realmstatus/status.xml", :cache => false)
91 raise "unable to retrieve realm status" unless xmldoc
92 realm_list = (REXML::Document.new xmldoc).root
93 realm_data = realm_list.get_elements("//r[@n=\"#{realm_name}\"]").first
94 if realm_data and realm_data.attributes.any? then
96 realm_data.attributes['n'],
97 realm_data.attributes['s'].to_i,
98 realm_data.attributes['t'].to_i,
99 realm_data.attributes['l'].to_i)
102 "realm #{realm_name} not found."
105 "error retrieving realm status: #{err}"
109 if params[:realm_name] and params[:realm_name].any?
110 realm_name = params[:realm_name].collect{|tok|
113 @registry[m.sourcenick] = realm_name
114 m.reply get_realm_status(realm_name)
116 if @registry.has_key?(m.sourcenick)
117 realm_name = @registry[m.sourcenick]
118 m.reply get_realm_status(realm_name)
120 m.reply "I don't know which realm you want.\n#{USAGE}"
125 plugin = RealmPlugin.new
126 plugin.map 'realm *realm_name',
127 :defaults => {:realm_name => false}, :thread => true