-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathshowdown-chatbot
139 lines (125 loc) · 3.9 KB
/
showdown-chatbot
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/env node
/**
* Showdown ChatBot runner
* Showdown ChatBot is distributed under the terms of the MIT License
* (https://github.com/AgustinSRG/Showdown-ChatBot/blob/master/LICENSE)
*
* Run this file in order to start Showdown ChatBot application
* Command line arguments options:
* -p [port] to change the http port
* -b [address] to change the bind address
* -d [path] to change the data / configuration path
* -i [instance] to change the instance (overwrites -d)
* -sp [port] to change the https port
* -k [ssl-key] to set the ssl key file
* -c [ssl-cert] to set the ssl certificate file
* --static to set static mode
*/
'use strict';
const Util = require("util");
const Path = require("path");
const Package = require(Path.resolve(__dirname, 'package.json'));
console.log(Util.format('Showdown-ChatBot %s', Package.version));
require(Path.resolve(__dirname, 'src/dependencies.js'));
console.log('Initializing...');
/* Shell Options */
let shellOpts = Object.create(null);
for (let i = 0; i < process.argv.length; i++) {
let tag = process.argv[i].trim();
if (tag.charAt(0) === '-') {
if (process.argv[i + 1]) {
shellOpts[tag] = process.argv[i + 1];
} else {
shellOpts[tag] = true;
}
}
}
let env = Object.create(null);
for (let key in shellOpts) {
switch (key) {
case '-port':
case '-p':
if (shellOpts[key] !== true && !isNaN(parseInt(shellOpts[key]))) {
env.port = parseInt(shellOpts[key]);
console.log("Shell Options: PORT set to " + env.port);
} else {
console.log("Invalid PORT set. Usage: node showdown-chatbot [-p] [PORT]");
process.exit(1);
}
break;
case '-bindaddress':
case '-b':
if (shellOpts[key] !== true) {
env.bindaddress = shellOpts[key].trim();
console.log("Shell Options: BINADDRESS set to " + env.bindaddress);
} else {
console.log("Invalid BINADDRESS set. Usage: node showdown-chatbot [-b] [BINADDRESS]");
process.exit(1);
}
break;
case '-dir':
case '-d':
if (shellOpts[key] !== true) {
env.dir = Path.resolve(__dirname, shellOpts[key]);
console.log("Shell Options: DATA-DIRECTORY set to " + env.dir);
} else {
console.log("Invalid DATA-DIRECTORY set. Usage: node showdown-chatbot [-d] [DATA-DIRECTORY]");
process.exit(1);
}
break;
case '-instance':
case '-i':
if (shellOpts[key] !== true) {
env.dir = Path.resolve(__dirname, "instances", shellOpts[key]);
console.log("Shell Options: DATA-DIRECTORY set to " + env.dir);
} else {
console.log("Invalid INSTANCE set. Usage: node showdown-chatbot [-i] [INSTANCE]");
process.exit(1);
}
break;
case '-sslport':
case '-sp':
if (shellOpts[key] !== true && !isNaN(parseInt(shellOpts[key]))) {
env.sslport = parseInt(shellOpts[key]);
console.log("Shell Options: SSL PORT set to " + env.sslport);
} else {
console.log("Invalid PORT set. Usage: node showdown-chatbot [-sp] [PORT]");
process.exit(1);
}
break;
case '-key':
case '-k':
if (shellOpts[key] !== true) {
env.sslkey = Path.resolve(__dirname, shellOpts[key]);
console.log("Shell Options: SSL-KEY set to " + env.sslkey);
} else {
console.log("Invalid SSL-KEY set. Usage: node showdown-chatbot [-k] [SSL-KEY]");
process.exit(1);
}
break;
case '-cert':
case '-c':
if (shellOpts[key] !== true) {
env.sslcert = Path.resolve(__dirname, shellOpts[key]);
console.log("Shell Options: SSL-CERT set to " + env.sslcert);
} else {
console.log("Invalid SSL-CERT set. Usage: node showdown-chatbot [-c] [SSL-CERT]");
process.exit(1);
}
break;
case '--static':
console.log("MODE: Static Mode");
env.staticmode = true;
break;
}
}
env.package = Package;
try {
env.config = require(Path.resolve(__dirname, 'config.js'));
console.log("Loaded configuration");
} catch (err) {
console.log("Using default configuration");
env.config = require(Path.resolve(__dirname, 'config-example.js'));
}
/* Require Main File */
require(Path.resolve(__dirname, 'src/index.js')).setup(env);