Created
June 15, 2011 09:56
-
-
Save smiler/1026816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'rexml/document' | |
class EveOnline < Plugin | |
def on_load() | |
@triggers = Hash[".tq" => "get_tq_status"] | |
end | |
def name | |
"EVE Online server status v0.1" | |
end | |
def get_tq_status(nick, user, host, channel, args) | |
url = URI.parse('http://api.eve-online.com') | |
begin | |
request = Net::HTTP.start(url.host, url.port) { |http| | |
http.get('/Server/ServerStatus.xml.aspx') | |
} | |
rescue => ex | |
$irc.putchan(channel, "Failed to connect to API server: #{ex.message}") | |
return | |
end | |
status = REXML::Document.new request.body | |
if status.elements['/eveapi/error'] != nil | |
$irc.putchan(channel, "Error: " + status.elements['/eveapi/error'].text) | |
else | |
open = status.elements['/eveapi/result/serverOpen'].text.strip.downcase | |
if open == "true" | |
count = status.elements['/eveapi/result/onlinePlayers'].text | |
$irc.putchan(channel, "TQ is online with #{count} players.") | |
else | |
$irc.putchan(channel, "TQ is offline.") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment