2 # World of Warcraft Realm Status plugin for rbot
3 # by MrChucho (mrchucho@mrchucho.net)
4 # Copyright (C) 2006 Ralph M. Churchill
6 # Requires: insatiable appetite for World of Warcraft
9 require 'rexml/document'
12 attr_accessor :name,:status,:type,:pop
13 def initialize(name,status,type,pop)
14 self.name = pretty_realm(name)
15 self.status = pretty_status(status)
16 self.type = pretty_type(type)
17 self.pop = pretty_pop(pop)
19 def Realm.get_realm_status(realm_name)
21 open("http://www.worldofwarcraft.com/realmstatus/status.xml") do |xmldoc|
22 realm_list = (REXML::Document.new xmldoc).root
23 realm_data = realm_list.elements["r[@n=\"#{realm_name}\"]"]
24 if realm_data and realm_data.attributes.any? then
26 realm_data.attributes['n'],
27 realm_data.attributes['s'].to_i,
28 realm_data.attributes['t'].to_i,
29 realm_data.attributes['l'].to_i)
31 "Realm, #{realm_name}, not found."
35 "Error retrieving realm status: #{err}"
39 "#{name} (#{type}) Status: #{status} Population: #{pop}"
41 # just a longer, tabluar format
42 # might be good if displaying multiple realms
44 sprintf("%-8s %-20s %-8s %-9s\n%-11s %-22s %-8s %-9s",
45 "Status","Realm","Type","Population",
49 def pretty_status(status)
69 def pretty_realm(realm)
86 class RealmPlugin < Plugin
87 USAGE="realm <realm> => determine the status of a Warcraft realm"
99 def help(plugin,topic="")
102 def usage(m,params={})
106 if params[:realm_name] and params[:realm_name].any?
107 realm_name = params[:realm_name].collect{|tok|
110 @registry[m.sourcenick] = realm_name
111 m.reply Realm.get_realm_status(realm_name)
113 if @registry.has_key?(m.sourcenick)
114 realm_name = @registry[m.sourcenick]
115 m.reply Realm.get_realm_status(realm_name)
117 m.reply "I don't know which realm you want.\n#{USAGE}"
122 plugin = RealmPlugin.new
123 plugin.map 'realm *realm_name', :defaults => {:realm_name => false}