diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2010-12-11 14:42:17 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2010-12-11 14:42:17 +0100 |
commit | af4a5c5de2581f7082e7d3e404cb64dfccb410de (patch) | |
tree | 96ba774478951935311d2beb3ca3c4f9e1cbb28a /data/rbot/plugins/time.rb | |
parent | 9586b15bfd4f0b616dcc3994262029c9b4f9a6b6 (diff) |
time plugin: check if argument is a nick earlier
When !time <somenick> was being used and the user <somenick> hadn't set
his or her location, the bot would wrongly assume the argument was some
timezone.
Fix by checking against local nicks first.
Diffstat (limited to 'data/rbot/plugins/time.rb')
-rw-r--r-- | data/rbot/plugins/time.rb | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/data/rbot/plugins/time.rb b/data/rbot/plugins/time.rb index 4838a469..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 <Continent>/<City> to set your time zone." + if speaker + msg = _("I don't know where you are, use %{pfx}time set <Continent>/<City> to let me know") + else + msg = _("I don't know where %{nick} is, (s)he should use %{pfx}time set <Continent>/<City> 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 ) |