-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.rb
More file actions
36 lines (27 loc) · 742 Bytes
/
Copy pathstart.rb
File metadata and controls
36 lines (27 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require './bot'
require 'yaml'
channels = ARGV.map{|chan| "##{chan}"}
bots = Set.new
if !File.exists?('./PIDS')
File.open('./PIDS', 'w') { |f| f.puts Hash.new.to_yaml }
end
pids = YAML.load_file('./PIDS')
channels.each do |channel|
if pids.has_key?(channel)
puts "There is already a bot running in #{channel} (PID: #{pids[channel]})"
next
end
bot = Bot.new(channel)
bots << bot
puts "Bot created for #{channel}" unless bot.nil?
puts "Bot could not be created for #{channel}" if bot.nil?
end
bots.each do |bot|
pids[bot.channel] = fork do
bot.start
end
puts "Bot started in #{bot.channel}"
Process.detach(pids[bot.channel])
end
puts pids.inspect
File.open('./PIDS', 'w') { |f| f.puts pids.to_yaml }