-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
675 lines (642 loc) · 29.5 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
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
"use strict";
//define important bot things
const { Intents } = require("discord.js");
const Commando = require("discord.js-commando");
const path = require("path");
const fs = require("fs");
const chalk = require("chalk");
const keepAlive = require('./modules/service/server.js');
const intents = new Intents([Intents.NON_PRIVILEGED, "GUILD_MEMBERS"]);
//create the bot boi
const client = new Commando.CommandoClient({
commandPrefix: `${require("./config.json").prefix}`,
owner: `${require("./config.json").ownerid}`,
partials: ["MESSAGE", "CHANNEL", "REACTION"],
ws: { intents },
});
///////////////
keepAlive();
//////////////
try {
require("./config.json");
} catch (e) {
return require(path.join(__dirname, "functions/console.js")).error("CONFIG", "There seems to be an error with your configuration file. This is most likely a simple JSON syntax error. Please see the docs for details.\nDetailed error: " + e);
}
//hey look its a config file poggers
client.config = require("./config.json");
//this must match what is in the config.json
const CONFIG_VERSION = 1;
/*
==========================================================================================
_____ ____ __ __ __ __ _ _ _____ _____
/ ____/ __ \| \/ | \/ | /\ | \ | | __ \ / ____|
| | | | | | \ / | \ / | / \ | \| | | | | (___
| | | | | | |\/| | |\/| | / /\ \ | . ` | | | |\___ \
| |___| |__| | | | | | | |/ ____ \| |\ | |__| |____) |
\_____\____/|_| |_|_| |_/_/ \_\_| \_|_____/|_____/
==========================================================================================
*/
client.registry
.registerDefaultTypes()
.registerGroups([
["utility", "Utility"],
["mods", "Mods"],
["admins", "Admins"],
["settings", "Settings"],
])
.registerDefaultGroups()
.registerDefaultCommands({
unknownCommand: false,
prefix: false,
})
.registerCommandsIn(path.join(__dirname, "commands"));
/*
==========================================================================================
_____ ______ _____ __ __ _____ _____ _____ _____ ____ _ _ _____
| __ \| ____| __ \| \/ |_ _|/ ____/ ____|_ _/ __ \| \ | |/ ____|
| |__) | |__ | |__) | \ / | | | | (___| (___ | || | | | \| | (___
| ___/| __| | _ /| |\/| | | | \___ \\___ \ | || | | | . ` |\___ \
| | | |____| | \ \| | | |_| |_ ____) |___) |_| || |__| | |\ |____) |
|_| |______|_| \_\_| |_|_____|_____/_____/|_____\____/|_| \_|_____/
==========================================================================================
*/
client.dispatcher.addInhibitor((msg) => {
if (msg.channel.type == "dm") return false;
let admin = msg.guild.roles.cache.find((r) => r.id == client.config.role.admin || r.name == client.config.role.admin);
let mod = msg.guild.roles.cache.find((a) => a.id == client.config.role.admin || a.name == client.config.role.mod);
switch (msg.command.group.name) {
case "Admins":
if (msg.member.roles.cache.has(admin.id) || client.config.ownerid == msg.member.user.id) {
return false;
} else {
client.error("Invalid permissions, you must be an Admin!", msg);
return "Invalid permissions";
}
break;
case "Mods":
if (msg.member.roles.cache.has(mod.id) || msg.member.roles.cache.has(admin.id) || client.config.ownerid == msg.member.user.id) {
return false;
} else {
client.error("Invalid permissions, you must be a Mod!", msg);
return "Invalid permissions";
}
break;
case "Settings":
if (msg.member.roles.cache.has(admin.id) || client.config.ownerid == msg.member.user.id) {
return false;
} else {
client.error("Invalid permissions, you must be an Admin!", msg);
return "Invalid permissions";
}
break;
default:
return false;
}
});
client.dispatcher.addInhibitor((msg) => {
if (!msg.channel.parent) return;
if (msg.channel.parent.name == client.config.modmail.category) {
msg.channel.send({ embed: { description: "Modmail Bot commands do not work very well in ModMail ticket channels! Please use another channel for smoother operation! (Users do not see bot output)", color: 13632027 } }).then((m) => m.delete({ timeout: 10000 }));
}
});
/*
=============================================================================================================
_ _ ______ _ _____ ______ _____ ______ _ _ _ _ _____ _______ _____ ____ _ _ _____
| | | | ____| | | __ \| ____| __ \ | ____| | | | \ | |/ ____|__ __|_ _/ __ \| \ | |/ ____|
| |__| | |__ | | | |__) | |__ | |__) | | |__ | | | | \| | | | | | || | | | \| | (___
| __ | __| | | | ___/| __| | _ / | __| | | | | . ` | | | | | || | | | . ` |\___ \
| | | | |____| |____| | | |____| | \ \ | | | |__| | |\ | |____ | | _| || |__| | |\ |____) |
|_| |_|______|______|_| |______|_| \_\ |_| \____/|_| \_|\_____| |_| |_____\____/|_| \_|_____/
============================================================================================================
*/
function sendMessage(client, channel, content) {
client.guilds.cache.map((g) => {
try {
g.channels.cache.find((ch) => ch.id == channel || ch.name == channel).send(content);
} catch (e) {
return;
}
});
}
client.once("ready", () => {
console.log("[READY] FOR DUTY")
setInterval(() => {
const statuses = [
`DM to Contact Staff!`,
`#${client.guilds.cache.size} Tagpuan PH`,
]
const status = statuses[Math.floor(Math.random() * statuses.length)]
client.user.setActivity(status, { type: "WATCHING", url: "https://www.twitch.tv/nocopyrightsounds"}) // Can Be WATCHING, STREAMING, LISTENING
}, 30000) // Second You Want to Change Status, This Cahnges Every 2 Seconds
/*
==========================================================================================
_____ _____ ______ _____ _____ __ __ _____ _____
/\ / ____/ ____| ____|/ ____/ ____| \ \ / /\ | __ \ / ____|
/ \ | | | | | |__ | (___| (___ \ \ / / \ | |__) | (___
/ /\ \| | | | | __| \___ \\___ \ \ \/ / /\ \ | _ / \___ \
/ ____ \ |___| |____| |____ ____) |___) | \ / ____ \| | \ \ ____) |
/_/ \_\_____\_____|______|_____/_____/ \/_/ \_\_| \_\_____/
==========================================================================================
*/
client.rolePerm = require("./functions/roleperm.js");
client.error = require("./functions/error.js");
client.log = require("./functions/log.js");
client.cn = require("./functions/console.js");
/*
==========================================================================================
_ ____ ____ _____ _____
| | / __ \ / __ \| __ \ / ____|
| | | | | | | | | |__) | (___
| | | | | | | | | ___/ \___ \
| |___| |__| | |__| | | ____) |
|______\____/ \____/|_| |_____/
==========================================================================================
*/
fs.readdir(path.join(__dirname, "modules/loop"), (err, files) => {
client.cn.log("Loop", `Found ${chalk.underline(Object.keys(client.config.loops).length)} loops`);
if (err) return console.error(err);
files.forEach((file) => {
if (!file.includes("js")) return;
let eventFunction = require(path.join(__dirname, `modules/loop/${file}`));
let eventName = file.split(".")[0];
if (client.config.loops[eventName]) {
eventFunction.run(client);
setInterval(() => {
eventFunction.run(client);
}, eventFunction.time);
client.cn.log("Loop", `Started ${chalk.underline(eventName)} loop`);
} else {
// client.cn.log("Loop", `Stopped ${chalk.underline(eventName)}`);
}
});
});
/*
==========================================================================================
_____ ______ _______ _______ _____ ______ _____
/ ____| ____| __ \ \ / /_ _/ ____| ____|/ ____|
| (___ | |__ | |__) \ \ / / | || | | |__ | (___
\___ \| __| | _ / \ \/ / | || | | __| \___ \
____) | |____| | \ \ \ / _| || |____| |____ ____) |
|_____/|______|_| \_\ \/ |_____\_____|______|_____/
==========================================================================================
*/
fs.readdir(path.join(__dirname, "modules/service"), (err, files) => {
client.cn.log("Services", `Found ${chalk.underline(Object.keys(client.config.services).length)} services`);
if (err) return console.log(err);
files.forEach((file) => {
if (!file.includes("js")) return;
let eventFunction = require(path.join(__dirname, `modules/service/${file}`));
let eventName = file.split(".")[0];
if (client.config.services[eventName]) {
eventFunction.run(client, sendMessage);
client.cn.log("Service", `Started ${chalk.underline(eventName)} service`);
} else {
// client.cn.log("Service", `Disabled ${chalk.underline(eventName)}`);
}
});
});
/*
==========================================================================================
_____ _ _ ______ _____ _ ________ _____
/ ____| | | | ____/ ____| |/ / ____| __ \
| | | |__| | |__ | | | ' /| |__ | |__) |
| | | __ | __|| | | < | __| | _ /
| |____| | | | |___| |____| . \| |____| | \ \
\_____|_| |_|______\_____|_|\_\______|_| \_\
==========================================================================================
*/
if (client.config.version != CONFIG_VERSION) {
throw new Error(chalk.red.bold(`Incompatible config file version ${client.config.version} for this bot version ${require("./package.json").version}. Must use config version ${CONFIG_VERSION}`));
}
// Role and Channel Checker
client.guilds.cache.map((guild) => {
const cn = require("./functions/console.js");
//Role checker
Object.keys(client.config.role).forEach(function (role) {
if (client.config.role[role] == "") return cn.error("Warn (Roles Config)", `Permission role for ${role} is not defined in the config!`);
if (guild.roles.cache.find((r) => r.id == client.config.role[role] || r.name == client.config.role[role]) == undefined) {
cn.error("Warn (Roles Config)", `Permission role for ${role} defined as ${client.config.role[role]} was not found in guild: ${guild.name}`);
}
});
//Channel Checker
Object.keys(client.config.channel).forEach(function (channel) {
if (client.config.channel[channel] == "") return cn.error("Warn (Channels Config)", `Channel for ${channel} is not defined in the config!`);
if (guild.channels.cache.find((ch) => ch.id == client.config.channel[channel] || ch.name == client.config.channel[channel]) == undefined) {
cn.error("Warn (Channels Config)", `Channel for ${channel} defined as ${client.config.channel[channel]} was not found in guild: ${guild.name}`);
}
});
});
});
fs.access("./logs", (err) => {
const cn = require("./functions/console.js");
if (!err) {
cn.log("Logs", "Your logs folder is ready");
} else {
fs.mkdir("./logs", function (err) {
if (err) return client.cn.log("Logs", err);
cn.log("Logs", "Your logs folder is now ready");
});
}
});
/*
==========================================================================================
______ _____ _____ ____ _____ _____
| ____| __ \| __ \ / __ \| __ \ / ____|
| |__ | |__) | |__) | | | | |__) | (___
| __| | _ /| _ /| | | | _ / \___ \
| |____| | \ \| | \ \| |__| | | \ \ ____) |
|______|_| \_\_| \_\\____/|_| \_\_____/
==========================================================================================
*/
client.on("error", (error) => {
if (error == "TypeError: Cannot read property 'group' of null") return;
return client.cn.error("Client", error);
});
/*
==========================================================================================
__ __ ____ _____ __ __ _____ _
| \/ |/ __ \| __ \| \/ | /\ |_ _| |
| \ / | | | | | | | \ / | / \ | | | |
| |\/| | | | | | | | |\/| | / /\ \ | | | |
| | | | |__| | |__| | | | |/ ____ \ _| |_| |____
|_| |_|\____/|_____/|_| |_/_/ \_\_____|______|
==========================================================================================
*/
const guild = client.guilds.cache.get(client.config.modmail.guild);
function logMail(user, message) {
let LOG_TEMPLATE = `[${new Date()}] [${message.author.username}] ${message.content} ${message.attachments.first() ? message.attachments.first().url : ""}\n`;
if (message.content.startsWith(`${client.config.prefix}snippet`)) LOG_TEMPLATE = `[${new Date()}] [${message.author.username}] Snippet (#${message.content.split(" ")[1]}): ${client.config.snippets[parseInt(message.content.split(" ")[1])]}\n`;
fs.appendFileSync(`./logs/${user.id}.txt`, LOG_TEMPLATE);
}
function msg(destination, g, message, embed) {
switch (destination) {
case "guild":
g.channels.cache
.find((ch) => ch.name == `${message.author.tag.replace("#", "-").toLowerCase()}`)
.send({ embed })
.then(() => message.react(" <a:tcheck2:843702834251038740>"))
.catch((error) => message.react("<a:twrong1:843702835580895242>"));
break;
case "dm":
user.send({ embed });
break;
}
}
// check if guild modmail category exists
function hasCategory(g) {
if (g.channels.cache.find((ch) => ch.id == client.config.modmail.category || ch.name == client.config.modmail.category)) {
return true;
} else {
return false;
}
}
//makes a ticket channel, sends the confirmation that a ticket was created and starts the logger
function makeTicket(g, message, embed) {
let category = g.channels.cache.find((ch) => ch.id == client.config.modmail.category || ch.name == client.config.modmail.category);
g.channels.create(message.author.tag.replace("#", "-"), { reason: "New ModMail ticket", topic: `[${message.author.id}] ${client.config.messages.ticketDesc.replace("[p]", client.config.prefix)}`, parent: category }).then((ch) => ch.send({ embed }));
logMail(message.author, message);
message.author
.send({ embed: { description: client.config.messages.newTicket } })
.then(() => message.react(" <a:tcheck2:843702834251038740>"))
.catch((error) => message.react("<a:twrong1:843702835580895242>"));
// client.log("New Ticket", `Initial content: \`\`\`${message.content}\`\`\``, 4784242, message);
g.channels.cache
.find((ch) => ch.name == client.config.channel.log || ch.id == client.config.channel.log)
.send({
embed: {
description: `Initial Content: \`\`\`${message.content}\`\`\``,
color: 4784242,
timestamp: Date.now(),
footer: {
icon_url: `${client.user.avatarURL()}`,
text: `${client.user.username} - Logs`,
},
author: {
name: "New Ticket",
icon_url: "https://samstep.net/bots/assets/log.png",
},
fields: [
{
name: "Runned by⤵️",
value: `${message.author}`,
},
],
},
});
}
//checks if a ticket is already open
function hasTicket(g, message) {
let ticket = g.channels.cache.find((ch) => ch.name == message.author.tag.replace("#", "-").toLowerCase());
if (ticket) {
return true;
} else {
return false;
}
}
function modmailCommands() {
const commands = [
{ cmd: "close", desc: "Close a ticket channel" },
{ cmd: "cmds", desc: "This command! Shows you useful things :)" },
{ cmd: "snippet", desc: "Open the snippet menu and choose a snippet to send" },
{ cmd: "block", desc: "Block this user" },
{ cmd: "lock", desc: "Disable all modmail messages" },
];
let str = "```\n";
for (let i in commands) {
str += `${client.config.prefix}${commands[i].cmd} - ${commands[i].desc}\n`;
}
return str + "\n```";
}
async function configArrayPush(property, value) {
let data = client.config;
await data.modmail[property].push(value);
fs.writeFile("./config.json", JSON.stringify(data, null, 3), (err) => {
if (err) return client.cn.error("Config", err);
client.cn.log("Config", `The config file has been saved! Added to property ${property} new value ${value}`);
});
client.config = await require("./config.json");
}
async function configArrayRemove(property, value) {
let data = client.config;
data.modmail[property] = await data.modmail[property].filter(function (val, index, arr) {
return val !== value;
});
fs.writeFile("./config.json", JSON.stringify(data, null, 3), (err) => {
if (err) return client.cn.error("Config", err);
client.cn.log("Config", `The config file has been saved! Removed in property ${property} removed value ${value}`);
});
client.config = await require("./config.json");
}
async function updateConfigProp(property, value) {
let data = client.config;
data.modmail[property] = value;
fs.writeFile("./config.json", JSON.stringify(data, null, 3), (err) => {
if (err) return client.cn.error("Config", err);
client.cn.log("Config", `The config file has been saved! Updated property ${property} to value ${value}`);
});
client.config = await require("./config.json");
}
function getSnippets() {
let d = "";
client.config.snippets.forEach((snip) => {
if (snip.length > 20) {
d += `[${client.config.snippets.indexOf(snip)}] ` + snip.substring(0, 20).concat(" (cont.)\n");
} else {
d += `[${client.config.snippets.indexOf(snip)}] ${snip}` + "\n";
}
});
if (client.config.snippets.length == 0) d = `No snippets loaded! Make some with ${client.config.prefix}snippets create <Text to add>.`;
return `\`\`\`\n${d}\`\`\``;
}
let reason = "";
client.on("message", async (message) => {
//guild active in (one guild only right now)
const guild = client.guilds.cache.get(client.config.modmail.guild);
// template message sender return
let embed = {
author: {
name: client.user.username,
icon_url: message.author.displayAvatarURL(),
},
description: message.content,
color: client.config.modmail.color,
image: {},
timestamp: {}
};
if (message.attachments.first()) embed.image.url = message.attachments.first().url;
//detect dm channel
if (message.channel.type == "dm" && !message.author.bot) {
//checks if the user is blocked
if (client.config.modmail.blockedUsers.some((usr) => message.author.id == usr)) {
return message.author.send({ embed: { description: client.config.messages.blockedUserError, color: client.config.modmail.color } });
} else if (!client.config.modmail.enabled) {
return message.author.send({ embed: { description: client.config.messages.enabled, color: client.config.modmail.color } });
}
if (message.content.startsWith(client.config.prefix)) {
return;
}
if (hasCategory(guild)) {
//check for modmail category
//if modmail category, check for open ticket
if (hasTicket(guild, message)) {
//if ticket, send messages and write to logger
msg("guild", guild, message, embed);
logMail(message.author, message);
} else {
//if no ticket, make one
makeTicket(guild, message, embed);
}
} else {
//if no modmail category create one and then create the ticket and send a confirmation message
let perms = [
{ id: guild.roles.cache.find((r) => r.name == client.config.role.mod || r.id == client.config.role.mod).id, allow: ["VIEW_CHANNEL"] },
{ id: guild.roles.cache.find((r) => r.name == client.config.role.admin || r.id == client.config.role.admin).id, allow: ["VIEW_CHANNEL"] },
{ id: guild.roles.cache.find((r) => r.name == client.config.role.mod || r.id == client.config.role.member).id, deny: ["VIEW_CHANNEL"] },
{ id: guild.id, deny: ["VIEW_CHANNEL"] },
];
if (client.config.modmail.rolesAllowed.length > 0) {
client.config.modmail.rolesAllowed.forEach((role) => {
perms.push({ id: guild.roles.cache.find((r) => r.name == role || r.id == role).id, allow: ["VIEW_CHANNEL"] });
});
}
guild.channels
.create(client.config.modmail.category, {
type: "category",
reason: "ModMail category needed",
permissionOverwrites: perms,
})
.then((cat) => {
guild.channels
.create(message.author.tag.replace("#", "-"), { reason: "New ModMail ticket", topic: `[${message.author.id}] ${client.config.messages.ticketDesc.replace("[p]", client.config.prefix)}`, parent: cat })
.then((ch) => {
ch.send({ embed }).then(() => message.react(" <a:tcheck2:843702834251038740>"));
logMail(message.author, message);
message.author.send({ embed: { description: client.config.messages.newTicket } });
})
.catch((error) => message.react("<a:twrong1:843702835580895242>"));
});
// client.log("New Ticket", `Initial content: \`\`\`${message.content}\`\`\``, 12189830, message);
guild.channels.cache
.find((ch) => ch.name == client.config.channel.log || ch.id == client.config.channel.log)
dm .send({
embed: {
description: `Initial Content: \`\`\`${message.content}\`\`\``,
color: 4784242,
timestamp: Date.now(),
footer: {
icon_url: `${client.user.avatarURL()}`,
text: `${client.user.username} - Logs`,
},
author: {
name: "New Ticket",
icon_url: "https://samstep.net/bots/assets/log.png",
},
fields: [
{
name: "Ran By",
value: `${message.author}`,
},
],
},
});
// client.log("Category Remade", `Recreated ModMail tickets category as I could not find it.`, 4784242, message);
guild.channels.cache
.find((ch) => ch.name == client.config.channel.log || ch.id == client.config.channel.log)
.send({
embed: {
description: `Recreated ModMail tickets category as I could not find it.`,
color: 4784242,
timestamp: Date.now(),
footer: {
icon_url: `${client.user.avatarURL()}`,
text: `${client.user.username} - Logs`,
},
author: {
name: "Category Remade",
icon_url: "https://samstep.net/bots/assets/log.png",
},
fields: [
{
name: "Ran By",
value: `${message.author}`,
},
],
},
});
}
}
//TICKET COMMANDS CONTROLLER
if (message.channel.parentID == guild.channels.cache.find((ch) => ch.name == client.config.modmail.category || ch.id == client.config.modmail.category) && !message.author.bot && message.content.startsWith(client.config.prefix)) {
guild.members.fetch();
let user = guild.members.cache.find((m) => m.id == message.channel.topic.substring(1, message.channel.topic.indexOf("]")));
switch (message.content.split(" ")[0].slice(1).toLowerCase()) {
case "close":
reason = message.content.split(" ").slice(1).join(" ") || null;
message.channel.delete();
break;
case "snippet":
let arg = message.content.split(" ")[1];
if (arg == undefined) {
return message.channel.send(`Use a valid snippet number. \`Ex: ${client.config.prefix}snippet [#]\`\n` + getSnippets());
} else if (!client.config.snippets[parseInt(arg)]) {
message.react("<a:twrong1:843702835580895242>");
return message.delete({ timeout: 3000 });
} else {
user.send({ embed: { author: { name: message.author.username, icon_url: message.author.displayAvatarURL() }, color: client.config.modmail.color, description: client.config.snippets[parseInt(arg)] } }).catch((e) => {
return client.error("Unable to send snippet to this user.", message);
});
logMail(user, message);
message.delete();
message.channel
.send({
embed: { description: `Snippet Sent (#${arg}): \`\`\`${client.config.snippets[parseInt(arg)]}\`\`\``, color: client.config.modmail.color, author: { name: message.author.username, icon_url: message.author.displayAvatarURL() } },
})
.then((msg) => msg.react(" <a:tcheck2:843702834251038740>"));
}
break;
case "block":
if (client.config.modmail.blockedUsers.some((usr) => usr == user.id)) {
configArrayRemove("blockedUsers", user.id);
message.channel.send(`${user} successfully unblocked.`);
client.log("User Unblocked", `${user.user.username}#${user.user.discriminator} (ID: \`${user.id}\`) has been unblocked`, 82938, message);
} else {
configArrayPush("blockedUsers", user.id);
message.channel.send(`${user} successfully blocked.`);
client.log("User Blocked", `${user.user.username}#${user.user.discriminator} (ID: \`${user.id}\`) has been blocked`, 82938, message);
}
break;
case "lock":
if (client.config.modmail.enabled) {
updateConfigProp("enabled", false);
message.channel.send("ModMail has been locked");
client.user.setStatus("dnd");
client.log("ModMail Locked", `ModMail has been locked by a user in #${message.channel.name}`, 5112002, message);
} else {
updateConfigProp("enabled", true);
message.channel.send("ModMail has been unlocked");
client.user.setStatus("online");
client.log("ModMail Unlocked", `ModMail has been unlocked by a user in #${message.channel.name}`, 5112002, message);
}
break;
case "cmds":
message.channel.send(modmailCommands());
break;
default:
message.react("<a:twrong1:843702835580895242>");
message.delete({ timeout: 3000 });
break;
}
return;
}
//GUILD TO DM controller
if (!message.author.bot && message.channel.parentID == guild.channels.cache.find((ch) => ch.name == client.config.modmail.category || ch.id == client.config.modmail.category) && message.channel.type != "dm") {
// let user = guild.members.cache.find((m) => m.user.tag.replace("#", "-").toLowerCase() == message.channel.name);
let user = guild.members.cache.find((m) => m.id == message.channel.topic.substring(1, message.channel.topic.indexOf("]")));
if (!user) return;
user
.send({ embed })
.then(() => message.react("<a:tcheck2:843702834251038740>"))
.catch((error) => message.react("<a:twrong1:843702835580895242>"));
logMail(user, message);
}
});
//ticket closing functions
client.on("channelDelete", async (channel) => {
const guild = client.guilds.cache.get(client.config.modmail.guild);
// let user = guild.members.cache.find((m) => m.user.tag.replace("#", "-").toLowerCase() == channel.name);
if (channel.type != "text" || !channel.topic || channel.topic[0] != "[") return;
guild.members.fetch();
let user = guild.members.cache.find((m) => m.id == channel.topic.substring(1, channel.topic.indexOf("]")));
if (!user) return;
await guild.channels.cache
.find((ch) => ch.name == client.config.channel.log || ch.id == client.config.channel.log)
.send({
embed: {
author: { name: "Ticked Closed", icon_url: "https://samstep.net/bots/assets/log.png" },
description: `Ticket \`${channel.name}\` deleted by a staff member. If there are any logs find them below. ${reason ? "```Reason:" + reason + "```" : ""}`,
color: 4784242,
},
});
await guild.channels.cache.find((ch) => ch.name == client.config.channel.log || ch.id == client.config.channel.log).send("", { files: [`./logs/${user.id}.txt`] });
await fs.unlink(`./logs/${user.id}.txt`, (err) => {
if (err) return client.cn.error("Config", err);
});
//if channel is modmail ticket
if (!channel.parent) return;
if (channel.parent.name == client.config.modmail.category || channel.parent.id == client.config.modmail.category) {
user.send({ embed: { description: client.config.messages.closedTicket } });
}
try {
} catch (e) {
console.error(e);
}
});
/*
==========================================================================================
_ ____ _____ _____ _ _
| | / __ \ / ____|_ _| \ | |
| | | | | | | __ | | | \| |
| | | | | | | |_ | | | | . ` |
| |___| |__| | |__| |_| |_| |\ |
|______\____/ \_____|_____|_| \_|
==========================================================================================
*/
try {
client
.login(client.config.token)
.then(
function () {
let cn = require("./functions/console.js");
cn.log("Startup", `Logged in as ${client.user.username}#${client.user.discriminator}`);
cn.log("Tagpuan PH", `https://discord.gg/tagpuanph`);
cn.log(`Guilds`, `| Connected to ${client.guilds.cache.size} guild${client.guilds.cache.size > 1 ? "s " : " "}`);
if (client.guilds.cache.size > 1) cn.error("Warn", "Keep in mind that this bot is not optimized for multiple servers so use caution!");
},
function (err) {
require(path.join(__dirname, "functions/console.js")).error("Login", err);
}
)
.catch((err) => console.error(err));
} catch (e) {
console.error(e);
}