Class: Tkellem::TkellemBot::SettingCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/tkellem/tkellem_bot.rb

Instance Attribute Summary

Attributes inherited from Command

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

admin_only?, 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

.setting_resources(name) ⇒ Object



422
423
424
425
# File 'lib/tkellem/tkellem_bot.rb', line 422

def self.setting_resources(name)
  @setting_resources ||= YAML.load_file(File.expand_path("../../../resources/setting_descriptions.yml", __FILE__))
  @setting_resources[name] || {}
end

Instance Method Details

#executeObject



427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/tkellem/tkellem_bot.rb', line 427

def execute
  case args.size
  when 0
    r "Settings:"
    Setting.all.each { |s| r "    #{s}" }
  when 1
    setting = Setting.find_by_name(args.first)
    if setting
      r(setting.to_s)
      desc = self.class.setting_resources(setting.name)
      if desc['help']
        desc['help'].each_line { |l| r l }
      end
    else
      r("No setting with that name")
    end
  when 2
    setting = Setting.set(args[0], args[1])
    setting ? r(setting.to_s) : r("No setting with that name")
  else
    show_help
  end
end