Class: Tkellem::TimezoneCommand

Inherits:
Tkellem::TkellemBot::Command show all
Defined in:
lib/tkellem/plugins/backlog.rb

Instance Attribute Summary

Attributes inherited from Tkellem::TkellemBot::Command

#args, #bouncer, #conn, #options, #opts

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tkellem::TkellemBot::Command

admin_option, admin_user?, build_options, #initialize, option, register, resources, #respond, run, #show_help, #user

Constructor Details

This class inherits a constructor from Tkellem::TkellemBot::Command

Class Method Details

.admin_only?Boolean

Returns:

  • (Boolean)


287
288
289
# File 'lib/tkellem/plugins/backlog.rb', line 287

def self.admin_only?
  false
end

Instance Method Details

#executeObject



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/tkellem/plugins/backlog.rb', line 291

def execute
  backlog = Backlog.get_instance(bouncer)
  device = backlog.get_device(conn)

  if !args.empty?
    arg = args.join(' ')
    tz = ActiveSupport::TimeZone[arg]
    if !tz
      conn.say_as_tkellem "Unknown time zone '#{arg}'; please use an IANA time zone"
      return
    end
    device.time_zone = tz
  end

  if !device.time_zone
    conn.say_as_tkellem "<time zone not set; using #{Time.now.zone}>"
    return
  end

  # try to find a friendlier name to show the user
  begin
    country_zone = TZInfo::Country.get(device.country).zone_info.detect { |z| z.identifier == device.time_zone.name }
    if country_zone
      conn.say_as_tkellem country_zone.description_or_friendly_identifier
      return
    end
  rescue TZInfo::InvalidCountryCode
  end

  conn.say_as_tkellem device.time_zone.tzinfo.friendly_identifier
end