This repository has been archived by the owner on Nov 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
104 lines (85 loc) · 2.13 KB
/
index.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
#!/usr/bin/env node
const program = require('commander')
const theFunction = require("./function")
const MyClient = require("./MyClient");
const admin = require("./serverAdministrator")
program
.version('1.0.0')
.option('-f --file [value]', 'attach file to the message (use with -p or -s)')
.option('--login', 'set the account to use')
program
.command('list')
.description('List all server and chan')
.option('-s, --server', "to search only in this server (case insensitive)")
.action((options) => {
theFunction.getList(options.server)
});
program
.command('send <channels> <message>')
.description('send message to multiple channels')
.action((channels, message, options) => {
theFunction.msgToManyChan(message, channels, program.file)
}).on('--help', () => {
console.log(' Examples:');
console.log();
console.log(' $ send \"servername chan1 chan2, servername2 chan1 chan2\" "Hello world"');
console.log();
});
program
.command('message')
.description('send messages to channels or user')
.action((options) => {
theFunction.sendMessage(program.file)
});
program
.command('admin')
.description('admin administrator server')
.action((options) => {
admin.administate();
});
program
.command('set-token <token>')
.description('set the token account to use')
.option('-c, --no-check', "disable token check")
.action(async (token, options) => {
if (await MyClient.setToken(token, options.check)) {
console.log("Token setted !");
}
else {
console.log('Bad token !');
};
process.exit();
});
program
.command('*')
.action((options) => {
program.help();
});
checkNoArgs();
program
.parseOptions(process.argv);
startOptions();
async function startOptions() {
//if a --login option, do the login action fist
if (program.login) {
if (await MyClient.login()) {
console.log('You are logged');
if (process.argv.length <= 3) {
process.exit();
}
}
else {
console.log('Login failed');
process.exit();
}
}
program.parse(process.argv);
}
function checkNoArgs(){
let index = 1;
if(process.argv0 == 'node'){
index++;
}
if(process.argv[index] == undefined)
program.help();
}