forked from DraftBot-A-Discord-Adventure/DraftBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
105 lines (92 loc) · 2.97 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
103
104
105
require('colors');
require('core/Constant');
require('core/MessageError');
require('core/Tools');
const Draftbot = require('core/DraftBot');
(async (Drafbot) => {
await Drafbot.init();
/**
* Will be executed whenever the bot has started
* @return {Promise<void>}
*/
const onDiscordReady = async () => {
(require('figlet'))(JsonReader.bot.reboot, (err, data) => {
console.log(data.red);
console.log(JsonReader.bot.br.grey);
});
await client.guilds.cache.get(JsonReader.app.MAIN_SERVER_ID)
.channels
.cache
.get(JsonReader.app.CONSOLE_CHANNEL_ID)
.send(JsonReader.bot.startStatus + JsonReader.package.version)
.catch(console.error);
await client.user
.setActivity(JsonReader.bot.activity)
.catch(console.error);
await require('core/DBL').verifyDBLRoles();
};
/**
* Will be executed each time the bot join a new server
*/
const onDiscordGuildCreate = async (guild) => {
let [serv] = await Servers.getOrRegister(JsonReader.app.MAIN_SERVER_ID);
let msg = getJoinLeaveMessage(guild, true, serv.language);
(await client.channels.fetch(JsonReader.app.CONSOLE_CHANNEL_ID)).send(msg);
// if (validation == ":x:") {
// sendLeavingMessage(guilde);
// //guilde.leave() //temporairement désactivé pour top.gg
// }
console.log(msg);
};
/**
* Will be executed each time the bot leave a server
*/
const onDiscordGuildDelete = async (guild) => {
let [serv] = await Servers.getOrRegister(JsonReader.app.MAIN_SERVER_ID);
let msg = getJoinLeaveMessage(guild, false, serv.language);
(await client.channels.fetch(JsonReader.app.CONSOLE_CHANNEL_ID)).send(msg);
console.log(msg);
};
/**
* Get the message when the bot joins or leaves a guild
* @param {module:"discord.js".Guild} guild
* @param {boolean} join
* @param {"fr"|"en"} language
* @return {string}
*/
const getJoinLeaveMessage = (guild, join, language) => {
let {validation, humans, bots, ratio} = getValidationInfos(guild);
return format(join ? JsonReader.bot.getTranslation(language).joinGuild : JsonReader.bot.getTranslation(language).leaveGuild, {
guild: guild,
humans: humans,
robots: bots,
ratio: ratio,
validation: validation
});
};
/**
* Will be executed each time the bot see a message
* @param {module:"discord.js".Message} message
* @return {Promise<void>}
*/
const onDiscordMessage = async (message) => {
if (message.author.bot) return;
if (message.channel.type === 'dm') {
await handlePrivateMessage(message);
} else {
await handleMessage(message);
}
};
client.on('ready', onDiscordReady);
client.on('guildCreate', onDiscordGuildCreate);
client.on('guildDelete', onDiscordGuildDelete);
client.on('message', onDiscordMessage);
await client.login(JsonReader.app.DISCORD_CLIENT_TOKEN);
})(Draftbot);
// /**
// * Send a message to the owner of the guild the bot is leaving
// * @param {*} guilde - The guild the bot is leaving
// */
// function sendLeavingMessage(guilde) {
// guilde.owner.send(Console.departurMessage);
// }