]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/time.rb
script plugin: per-script permissions
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / time.rb
index f13f5a808922cf038199696a4279e8d1c6c960eb..4e7543c8be2317a0f6fc78f191602509985c4d0f 100644 (file)
@@ -1,13 +1,18 @@
-# Time Zone Plugin for rbot
-# (c) 2006 Ian Monroe <ian@monroe.nu>
-# Licensed under MIT License.
+#-- vim:sw=2:et
+#++
+#
+# :title: Time Zone Plugin for rbot
+#
+# Author:: Ian Monroe <ian@monroe.nu>
+# Copyright:: (C) 2006 Ian Monroe
+# License:: MIT license
 
 require 'tzinfo'
 
 class TimePlugin < Plugin
 
   def help(plugin, topic="")
-  "time <time zone> to get the local time of a certain location. <time zone> can be <Continent/City> or <two character country code>. time <nick> to see the local time of that person if their time zone is set. time admin set <nick> <time zone> to set the time zone for another user."
+  "time <time zone> to get the local time of a certain location. <time zone> can be <Continent/City> or <two character country code>. time <nick> to see the local time of that person if their time zone is set. time admin set <nick> <time zone> to set the time zone for another user. time [admin] reset [nick] to let the bot forget about the tzinfo about someone"
   end
 
   def initialize
@@ -47,18 +52,19 @@ class TimePlugin < Plugin
             zone = arr.join( sp )
         }
     
-    TZInfo::Timezone.get( zone ).now
+    tz = TZInfo::Timezone.get( zone )
+    "#{tz.friendly_identifier} - #{tz.now.strftime( '%a %b %d %H:%M' )} #{tz.current_period.abbreviation}"
   end
 
   def showTime(m, params)
     zone = params[:where].join('_')
     if params[:where].size > 0 then
       begin
-        m.reply "#{zone} - #{getTime( m,  zone )}"
+        m.reply getTime( m,  zone )
       rescue TZInfo::InvalidTimezoneIdentifier
         if @registry.has_key?( zone ) then
           zone =  @registry[ zone ]
-          m.reply "#{zone} - #{getTime( m,  zone )}"
+          m.reply getTime( m,  zone )
         else
           m.reply "#{zone} is an unknown time."
         end
@@ -66,7 +72,7 @@ class TimePlugin < Plugin
     else
       if @registry.has_key?( m.sourcenick) then
         zone = @registry[ m.sourcenick ]
-        m.reply "#{m.sourcenick}: #{zone} - #{getTime( m,  zone )}"
+        m.reply "#{m.sourcenick}: #{getTime( m,  zone )}"
       else
         m.reply "#{m.sourcenick}: use time set <Continent/City> to set your timezone."
       end
@@ -81,11 +87,23 @@ class TimePlugin < Plugin
     end
   end
 
+  def resetUserZone( m, params )
+    s = resetZone( m, m.sourcenick)
+  end
+
   def setAdminZone( m, params )
     if params[:who] and params[:where].size > 0 then
       s = setZone( m, params[:who], params[:where].join('_') )
     else
-      m.reply 'Requires a nick and the Continent/City or country code.'
+      m.reply "Requires a nick and the Continent/City or country code"
+    end
+  end
+
+  def resetAdminZone( m, params )
+    if params[:who]
+      s = resetZone( m, params[:who])
+    else
+      m.reply "Requires a nick"
     end
   end
 
@@ -97,10 +115,21 @@ class TimePlugin < Plugin
       return
     end
     @registry[ user ] = zone
+    m.reply "Ok, I'll remember that #{user} is on the #{zone} timezone"
+  end
+
+  def resetZone( m, user )
+    @registry.delete(user)
+    m.reply "Ok, I've forgotten #{user}'s timezone"
   end
 end
 
 plugin = TimePlugin.new
-plugin.map 'time set *where', :action=> 'setUserZone',  :defaults => {:where => false}
-plugin.map 'time admin set :who *where', :action=> 'setAdminZone', :defaults => {:where => false, :who=>false}, :auth=> 'timeadmin'
+
+plugin.default_auth('admin', false)
+
+plugin.map 'time set [time][zone] [to] *where', :action=> 'setUserZone', :defaults => {:where => false}
+plugin.map 'time reset [time][zone]', :action=> 'resetUserZone'
+plugin.map 'time admin set [time][zone] [for] :who [to] *where', :action=> 'setAdminZone', :defaults => {:who => false, :where => false}
+plugin.map 'time admin reset [time][zone] [for] :who', :action=> 'resetAdminZone', :defaults => {:who => false}
 plugin.map 'time *where', :action => 'showTime', :defaults => {:where => false}