This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.js
79 lines (69 loc) · 1.89 KB
/
manage.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
const Discord = require('discord.js');
const {
prefix,
token
} = require('./config.json');
var args = process.argv.slice(2);
if (args.length <= 0) {
console.log("U need some args dude");
usage();
process.exit();
}
const warnMsg = "> :warning: MogusBot is in maintenance, the bot may fail during next few hours :warning:";
const readyMsg = "> :white_check_mark: MogusBot is up again normally";
const client = new Discord.Client();
client.once('ready', () => {
console.log('A punt!');
let proves = false;
switch(args[0]){
case "manteniment":
sendWarning(warnMsg);
break;
case "up":
sendWarning(readyMsg);
break;
case "proves":
proves = true;
break;
default:
console.log("Command not accepted");
usage();
};
if (!proves) {
client.destroy();
process.exit();
}
});
client.once('reconnecting', () => {
console.log('Reconnectant!');
});
client.once('disconnect', () => {
console.log('Desconnectat!');
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.channel.send(warnMsg);
}
});
function sendWarning(msg) {
var guilds = client.guilds.cache;
guilds.each(guild => {
try {
console.log(guild.name);
//console.log(guild.systemChannel.name);
if (msg.length > 0) guild.systemChannel.send(msg);
//var channels = guild.channels.cache;
//channels.each(channel => console.log(channel.name));
console.log("--------");
}
catch(e) {
console.log("No s'ha pogut enviar missatge a " + guild.name);
}
});
return;
}
function usage() {
console.log("Usage:");
console.log("nodejs manage.js {manteniment | up | proves}");
}
client.login(token);