-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
882 lines (824 loc) · 30 KB
/
client.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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
import {
Client,
GatewayIntentBits,
Partials,
ApplicationCommandOptionType,
Events,
} from "discord.js";
import { getSettings } from "./services/settingService.js";
import cron from "node-cron";
import {
getUserProfile,
isDifferenceGreaterThanMonths,
matchYoutubeUrl,
} from "./utils/utils.js";
import { findOne, getMembersRankingData } from "./services/memberService.js";
import { getByGameName } from "./interactions/getByGameName.js";
import { closeTicket } from "./interactions/closeTicket.js";
import { getRegister } from "./interactions/getRegister.js";
import { getStatus } from "./interactions/getStatus.js";
import { vote } from "./interactions/vote.js";
import { submitVote } from "./interactions/submitVote.js";
import { setPoints } from "./interactions/setPoints.js";
import { submitRegisterBf2 } from "./modal-submit/submitRegisterBf2.js";
import { submitRegister } from "./modal-submit/submitRegister.js";
import { linkAnotherAccount } from "./interactions/linkAnotherAccount.js";
import { denyLinkAnotherAccount } from "./interactions/denyLinkAnotherAccount.js";
import { registerBf2 } from "./interactions/registerBf2.js";
import { myStatus } from "./interactions/myStatus.js";
import { YES_EMOJI } from "./emojies/emojies.js";
import { hasReachedVotes } from "./utils/hasReachedVotes.js";
import { updateNicks } from "./interactions/updateNicks.js";
import { strikeMember } from "./interactions/strikeMember.js";
import { getMemberStrikes } from "./interactions/getMemberStrikes.js";
import { getAllActiveStrikes } from "./services/strikeService.js";
import { getDogfightRoles } from "./interactions/getDogfightRoles.js";
import { fetchDogfightServersBF2042 } from "./utils/fetchDogfightServersBF2042.js";
import { getRequiredPoints } from "./interactions/getRequiredPoints.js";
import { generateMemberTable } from "./UI/rankingPlate.js";
import { updateMyGameName } from "./interactions/updateMyGameName.js";
import { fetchBfvServers } from "./utils/fetchBfvServers.js";
import { isAccountAlreadyLinked } from "./utils/isAccountAlreadyLinked.js";
import { register } from "./interactions/register.js";
import { subLinkAlt } from "./modal-submit/subLinkAlt.js";
import { muteUser } from "./interactions/mute.js";
import { unmuteUser } from "./interactions/unmute.js";
import { Invite } from "./schemas/invite.js";
export const client = async () => {
const settings = await getSettings();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildInvites,
],
partials: [Partials.User, Partials.Reaction, Partials.Message],
});
client
.login(process.env.DISCORD_TOKEN)
.then(() => console.log("connected the bot"))
.catch((err) => console.log(err));
client.on(Events.ClientReady, async () => {
if (settings.length === 0) return;
console.log(`Logged in as ${client.user.tag}!`);
const guild = client.guilds.cache.get(process.env.GUILD_ID);
let commands;
if (guild) {
commands = guild.commands;
} else {
commands = client?.application.commands;
}
// Fetch invites for the guild and store them in MongoDB
try {
const guildInvites = await guild.invites.fetch();
for await (const invite of guildInvites.values()) {
const existingInvite = await Invite.findOne({
inviteCode: invite?.code,
});
if (existingInvite) {
existingInvite.uses = invite?.uses;
await existingInvite?.save();
} else {
await Invite.create({
inviteCode: invite?.code,
uses: invite?.uses,
inviter: invite?.inviter?.id,
});
}
}
console.log("Guild invites have been cached.");
} catch (error) {
console.error("Error fetching invites:", error);
}
try {
const channelId = "548861917431726091";
const channel = guild.channels.cache.get(channelId);
const invites = await Invite.find();
for await (const invite of invites) {
const message = `${invite.uses} uses by invite code ${invite.code}, created by <@${invite.inviter}>`;
await channel.send(message);
}
} catch (error) {
console.error("Error fetching invites:", error);
}
commands?.create({
name: "vote",
description: "vote for user",
options: [
{
name: "username",
required: true,
description: "username of the user to vote for",
type: ApplicationCommandOptionType.User,
},
],
});
commands?.create({
name: "mute",
description: "temporarly mutes a user",
options: [
{
name: "username",
required: true,
description: "username of the user to mute",
type: ApplicationCommandOptionType.User,
},
],
});
commands?.create({
name: "unmute",
description: "unmute a user",
options: [
{
name: "username",
required: true,
description: "username of the user to mute",
type: ApplicationCommandOptionType.User,
},
],
});
commands?.create({
name: "mystatus",
description: "check your status",
});
commands?.create({
name: "updatenicks",
description:
"Does a api call to get users latest nickname for each user in the database.",
});
commands?.create({
name: "updatemygamename",
description:
"Checks your latest game name and updates it in the database.",
});
commands?.create({
name: "myvoters",
description: "shows the people that voted for you.",
});
commands?.create({
name: "addme",
description: "test",
});
commands?.create({
name: "getstatus",
description: "get user status plate",
options: [
{
name: "username",
required: true,
description: "username of the user to get the status",
type: ApplicationCommandOptionType.User,
},
],
});
commands?.create({
name: "strike",
description: "Strike a member",
options: [
{
name: "username",
required: true,
description: "username of the user",
type: ApplicationCommandOptionType.User,
},
{
name: "degree",
required: true,
description: "Degree of the strike",
type: ApplicationCommandOptionType.Number,
},
{
name: "reason",
required: true,
description: "Reason for the strike",
type: ApplicationCommandOptionType.String,
},
],
});
commands?.create({
name: "getmemberstrikes",
description: "Get member strikes",
options: [
{
name: "username",
required: true,
description: "username of the user",
type: ApplicationCommandOptionType.User,
},
],
});
commands?.create({
name: "getregister",
description: "get register button",
});
commands?.create({
name: "getdogfightroles",
description: "returns the dogfight roles embeds",
});
commands?.create({
name: "getbygamename",
description: "get user status plate",
options: [
{
name: "username",
required: true,
description: "username of the user to get the status",
type: ApplicationCommandOptionType.String,
},
{
name: "game",
required: true,
description: "game name of the user to get the status",
type: ApplicationCommandOptionType.String,
},
{
name: "platform",
required: true,
description: "platform of the user to get the status",
type: ApplicationCommandOptionType.String,
},
],
});
commands?.create({
name: "setpoints",
description: "set required points",
options: [
{
name: "points",
required: true,
description: "enter the required points",
type: ApplicationCommandOptionType.Number,
},
],
});
commands?.create({
name: "requiredpoints",
description: "preview required points",
});
commands?.create({
name: "closeticket",
description: "delete current channel",
});
commands?.create({
name: "ranking",
description: "Lists players ranking",
});
// send dogfight data to specific channel
const bf2042Channel = await guild.channels.fetch(settings[0].bf2042Channel);
const bfvChannel = await guild.channels.fetch(settings[0].bfvChannel);
cron.schedule("*/2 * * * *", async () => {
await fetchDogfightServersBF2042(bf2042Channel);
});
cron.schedule("*/1 * * * *", async () => {
await fetchBfvServers(bfvChannel);
});
});
// discordModals(client);
client.on(Events.MessageCreate, async (msg) => {
if (settings.length === 0) return;
const user = await findOne(msg.author.id);
if (!user) return;
//Checking the strikes
const strikes = await getAllActiveStrikes();
if (strikes && strikes.length > 0) {
const todaysDate = new Date();
strikes.forEach(async (strike) => {
if (strike.status === "active") {
if (strike.degree === 1) {
if (
isDifferenceGreaterThanMonths(
todaysDate,
new Date(strike.createdAt),
3
)
) {
strike.status = "resolved";
await strike.save();
await msg.member.roles
.remove(settings[0].strikeOne)
.catch((err) => {
console.log("Error" + err);
});
}
} else if (strike.degree === 2) {
if (
isDifferenceGreaterThanMonths(
todaysDate,
new Date(strike.createdAt),
6
)
) {
strike.status = "resolved";
await strike.save();
await msg.member.roles
.remove(settings[0].strikeTwo)
.catch((err) => {
console.log("Error" + err);
});
}
}
}
});
}
if (user) {
user.msgContribution += settings[0].msgValue;
if (user.msgContribution >= 1) {
user.msgContribution = 0;
user.contribution += 1;
}
if (
msg.channelId === settings[0].contentCreatorsId &&
matchYoutubeUrl(msg.content)
) {
user.contentContribution += settings[0].contentValue;
if (user.contentContribution >= 1) {
user.contentContribution = 0;
user.contribution += 1;
}
}
await user.save();
await hasReachedVotes(user, settings, client, msg.member);
}
if (msg.mentions?.roles?.first()) {
if (
[
settings[0].pcBfv,
settings[0].pcBf1,
settings[0].pcBf4,
settings[0].ps4Bfv,
settings[0].ps4Bf1,
settings[0].ps4Bf4,
settings[0].xboxBfv,
settings[0].xboxBf1,
settings[0].xboxBf4,
settings[0].allBf2042,
].includes(msg.mentions.roles.first().id) &&
msg.channelId?.toString() === settings[0].dogfightChannelId?.toString()
) {
// update usernames
// const user = await findOne(msg.author.id);
// const gameProfile = await getUserProfile(user.userNames[0], user.platforms[0], );
// console.log(user);
const botMsg = await msg.reply(
`Please only react if you going to participate in the dogfight, after 2 hours from this ping, you cannot react. \n - ${user.userNames[0]} \n`
);
await botMsg.react(YES_EMOJI);
}
}
//we dont want messages from the bot
if (msg.author.bot) return;
// in case you are very bored
if (msg.content.toLowerCase() === "who is the best pilot in the universe") {
return msg.reply("LhonXD");
}
if (
msg.content.toLowerCase() ===
"who lies about who is the worst pilot in the universe"
) {
return msg.reply("MrIcePops");
}
});
client.on(Events.InteractionCreate, async (interaction) => {
// return null if the interaction is from the modal submit
// this should be removed
if (
!["wantToRegister", "registerButton"].includes(interaction.customId) &&
!["mystatus", "getregister", "getdogfightroles", "ranking"].includes(
interaction.commandName
)
)
await interaction.deferReply({ ephemeral: true });
if (interaction.commandName === "mystatus") {
await interaction.deferReply();
await myStatus(interaction, settings);
} else if (interaction.commandName === "addme") {
try {
const guild = await client.guilds?.cache.get(process.env.GUILD_ID);
const role = await guild.roles.cache.find((role) => {
return role.name === "@everyone";
});
const mod = await guild.roles.cache.find((role) => {
return role.id === "548861871013494784";
});
await guild.channels.create("test", {
parent: settings[0].ticketsParentId,
permissionOverwrites: [
{
id: role?.id,
deny: ["VIEW_CHANNEL"],
},
{
id: interaction.user.id,
allow: ["VIEW_CHANNEL"],
},
{
id: mod?.id,
allow: ["VIEW_CHANNEL"],
},
],
});
return await interaction.editReply("ok");
} catch (error) {
console.log(error);
}
} else if (interaction.commandName === "getdogfightroles") {
await getDogfightRoles(interaction, settings, client);
} else if (interaction.commandName === "mute") {
await muteUser(interaction, settings);
} else if (interaction.commandName === "unmute") {
await unmuteUser(interaction, settings);
} else if (interaction.commandName === "getbygamename") {
await getByGameName(interaction, settings);
} else if (interaction.commandName === "strike") {
await strikeMember(interaction, settings);
} else if (interaction.commandName === "getmemberstrikes") {
await getMemberStrikes(interaction, settings);
} else if (interaction.commandName === "updatenicks") {
await updateNicks(interaction, settings);
} else if (interaction.commandName === "updatemygamename") {
await updateMyGameName(interaction);
} else if (interaction.commandName === "closeticket") {
await closeTicket(interaction, settings);
} else if (interaction.commandName === "getregister") {
await interaction.deferReply();
await getRegister(interaction, settings);
} else if (interaction.commandName === "ranking") {
await interaction.deferReply();
try {
const membersData = await getMembersRankingData();
const attachment = await generateMemberTable(
membersData.map((el) => {
return {
name: el._id,
avatar: el.avatar,
username: el.userNames[0],
totalPoints: el.totalVotes,
};
})
);
await interaction.editReply({
files: [attachment],
});
} catch (error) {
await interaction.editReply(error.toString());
}
} else if (interaction.commandName === "requiredpoints") {
getRequiredPoints(interaction, settings);
} else if (interaction.commandName === "getstatus") {
await getStatus(interaction, settings);
} else if (interaction.commandName === "myvoters") {
return await interaction.editReply({
content: "I lied, not gonna tell you.",
ephemeral: true,
});
} else if (interaction.commandName === "vote") {
await vote(interaction, settings);
} else if (interaction.commandName === "setpoints") {
await setPoints(interaction, settings);
} else if (
["personalityId", "contributionId", "skillsId"].includes(
interaction.customId?.split("-")[0]
)
) {
await submitVote(interaction, settings, client);
} else if (interaction.customId === "wantToRegister") {
await linkAnotherAccount(interaction, client);
} else if (interaction.customId === "refuseToRegister") {
await denyLinkAnotherAccount(interaction, settings);
} else if (interaction.customId === "registerButton") {
await register(interaction, client);
} else if (interaction.customId === "registerBf2") {
await registerBf2(interaction, client);
}
// ------------ Modal Submit ------------------------------
// this is for the dropdowns we will use it when mobile app is updated
// let gameVal = await modal.getSelectMenuValues("gameVal");
// const gameNameVal = await modal.getTextInputValue("gameNameVal");
// let platformVal = await modal.getSelectMenuValues("platformVal");
// if (platformVal?.length > 0) platformVal = platformVal[0];
// if (gameVal?.length > 0) gameVal = gameVal[0];
if (!interaction.isModalSubmit()) return;
const gameVal = interaction.fields.getTextInputValue("gameVal");
const gameNameVal = interaction.fields.getTextInputValue("gameNameVal");
const platformVal = interaction.fields.getTextInputValue("platformVal");
if (interaction.customId === "bf2Modal") {
await submitRegisterBf2(interaction, settings);
} else if (
["registerModal", "linkAnotherAccount"].includes(interaction.customId)
) {
console.log("here");
if (
!["bfv", "bf1", "bf4", "bf3", "bf2042"].includes(
gameVal?.toLowerCase()?.trim()
)
)
return await interaction.editReply({
content: "Please try again and enter correct game",
ephemeral: true,
});
if (
!["pc", "ps4", "ps3", "xbox360", "xboxone"].includes(
platformVal?.toLowerCase()?.trim()
)
)
return await interaction.editReply({
content: "Please try again and enter correct platform",
ephemeral: true,
});
try {
const returnedMember = await getUserProfile(
gameVal,
gameNameVal,
platformVal
);
if (returnedMember?.data?.id) {
// we check if this account is linked by someone else already
if (await isAccountAlreadyLinked(returnedMember, interaction)) {
return await interaction.editReply({
content: "This account is already linked",
});
}
if (interaction.customId === "registerModal") {
await submitRegister(
interaction,
settings,
returnedMember,
client,
platformVal,
gameVal
);
} else if (interaction.customId === "linkAnotherAccount") {
await subLinkAlt(interaction, returnedMember, platformVal);
// }
// show them their plate here
}
} else {
return await interaction.editReply({
content: "game profile not found",
ephemeral: true,
});
}
} catch (error) {
return await interaction.editReply({
content: "profile not found",
ephemeral: true,
});
}
}
});
// client.on("modalSubmit", async (modal) => {});
client.on(Events.MessageReactionAdd, async (reaction, user) => {
if (user.bot) return;
const { guild } = reaction.message;
const discordUser = guild.members.cache.find(
(member) => member.id === user.id
);
// dogfight roles
if (
["bf4", "bfv", "bf1", "bf2042", "dcs"].includes(
reaction.emoji.name?.trim()?.toLowerCase()
)
) {
const { guild } = reaction.message;
const msg = await reaction.message.fetch();
if (msg.author.id !== settings[0].botId) return;
const member = guild.members.cache.find(
(member) => member.id === user.id
);
console.log(member);
const title = msg.embeds[0].data.title.toLowerCase();
// dogfight roles
console.log(msg.channelId);
if (msg.channelId === settings[0].dogfightRolesChannelId) {
if (title.includes("pc")) {
if (reaction.emoji.name?.trim().toLowerCase() === "bf4") {
member.roles.add(settings[0].pcBf4).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bfv") {
console.log("here");
member.roles.add(settings[0].pcBfv).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf1") {
member.roles.add(settings[0].pcBf1).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf2042") {
member.roles.add(settings[0].allBf2042).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "dcs") {
member.roles.add(settings[0].dcsPc).catch((err) => {
console.log("Error" + err);
});
}
} else if (title.includes("xbox")) {
if (reaction.emoji.name?.trim().toLowerCase() === "bf4") {
member.roles.add(settings[0].xboxBf4).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bfv") {
member.roles.add(settings[0].xboxBfv).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf1") {
member.roles.add(settings[0].xboxBf1).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf2042") {
member.roles.add(settings[0].allBf2042).catch((err) => {
console.log("Error" + err);
});
}
} else if (title.includes("playstation")) {
if (reaction.emoji.name?.trim().toLowerCase() === "bf4") {
member.roles.add(settings[0].ps4Bf4).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bfv") {
member.roles.add(settings[0].ps4Bfv).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf1") {
member.roles.add(settings[0].ps4Bf1).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf2042") {
member.roles.add(settings[0].allBf2042).catch((err) => {
console.log("Error" + err);
});
}
}
}
}
const dateNow = new Date();
if (reaction.emoji.name === YES_EMOJI) {
const msg = await reaction.message.fetch();
if (msg.author.id !== settings[0].botId) return;
const msgTime = reaction.message.createdAt;
if (dateNow.getDay() === msgTime.getDay()) {
if (dateNow.getHours() - msgTime.getHours() <= 2) {
const member = await findOne(user.id);
const askedForDf = msg.content.includes(member?.userNames[0]);
const gotPoints = msg.content.includes("**");
if (member && !askedForDf) {
const mainUser = await findOne(
reaction.message.mentions?.repliedUser?.id
);
if (!gotPoints) {
mainUser.rolePingContribution += settings[0].rolePingValue;
await msg.edit(`${msg.content} **`);
mainUser.rolePingContribution += settings[0].rolePingValue;
await mainUser.save();
if (mainUser.rolePingContribution >= 1) {
mainUser.rolePingContribution = 0;
mainUser.skills += 1;
await mainUser.save();
// await hasReachedVotes(mainUser, settings, client, discordUser);
}
}
member.dfReactionContribution += settings[0].dfReactionValue;
if (member.dfReactionContribution >= 1) {
member.dfReactionContribution = 0;
member.skills += 1;
}
if (!msg.content.toString().includes(member.userNames[0])) {
await msg.edit(`${msg.content} \n - ${member.userNames[0]} \n`);
}
await member.save();
// await hasReachedVotes(member, settings, client, discordUser);
}
}
}
}
});
client.on(Events.MessageReactionRemove, async (reaction, user) => {
if (user.bot) return;
const dateNow = new Date();
if (
["bf4", "bfv", "bf1", "bf2042", "dcs"].includes(
reaction.emoji.name?.trim()?.toLowerCase()
)
) {
const { guild } = reaction.message;
const msg = await reaction.message.fetch();
if (msg.author.id !== settings[0].botId) return;
const member = guild.members.cache.find(
(member) => member.id === user.id
);
const title = msg.embeds[0].data.title.toLowerCase();
// dogfight roles
if (msg.channelId === settings[0].dogfightRolesChannelId) {
if (title.includes("pc")) {
if (reaction.emoji.name?.trim().toLowerCase() === "bf4") {
member.roles.remove(settings[0].pcBf4).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bfv") {
member.roles.remove(settings[0].pcBfv).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf1") {
member.roles.remove(settings[0].pcBf1).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf2042") {
member.roles.remove(settings[0].allBf2042).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "dcs") {
member.roles.remove(settings[0].dcsPc).catch((err) => {
console.log("Error" + err);
});
}
} else if (title.includes("xbox")) {
if (reaction.emoji.name?.trim().toLowerCase() === "bf4") {
member.roles.remove(settings[0].xboxBf4).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bfv") {
member.roles.remove(settings[0].xboxBfv).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf1") {
member.roles.remove(settings[0].xboxBf1).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf2042") {
member.roles.remove(settings[0].allBf2042).catch((err) => {
console.log("Error" + err);
});
}
} else if (title.includes("playstation")) {
if (reaction.emoji.name?.trim().toLowerCase() === "bf4") {
member.roles.remove(settings[0].ps4Bf4).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bfv") {
member.roles.remove(settings[0].ps4Bfv).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf1") {
member.roles.remove(settings[0].ps4Bf1).catch((err) => {
console.log("Error" + err);
});
} else if (reaction.emoji.name?.trim().toLowerCase() === "bf2042") {
member.roles.remove(settings[0].allBf2042).catch((err) => {
console.log("Error" + err);
});
}
}
}
}
if (reaction.emoji.name === YES_EMOJI) {
const msg = await reaction.message.fetch();
if (msg.author.id !== settings[0].botId) return;
const msgTime = reaction.message.createdAt;
if (dateNow.getDay() === msgTime.getDay()) {
if (dateNow.getHours() - msgTime.getHours() <= 2) {
const msg = await reaction.message.fetch();
const member = await findOne(user.id);
const askedForDf = msg.content.includes(member?.userNames[0]);
if (member && !askedForDf) {
member.dfReactionContribution -= settings[0].dfReactionValue;
if (member.dfReactionContribution >= 1) {
member.dfReactionContribution = 0;
member.skills -= 1;
}
if (!msg.content.toString().includes(member.userNames[0])) {
await msg.edit(
msg.content.replace(`\n - ${member.userNames[0]} \n`, "")
);
}
await member.save();
}
}
}
}
});
client.on(Events.GuildMemberAdd, async (member) => {
try {
const channelId = "548861917431726091";
const channel = member.guild.channels.cache.get(channelId);
const newInvites = await member.guild.invites.fetch();
for await (const invite of newInvites.values()) {
const storedInvite = await Invite.findOne({
inviteCode: invite.code,
});
if (storedInvite && invite.uses > storedInvite.uses) {
const message = `${member.user.tag} joined using invite code ${invite.code}, created by <@${storedInvite.inviter}>`;
await channel.send(message);
storedInvite.uses = invite.uses;
await storedInvite.save();
break;
}
}
} catch (error) {
console.error("Error tracking invite usage:", error);
}
});
};