X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=data%2Frbot%2Fplugins%2Ftime.rb;h=5c3189f60ad2d6b0164c215d036d4f22b33e1e97;hb=052217de30c59206d7025b582d4604557a747470;hp=4a1effd79d77ce3fd918541b9646a6c5055ba8f8;hpb=edd4f0e4f2cc93d8b02047384aa61f2f830b897a;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/time.rb b/data/rbot/plugins/time.rb index 4a1effd7..5c3189f6 100644 --- a/data/rbot/plugins/time.rb +++ b/data/rbot/plugins/time.rb @@ -66,33 +66,48 @@ class TimePlugin < Plugin end def showTime(m, params) - zone = params[:where].join('_') - if params[:where].size > 0 then - begin - m.reply getTime( m, zone ) - rescue TZInfo::InvalidTimezoneIdentifier - if @registry.has_key?( zone ) then - zone = @registry[ zone ] - m.reply getTime( m, zone ) - else - parse(m, params) - end - end + nick = nil + zone = nil + speaker = false + case params[:where].size + when 0 + nick = m.sourcenick + speaker = true + when 1 + zone = params[:where].first + nick = m.channel.get_user(zone) + speaker = (nick == m.sourcenick) else - if @registry.has_key?( m.sourcenick) then - zone = @registry[ m.sourcenick ] - m.reply "#{m.sourcenick}: #{getTime( m, zone )}" + zone = params[:where].join('_') + end + + # now we have a non-nil nick iff we want user information + if nick + if @registry.has_key? nick + zone = @registry[nick] else - m.reply "#{m.sourcenick}: use time set to set your timezone." + if speaker + msg = _("I don't know where you are, use %{pfx}time set / to let me know") + else + msg = _("I don't know where %{nick} is, (s)he should use %{pfx}time set / to let me know") + end + m.reply(msg % { :pfx => @bot.config['core.address_prefix'].first, :nick => nick }) + return false end end + + begin + m.reply getTime( m, zone ) + rescue TZInfo::InvalidTimezoneIdentifier + parse(m, params) + end end def setUserZone( m, params ) if params[:where].size > 0 then s = setZone( m, m.sourcenick, params[:where].join('_') ) else - m.reply "Requires Continent/City or country code" + m.reply "Requires / or country code" end end @@ -104,7 +119,7 @@ class TimePlugin < Plugin 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 / or country code" end end @@ -120,16 +135,16 @@ class TimePlugin < Plugin begin getTime( m, zone ) rescue TZInfo::InvalidTimezoneIdentifier - m.reply "#{zone} is an invalid timezone. Format is Continent/City or a two character country code." + m.reply "#{zone} is an invalid time zone. Format is / or a two character country code." return end @registry[ user ] = zone - m.reply "Ok, I'll remember that #{user} is on the #{zone} timezone" + m.reply "Ok, I'll remember that #{user} is on the #{zone} time zone" end def resetZone( m, user ) @registry.delete(user) - m.reply "Ok, I've forgotten #{user}'s timezone" + m.reply "Ok, I've forgotten #{user}'s time zone" end def parse(m, params) @@ -159,8 +174,12 @@ class TimePlugin < Plugin offset = (time - now).abs raise if offset < 0.1 rescue => e - m.reply _("unintelligible time") - return + if str.match(/^\d+$/) + time = Time.at(str.to_i) + else + m.reply _("unintelligible time") + return + end end if zone = @registry[m.sourcenick] @@ -177,8 +196,9 @@ class TimePlugin < Plugin def on_timezone(to_zone) original_zone = ENV["TZ"] ENV["TZ"] = to_zone - return yield + ret = yield ENV["TZ"] = original_zone + return ret end end