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
12 require 'rexml/document'
15 attr_accessor :name,:status,:type,:pop
16 def initialize(name,status,type,pop)
17 self.name = pretty_realm(name)
18 self.status = pretty_status(status)
19 self.type = pretty_type(type)
20 self.pop = pretty_pop(pop)
22 def Realm.get_realm_status(realm_name)
24 open("http://www.worldofwarcraft.com/realmstatus/status.xml") do |xmldoc|
25 realm_list = (REXML::Document.new xmldoc).root
26 realm_data = realm_list.elements["r[@n=\"#{realm_name}\"]"]
27 if realm_data and realm_data.attributes.any? then
29 realm_data.attributes['n'],
30 realm_data.attributes['s'].to_i,
31 realm_data.attributes['t'].to_i,
32 realm_data.attributes['l'].to_i)
34 "Realm, #{realm_name}, not found."
38 "Error retrieving realm status: #{err}"
42 "#{name} (#{type}) Status: #{status} Population: #{pop}"
44 # just a longer, tabluar format
45 # might be good if displaying multiple realms
47 sprintf("%-8s %-20s %-8s %-9s\n%-11s %-22s %-8s %-9s",
48 "Status","Realm","Type","Population",
52 def pretty_status(status)
72 def pretty_realm(realm)
89 class RealmPlugin < Plugin
90 USAGE="realm <realm> => determine the status of a Warcraft realm"
102 def help(plugin,topic="")
105 def usage(m,params={})
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 Realm.get_realm_status(realm_name)
116 if @registry.has_key?(m.sourcenick)
117 realm_name = @registry[m.sourcenick]
118 m.reply Realm.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', :defaults => {:realm_name => false}