Module: Cogbot::Setup

Defined in:
lib/cogbot/setup.rb

Class Method Summary collapse

Class Method Details

.initObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cogbot/setup.rb', line 31

def self.init
  st = "\033[0;33m"
  en = "\033[m"

  default = YAML::load_file(File.join(ROOT_DIR,'config','cogbot.yml.defaults'))
  main = {}
  puts "You don't have a configuration file yet,"
  puts "let's make one in ~/.cogbot/cogbot.yml"
  puts
  puts "Please answer those few questions"

  print "#{st}What name will cogbot use ?#{en} [#{default['main']['nick']}] "
  main['nick'] = setvalue default['main']['nick']

  print "#{st}What irc server #{main['nick']} will connect to ?#{en} [#{default['main']['server']}] "
  main['server'] = setvalue default['main']['server']

  print "#{st}What port #{main['nick']} will use to connect to #{main['server']} ?#{en} [#{default['main']['port']}] "
  main['port'] = setvalue default['main']['port']

  print "#{st}Will #{main['nick']} use SSL to connect to #{main['server']}:#{main['port']} ?#{en} [#{default['main']['ssl'] ? 'Yn' : 'yN'}] "
  main['ssl'] = setbinary default['main']['ssl']

  print "#{st}What channels #{main['nick']} should join ?#{en} [#{default['main']['channels'].join(',')}] "
  main['channels'] = setlist default['main']['channels']

  print "#{st}What prefix #{main['nick']} will use to understand he's talked to ?#{en} [#{default['main']['prefix']}] "
  main['prefix'] = setvalue default['main']['prefix']

  print "#{st}What plugins will be enabled for #{main['nick']} ?#{en} [#{default['main']['plugins'].join(',')}] "
  main['plugins'] = setlist default['main']['plugins']

  FileUtils.mkdir_p(CONFIG_DIR) unless File.directory?(CONFIG_DIR)
  FileUtils.mkdir_p(LOG_DIR) unless File.directory?(LOG_DIR)
  File.open(CONFIG_FILE,'w') { |f| YAML::dump({ 'main' => main }, f) }
  return main
end

.setbinary(default) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/cogbot/setup.rb', line 13

def self.setbinary default
  input = $stdin.gets.chomp
  if input == ''
    default
  else
    input.downcase == 'y'
  end
end

.setlist(default) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/cogbot/setup.rb', line 22

def self.setlist default
  input = $stdin.gets.chomp
  if input == ''
    default
  else
    input.split(',')
  end
end

.setvalue(default) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/cogbot/setup.rb', line 4

def self.setvalue default
  input = $stdin.gets.chomp
  if input == ''
    default
  else
    input
  end
end