Class: Irc::Bot::Config::Wizard

Inherits:
Object
  • Object
show all
Defined in:
/home/apoc/projects/ruby/rbot/lib/rbot/config.rb

Instance Method Summary (collapse)

Constructor Details

- (Wizard) initialize(bot)

Returns a new instance of Wizard



374
375
376
377
378
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 374

def initialize(bot)
  @bot = bot
  @manager = Config.manager
  @questions = @manager.items.values.find_all {|i| i.wizard }
end

Instance Method Details

- (Object) run



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 380

def run()
  $stdout.sync = true
  puts _("First time rbot configuration wizard")
  puts "===================================="
  puts _("This is the first time you have run rbot with a config directory of: #{@bot.botclass}")
  puts _("This wizard will ask you a few questions to get you started.")
  puts _("The rest of rbot's configuration can be manipulated via IRC once rbot is connected and you are auth'd.")
  puts "-----------------------------------"

  return unless @questions
  @questions.sort{|a,b| a.order <=> b.order }.each do |q|
    puts _(q.desc)
    begin
      print q.key.to_s + " [#{q.to_s}]: "
      response = STDIN.gets
      response.chop!
      unless response.empty?
        q.set_string response, false
      end
      puts _("configured #{q.key} => #{q.to_s}")
      puts "-----------------------------------"
    rescue ArgumentError => e
      puts _("failed to set #{q.key}: #{e.message}")
      retry
    end
  end
end