This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.js
409 lines (373 loc) · 13 KB
/
bot.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/**********************************************************
* @INFO [TABLE OF CONTENTS]
* 1 Import_Modules
* 1.1 Validating script for advertisement
* 2 CREATE_THE_DISCORD_BOT_CLIENT
* 3 Load_Discord_Buttons_and_Discord_Menus
* 4 Create_the_client.memer
* 5 create_the_languages_objects
* 6 Raise_the_Max_Listeners
* 7 Define_the_Client_Advertisments
* 8 LOAD_the_BOT_Functions
* 9 Login_to_the_Bot
*
* BOT CODED BY: paninizer as improved from bot by Tomato#6966
*********************************************************/
/**********************************************************
* @param {1} Import_Modules for this FIle
*********************************************************/
const Discord = require("discord.js");
const colors = require("colors");
const Cluster = require("discord-hybrid-sharding");
const fs = require("fs");
const OS = require("os");
const Events = require("events");
const emojis = require("./botconfig/emojis.json")
const config = require("./botconfig/config.json")
const advertisement = require("./botconfig/advertisement.json")
const { delay } = require("./handlers/functions")
/**********************************************************
* @param {2} CREATE_THE_DISCORD_BOT_CLIENT with some default settings
*********************************************************/
const client = new Discord.Client({
fetchAllMembers: false,
restTimeOffset: 0,
failIfNotExists: false,
shards: Cluster.data.SHARD_LIST, // A Array of Shard list, which will get spawned
shardCount: Cluster.data.TOTAL_SHARDS, // The Number of Total Shards
allowedMentions: {
parse: ["roles", "users"],
repliedUser: false,
},
partials: ["MESSAGE", "CHANNEL", "REACTION", "GUILD_MEMBER", "USER", "INTERACTION"],
intents: [ Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
Discord.Intents.FLAGS.GUILD_BANS,
Discord.Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
Discord.Intents.FLAGS.GUILD_INTEGRATIONS,
Discord.Intents.FLAGS.GUILD_WEBHOOKS,
Discord.Intents.FLAGS.GUILD_INVITES,
Discord.Intents.FLAGS.GUILD_VOICE_STATES,
Discord.Intents.FLAGS.GUILD_PRESENCES,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
//Discord.Intents.FLAGS.GUILD_MESSAGE_TYPING,
Discord.Intents.FLAGS.DIRECT_MESSAGES,
Discord.Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
//Discord.Intents.FLAGS.DIRECT_MESSAGE_TYPING
],
presence: {
activities: [{name: `${config.status.text}`.replace("{prefix}", config.prefix), type: config.status.type, url: config.status.url}],
status: "online"
}
});
const discordModals = require('discord-modals') // Define the discord-modals package!
discordModals(client); // discord-modals needs your client in order to interact with modals
/**********************************************************
* @param {4} Create_the_client.memer property from Tomato"s Api
*********************************************************/
const Meme = require("memer-api");
client.memer = new Meme(config.memer_api); // GET a TOKEN HERE: https://discord.gg/Mc2FudJkgP
/**********************************************************
* @param {5} create_the_languages_objects to select via CODE
*********************************************************/
client.la = { }
var langs = fs.readdirSync("./languages")
for (const lang of langs.filter(file => file.endsWith(".json"))){
client.la[`${lang.split(".json").join("")}`] = require(`./languages/${lang}`)
}
Object.freeze(client.la)
//function "handlemsg(txt, options? = {})" is in /handlers/functions
/**********************************************************
* @param {6} Raise_the_Max_Listeners to 0 (default 10)
*********************************************************/
client.setMaxListeners(0);
Events.defaultMaxListeners = 0;
process.env.UV_THREADPOOL_SIZE = OS.cpus().length;
/**********************************************************
* @param {7} Define_the_Client_Advertisments from the Config File
*********************************************************/
client.ad = {
enabled: advertisement.adenabled,
statusad: advertisement.statusad,
spacedot: advertisement.spacedot,
textad: advertisement.textad
}
/**********************************************************
* @param {8} LOAD_the_BOT_Functions
*********************************************************/
//those are must haves, they load the dbs, events and commands and important other stuff
async function requirehandlers(){
// resolve promise
for await (const handler of [
"extraevents",
"clientvariables",
"events",
"erelahandler",
"command",
"loaddb",
"slashCommands"
]) {
try{
await require(`./handlers/${handler}`)(client);
}catch (e){ console.error(e) }
}
//social logs
[
"twitterfeed",
/* "twitterfeed2", */
"livelog",
"youtube",
/* "tiktok" */
].forEach(async handler=>{
try{ await require(`./social_log/${handler}`)(client); }catch (e){ console.error(e) }
});
//handlers
[
"aichat",
"anticaps",
"antidiscord",
"antilinks",
"antimention",
"anti_nuke",
"antiselfbot",
"antispam",
"apply",
"autobackup",
"autoembed",
"automeme",
"blacklist",
"boostlog",
"counter",
"dailyfact",
"epicgamesverification",
"ghost_ping_detector",
"jointocreate", // highers the memory
"joinvc",
"keyword",
"leave",
"logger",
"membercount",
"mute", // highers the memory
"ranking",
"reactionrole",
"roster",
"suggest",
"ticket",
"ticketevent",
"timedmessages",
"validcode",
"welcome",
].forEach(handler => {
try{ require(`./handlers/${handler}`)(client); }catch (e){ console.error(e) }
});
}
requirehandlers();
//tanks
let now = Date.now();
client.tanks = new Discord.Collection();
fs.readdirSync("./tanks_info/").forEach(async (n_dir) => {
fs.readdirSync(`./tanks_info/${n_dir}`).forEach(async (t_dir) => {
const tankTypeFiles = fs.readdirSync(`./tanks_info/${n_dir}/${t_dir}`).filter((file) =>
file.endsWith(".json")
);
for (const file of tankTypeFiles) {
const filename = file.split(".")[0];
const tank = JSON.parse(fs.readFileSync(`./tanks_info/${n_dir}/${t_dir}/${filename}.json`, 'utf-8'));
client.tanks.set(tank.name, tank);
}
})
})
client.tanks.sort((tankA, tankB) => tankA.name-tankB.name);
console.log(`Loaded ${client.tanks.size} tanks after ${Date.now()-now}ms.`.green);
client.guilds.cache.forEach(guild => {
console.log(`${guild.name} | ${guild.id}`);
})
/**********************************************************
* @param {9} Login_to_the_Bot
*********************************************************/
client.cluster = new Cluster.Client(client); //Init the Client & So we can also access broadcastEval...
client.login(config.token);
//start the dashboard
//require("/path/to/dashboard/index.js")(client);
/**********************************************************
* @INFO
* Bot Coded by paninzer |
* @INFO
* Panzer Shipyards Development
* @INFO
* Improved on code by Tomato#6966
* @INFO
*********************************************************/
/**
* NEEDED TO HAVE DMS WORKING (for receiving messages and interaction)
*/
client.cluster.on("message", async (msg) => {
if(!msg._sCustom) return
if(msg.dm && msg.message) {
client.actions.MessageCreate.handle(msg.packet); //handle the raw api data, so that djs can use it
}
if(msg.dm && msg.interaction) {
client.actions.InteractionCreate.handle(msg.packet); //handle the raw api data, so that djs can use it
}
})
client.on("raw", (packet) => {
if (client.cluster.id !== 0) return; // if not on the shard 0, return
if (packet.t === "MESSAGE_CREATE" && !packet.d.guild_id) {
client.cluster.send({
dm: true,
message: true,
packet: packet.d
}); //send the raw api packet data to the cluster, to receive it on the shards!
}
})
client.on("interactionCreate", (interaction) => {
if(client.cluster.id !== 0) return; // if not on the shard 0, return
if(interaction.isSelectMenu() && !interaction.guildId && interaction.user.id != client.user?.id) {
// all of the component types
const Types = {
"PING" : 1,
"APPLICATION_COMMAND": 2,
"MESSAGE_COMPONENT": 3,
"APPLICATION_COMMAND_AUTOCOMPLETE": 4
};
// send the interaction data
client.cluster.send({
dm: true,
interaction: true,
packet: {
version: 1,
type: 3,
token: interaction.token,
member: {
user: {
username: interaction.user.username,
public_flags: interaction.user.flags,
id: interaction.user.id,
discriminator: interaction.user.discriminator,
bot: interaction.user.bot,
avatar: interaction.user.avatar
}
},
message: {
type: 19,
tts: false,
timestamp: interaction.message.timestamp,
pinned: false,
message_reference: {
message_id: interaction.message.id,
guild_id: null,
channel_id: interaction.message.channelId,
},
mentions: [],
mention_roles: [],
mention_everyone: false,
id: interaction.message.id,
flags: 0,
embeds: interaction.message.embeds.map(e => e.toJSON()),
edited_timestamp: null,
content: interaction.message.content,
components: interaction.message.components.map(c => c.toJSON()),
channel_id: interaction.message.channelId,
author: {
username: client.user?.username,
public_flags: client.user?.flags,
id: client.user?.id,
discriminator: client.user?.discriminator,
bot: client.user?.bot,
avatar: client.user?.avatar
},
attachments: interaction.message.attachments
},
user: {
username: interaction.user?.username,
public_flags: interaction.user?.flags,
id: interaction.user?.id,
discriminator: interaction.user?.discriminator,
bot: interaction.user?.bot,
avatar: interaction.user?.avatar
},
locale: interaction.locale,
id: interaction.id,
guild_locale: interaction.guildLocale,
guild_id: interaction.guildId,
data: {
values: interaction.values,
custom_id: interaction.customId,
component_type: Types[interaction.type]
},
channel_id: interaction.channelId,
application_id: interaction.applicationId,
}
});
}
});
// for requesting songs over clusters
client.cluster.on('message', async (message) => {
if(message._sRequest && message.songRequest) {
const { guildId, userId, songRequest } = message;
const guild = client.guilds.cache.get(guildId);
if(!guild) return message.reply({ data: false });
const member = guild.members.cache.get(userId) || await guild.members.fetch(userId).catch(() => null);
if(!member) return message.reply({ data: false })
// if member not in a vc
if(!member?.voice?.channel?.id) return message.reply({ data: false });
var player = client.manager.players.get(guildId);
//if no node, connect it
if (player && player.node && !player.node.connected) await player.node.connect()
//if no player create it
if (!player) {
player = await client.manager.create({
guild: guildId,
voiceChannel: member.voice.channel.id,
textChannel: null,
selfDeafen: true,
});
if (player && player.node && !player.node.connected) await player.node.connect()
}
let state = player.state;
if (state !== "CONNECTED") {
player.set("playerauthor", member.id);
player.connect();
player.stop();
}
res = await client.manager.search(songRequest, member.user);
// Check the load type as this command is not that advanced for basics
let data = null;
if (res.loadType === "LOAD_FAILED") {
throw res.exception;
} else if (res.loadType === "PLAYLIST_LOADED") {
if(res.tracks[0]) data = res.tracks
else data = false;
} else {
if(res.tracks[0]) data = res.tracks[0];
else data = false;
}
if(data) {
//if the player is not connected, then connect and create things
if (player.state !== "CONNECTED") {
//set the variables
player.set("playerauthor", member.id);
player.connect();
//add track
player.queue.add(data);
//play track
player.play();
player.pause(false);
} else if (!player.queue || !player.queue.current) {
//add track
player.queue.add(data);
//play track
player.play();
player.pause(false);
}
//otherwise
else {
//add track
player.queue.add(data);
}
}
message.reply({ data: true })
}
})