Skip to content

Instantly share code, notes, and snippets.

@KTamas
Created June 9, 2011 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KTamas/1016454 to your computer and use it in GitHub Desktop.
Save KTamas/1016454 to your computer and use it in GitHub Desktop.
wo2008 irc bot
require 'rexml/document'
require 'time'
class WO2008Plugin < Plugin
WO_TAPI_PREFIX = "http://wormolympics.com/api/tournaments/"
def help(plugin, topic="")
"Worm Olympics 2008 Tourney Schedule InfoBot.\nTriggers: !!wo today, !!wo tomorrow, !!wo next, !!wo date, where date is YYYY-MM-DD i.e. !!wo 2008-08-31"
end
def tourneys(m, params)
next_data = @bot.httputil.get(WO_TAPI_PREFIX + "next")
(m.reply "Can't get the data for the next tourney!"; return) unless next_data
next_doc = REXML::Document.new(next_data)
(m.reply "Couldn't process the data for the next tourney!"; return) unless next_doc
next_msg = "Next tourney is " + next_doc.elements["schedule/next"].text + " and it's a(n) " + next_doc.elements["schedule/tournament/scheme"].text.gsub(" ", " ") + " in " + next_doc.elements["schedule/tournament/channel"].text + " hosted by " + next_doc.elements["schedule/tournament/hoster"].text + ". More info: " + next_doc.elements["schedule/tournament/url"].text
is_next = params[:when] == "next" ? true : false
if is_next
m.reply next_msg
return
else
tourney_data = @bot.httputil.get(WO_TAPI_PREFIX + params[:when])
(m.reply "Can't get data for " + params[:when] + "."; return) unless tourney_data
tourney_doc = REXML::Document.new(tourney_data)
(m.reply "Couldn't process the data for " + params[:when] + "!"; return) unless tourney_doc
has_tourneys = false
m.reply (params[:when] == "today" ? "Today's schedule: " : (is_next ? "" : "Schedule for " + params[:when]))
tourney_doc.elements.each('schedule/tournament') do |tourney|
has_tourneys = true
m.reply tourney.elements['time'].text.slice(0,5) + " - " + tourney.elements['scheme'].text.gsub(" ", " ") + " in " + tourney.elements['channel'].text + " hosted by " + tourney.elements['hoster'].text + " (" + tourney.elements['url'].text + ")"
end
(m.reply "There are no tourneys for " + params[:when] + "."; return) unless has_tourneys
m.reply next_msg
# m.reply ret_msg + next_msg
return
end
end
end
plugin = WO2008Plugin.new
plugin.map "wo :when", :action => 'tourneys', :defaults => {:when => 'today'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment