diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2006-02-08 18:47:38 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2006-02-08 18:47:38 +0000 |
commit | 23f5b9a75731b7c5fcd1c92a77e1cd504abee183 (patch) | |
tree | 8400596da5ac1051cd390666e1f7667839770aac /data/rbot/plugins/wow.rb | |
parent | 8246bd135ebf319beae8fec39620f4c4c7e54601 (diff) |
From Ralph Churchill, a new weather plugin using the new XML format rather
than METAR! Yay, goodbye ugly METAR parser :)
Also, a wow plugin, as requested by various folks, for checking realm status
:)
Diffstat (limited to 'data/rbot/plugins/wow.rb')
-rw-r--r-- | data/rbot/plugins/wow.rb | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/data/rbot/plugins/wow.rb b/data/rbot/plugins/wow.rb new file mode 100644 index 00000000..4faadaf4 --- /dev/null +++ b/data/rbot/plugins/wow.rb @@ -0,0 +1,123 @@ +# +# World of Warcraft Realm Status plugin for rbot +# by MrChucho (mrchucho@mrchucho.net) +# Copyright (C) 2006 Ralph M. Churchill +# +# Requires: insatiable appetite for World of Warcraft +# +require 'open-uri' +require 'rexml/document' + +class Realm + attr_accessor :name,:status,:type,:pop + def initialize(name,status,type,pop) + self.name = pretty_realm(name) + self.status = pretty_status(status) + 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 + # just a longer, tabluar format + # might be good if displaying multiple realms + def _to_s + sprintf("%-8s %-20s %-8s %-9s\n%-11s %-22s %-8s %-9s", + "Status","Realm","Type","Population", + status,name,type,pop) + end +private + def pretty_status(status) + case status + when 1 + "3Up" + when 2 + "5Down" + end + end + def pretty_pop(pop) + case pop + when 1 + "3Low" + when 2 + "7Medium" + when 3 + "4High" + when 4 + "5Max(Queued)" + end + end + def pretty_realm(realm) + "#{realm}" + end + def pretty_type(type) + case type + when 0 + 'RP-PVP' + when 1 + 'Normal' + when 2 + 'PVP' + when 3 + 'RP' + end + end +end + +class RealmPlugin < Plugin + USAGE="realm <realm> => determine the status of a Warcraft realm" + def initialize + super + class << @registry + def store(val) + val + end + def restore(val) + val + end + end + end + def help(plugin,topic="") + USAGE + end + def usage(m,params={}) + m.reply USAGE + 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) + 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 + end + end +end +plugin = RealmPlugin.new +plugin.map 'realm *realm_name', :defaults => {:realm_name => false} |