Module: Cogbot::Setup

Extended by:
Setup
Included in:
Setup
Defined in:
lib/cogbot/setup.rb

Instance Method Summary collapse

Instance Method Details

#initObject



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
# File 'lib/cogbot/setup.rb', line 32

def 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']

  write(main)
  return main
end

#setbinary(default) ⇒ Object



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

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

#setlist(default) ⇒ Object



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

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

#setvalue(default) ⇒ Object



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

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

#write(content) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/cogbot/setup.rb', line 68

def write(content)
  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') do |f| 
    YAML::dump({ 'main' => content }, f)
  end
end