Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds the LocalTime plugin that queries the local time of a given city.

  • Loading branch information...
commit cbc36c59adceeb6e64a6a31ec0521547e4bcbf07 1 parent 0d91006
Dave Wilkinson II wilkie authored
Showing with 15 additions and 0 deletions.
  1. +15 −0 lib/xombot/plugins/local_time.rb
15 lib/xombot/plugins/local_time.rb
View
@@ -0,0 +1,15 @@
+class LocalTime < XOmBot::Plugin
+ TIME_QUERY_URL = "http://www.timeanddate.com/worldclock/results.html?query="
+
+ match /time (.+)/
+ help "gives the local time in the given city"
+ usage "time Melbourne -- gives the time in Melbourne Australia"
+
+ def execute(m, place)
+ @agent = Mechanize.new
+ page = @agent.get "#{TIME_QUERY_URL}#{place}"
+ current_time = page.search '//strong[@id="ct"]'
+
+ m.reply "Time in #{place}: #{current_time.first.content}"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.