-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure.js
executable file
·125 lines (109 loc) · 3.87 KB
/
configure.js
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
var fs = require('fs');
const WickrIOBotAPI = require('wickrio-bot-api');
const util = require('util')
require("dotenv").config({
path: `.env.configure`
})
var wickrIOConfigure;
process.stdin.resume(); //so the program will not close instantly
function exitHandler(options, err) {
try {
if (err) {
process.kill(process.pid);
process.exit();
}
if (options.exit) {
process.exit();
} else if (options.pid) {
process.kill(process.pid);
}
} catch (err) {
console.log(err);
}
}
//catches ctrl+c and stop.sh events
process.on('SIGINT', exitHandler.bind(null, {exit: true}));
//catches "kill pid" (for example: nodemon restart)
process.on('SIGUSR1', exitHandler.bind(null, {pid: true}));
process.on('SIGUSR2', exitHandler.bind(null, {pid: true}));
//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {
exit: true,
reason: 'uncaughtException'
}));
main();
async function main()
{
// Create the messages directory, needed as the default version
mesgdir = __dirname + "/messages";
if (!fs.existsSync(mesgdir)) {
fs.mkdirSync(mesgdir);
}
// Create the attachments directory, needed as the default version
attachdir = __dirname + "/attachments";
if (!fs.existsSync(attachdir)) {
fs.mkdirSync(attachdir);
}
const tokenConfig = [
{
token: 'USE_STREAMING',
pattern: 'yes|no',
type: 'string',
description: 'Use new file save process [yes/no]',
message: 'Please enter either yes or no',
required: true,
default: 'no',
list: [
{
token: 'STREAM_DESTINATION',
pattern: '',
type: 'file',
description: 'Please specify the directory to save message data',
message: 'Cannot find directory!',
required: true,
default: mesgdir,
},
{
token: 'STREAM_BASENAME',
pattern: '',
type: 'string',
description: "Please add a prefix for message data files",
message: 'Cannot leave empty! Please enter a value',
required: true,
default: 'receivedMessages',
},
{
token: 'STREAM_MAXSIZE',
pattern: '^([1-9][0-9]{4,9}|10000000000)$',
type: 'number',
description: "Please enter the maximum size in bytes for each messages file [1GB = 1073741824]",
message: 'Please enter a valid number between 10000 and 10000000000',
required: false,
default: '1073741824',
},
{
token: 'STREAM_ATTACHLOC',
pattern: '',
type: 'file',
description: "Please specify the directory to save attachment data",
message: 'Cannot find directory!',
required: true,
default: attachdir,
}
]
},
{
token: 'RUNTIME_DURATION',
pattern: '^([1-9][0-9]{1,2}|[1-4][0-9]{1,3}|[1-5]000)$',
type: 'string',
description: "Memory can reach 100% if the bot isn't restarted periodically. Please enter a time in minutes to restart the service [24hrs = 1440]",
message: 'Please enter a valid number',
required: true,
default: '1440'
}
];
var fullName = process.cwd() + "/processes.json";
wickrIOConfigure = new WickrIOBotAPI.WickrIOConfigure(tokenConfig, fullName, false, false);
await wickrIOConfigure.configureYourBot("WickrIO-Compliance-Bot");
process.exit();
}