X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ftime.rb;h=5c3189f60ad2d6b0164c215d036d4f22b33e1e97;hb=6423121e96dd602093cbda86de1922e95a45ff07;hp=efea466f1d2012548372a42fb104b16478559d8c;hpb=284bcbf4b29184717cd2e0986d4c2007ee6a930c;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/time.rb b/data/rbot/plugins/time.rb index efea466f..5c3189f6 100644 --- a/data/rbot/plugins/time.rb +++ b/data/rbot/plugins/time.rb @@ -66,26 +66,41 @@ 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 time zone." + 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 ) @@ -181,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