forked from pickdenis/ps-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnector.rb
87 lines (57 loc) · 1.6 KB
/
connector.rb
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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'faye/websocket'
require 'eventmachine'
require 'em-http-request'
require 'json'
require 'fileutils'
require 'yaml'
require './app/chatbot.rb'
require './app/chathandler.rb'
require './app/battle.rb'
require './app/consoleinput.rb'
require './app/socketinput.rb'
require './app/utils.rb'
require './app/pokedata.rb'
if __FILE__ == $0
cfg_file = ARGV[0]
if cfg_file
puts "Using config file: #{cfg_file}."
else
puts "No config file specified, attempting to use 'config.yml'"
cfg_file = 'config.yml'
end
if File.exist?(cfg_file)
configs = YAML.load(File.open(cfg_file))["bots"]
else
raise "config file specified #{cfg_file} does not exist!"
end
$0 = 'pschatbot'
EM.run do
bots = []
configs.each do |options|
bot = Chatbot.new(
id: options['id'],
name: options['name'],
pass: options['pass'],
room: options['room'], # compatibility
rooms: options['rooms'],
console: options['console'],
server: (options['server'] || nil),
log: options['log'],
usetriggers: options['usetriggers'],
triggers: options['triggers'],
dobattles: options['dobattles'],
allconfig: options)
bots << bot
end
exiting = false
exitblk = proc do |&callback|
next if exiting || bots.any?(&:initializing)
exiting = true
bots.each do |bot|
bot.exit_gracefully(&callback)
end
end
at_exit &exitblk
Signal.trap("INT") { exitblk.call { Process.exit(0) } }
end
end