-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
138 lines (114 loc) · 3.91 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
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
const Discord = require('discord.js');
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMessageReactions,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.DirectMessages,
Discord.GatewayIntentBits.DirectMessageReactions,
Discord.GatewayIntentBits.DirectMessageTyping,
],
partials: [Discord.Partials.Channel],
});
const config = require('./config.json');
const util = require('./modules/util.js');
util.init(client);
const help = require('./modules/help.js');
const purge = require('./modules/purge.js');
const serverlist = require('./modules/serverlist.js');
const ingame = require('./modules/ingame.js');
const roles = require('./modules/roles.js');
const find = require('./modules/find.js');
const mention = require('./modules/mention.js');
const advertise = require('./modules/advertise.js');
let servers;
// client.on("error", console.error);
client.once('ready', () => {
console.log(`Logged in as ${client.user.username} on ${client.guilds.cache.size} ${util.plural(client.guilds.size, 'guild')}`);
getServers();
help.init(client);
serverlist.init(client);
ingame.init(client);
advertise.init(client);
});
client.on('messageCreate', async (message) => {
if (
// wrong guild
(message.guild && message.guild.id !== config.guild) ||
// bot message
message.author.bot ||
// wrong/no prefix
message.content.indexOf(config.prefix) !== 0
) {
return;
}
const args = message.content.slice(config.prefix.length).trim().split(/\s+/g);
const command = args.shift().toLowerCase();
// delete commands not sent in commands channel
if (
// commands channel is specified
config.commands_channel &&
// message sent in wrong channel
util.getChannel(message.channel) !== config.commands_channel
) {
util.deleteMessage(message);
return;
}
if (command === 'ping') {
// delete command
if (config.delete_commands) {
util.deleteMessage(message);
}
// dont auto delete message if moderator sent command
// used for initially creating server list message
return util.sendMessage(message.channel, 'Pong!', !util.isMod(message.author));
}
if (command === 'creator') {
// delete command
if (config.delete_commands) {
util.deleteMessage(message);
}
return util.sendMessage(message.channel, `${client.user.username} was created by epsilon and Mazey`, true);
}
if (['prune', 'purge'].includes(command) && util.isMod(message.author)) {
return purge.onCommand(message, command, args);
}
if (['help', 'commands'].includes(command)) {
return help.onCommand(message, command, args);
}
if (command === 'find') {
return find.onCommand(message, command, args);
}
if (command === 'role') {
return roles.onCommand(message, command, args);
}
if (['advertise', 'invite'].includes(command)) {
return advertise.onCommand(message, command, args);
}
if (['mention', 'tag'].includes(command) && util.isMod(message.author)) {
return mention.onCommand(message, command, args);
}
});
client.on('guildMemberAdd', (member) => {
if (config.welcome_channel) {
util.sendMessage(config.welcome_channel, `Welcome ${member.toString()}! Please read the <#${config.rules_channel}> and check out <#${config.information_channel}>.`);
}
});
client.on('presenceUpdate', () => {
ingame.update(servers);
});
function getServers() {
util.XMLHttpRequest(data => {
servers = util.sortServers(data);
util.updatePresence(servers);
serverlist.update(servers);
ingame.update(servers);
}, 'https://api.kag2d.com/v1/game/thd/kag/servers?filters=[{"field":"current","op":"eq","value":"true"},{"field":"connectable","op":"eq","value":true},{"field":"currentPlayers","op":"gt","value":"0"}]');
// loop every minute
const ms = config.update_interval_secs * 1000;
const delay = ms - new Date() % ms;
setTimeout(getServers, delay);
}
client.login(config.token);