-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
814 lines (742 loc) · 31.9 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
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
const express = require("express");
const {
Client,
GatewayIntentBits,
ButtonBuilder,
ButtonStyle,
ActionRowBuilder,
Events,
EmbedBuilder,
PermissionsBitField,
ChannelType,
} = require("discord.js");
const fs = require("fs");
const { v4: uuidv4 } = require("uuid");
const app = express();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
// Przechowywanie menedżerów i priorytetowych kanałów
const raidManagers = new Map();
let priorityChannels = new Set();
client.raids = new Map();
const priorityRoles = [
"1094860225955242115",
"1124781716700143717",
"1165383754211131473",
];
const priorityServerId = "1094726552610156688";
// Lista emoji dla priorytetowego serwera
const priorityEmojis = [
{ id: "1095004009414283314", name: "archsp1" },
{ id: "1095004578967199865", name: "archsp2" },
{ id: "1095004662832300042", name: "archsp3" },
{ id: "1095004747955712166", name: "archsp4" },
{ id: "1095004811168071710", name: "archsp5" },
{ id: "1095004890213920890", name: "archsp6" },
{ id: "1095004995700662354", name: "archsp7" },
{ id: "1095005054529966181", name: "archsp8" },
{ id: "1095005137229066410", name: "archsp9" },
{ id: "1095005196758810704", name: "archsp10" },
{ id: "1255666385288167444", name: "archsp11" },
{ id: "1095001073854468147", name: "warsp1" },
{ id: "1095003184189149315", name: "warsp2" },
{ id: "1095003271069958164", name: "warsp3" },
{ id: "1095003348123525150", name: "warsp4" },
{ id: "1095003429748875395", name: "warsp5" },
{ id: "1095003529732694147", name: "warsp6" },
{ id: "1095003599211348049", name: "warsp7" },
{ id: "1095003674327138375", name: "warsp8" },
{ id: "1095003772272525454", name: "warsp9" },
{ id: "1095003866677923972", name: "warsp10" },
{ id: "1255664534719303781", name: "warsp11" },
{ id: "1095006313462911016", name: "magsp1" },
{ id: "1095006395025334272", name: "magsp2" },
{ id: "1095006452797677619", name: "magsp3" },
{ id: "1095006513061437440", name: "magsp4" },
{ id: "1095006831396528240", name: "magsp5" },
{ id: "1095006900141182996", name: "magsp6" },
{ id: "1095006969099722892", name: "magsp7" },
{ id: "1095007030466596975", name: "magsp8" },
{ id: "1095007124381241434", name: "magsp9" },
{ id: "1095007187866222683", name: "magsp10" },
{ id: "1255665297235513464", name: "magsp11" },
{ id: "1095007263372083340", name: "mswsp1" },
{ id: "1095007371920691252", name: "mswsp2" },
{ id: "1095007440749203518", name: "mswsp3" },
{ id: "1095007501516275782", name: "mswsp4" },
{ id: "1255667075054043166", name: "mswsp11" },
];
// Lista emoji dla reszty serwerów
const defaultEmojis = [
{ id: "1259195576696967238", name: "1a" },
{ id: "1259195010281373727", name: "2a" },
{ id: "1259195594879008768", name: "3a" },
{ id: "1259195005957046313", name: "4a" },
{ id: "1259195620946874408", name: "5a" },
{ id: "1259195002483900416", name: "6a" },
{ id: "1259195746977058976", name: "7a" },
{ id: "1259194998620950630", name: "8a" },
{ id: "1259195767625875486", name: "9a" },
{ id: "1259194995265638530", name: "10a" },
{ id: "1259195801037574287", name: "11a" },
{ id: "1259195299793080391", name: "1w" },
{ id: "1259195030963486802", name: "2w" },
{ id: "1259195323524321330", name: "3w" },
{ id: "1259195027951976538", name: "4w" },
{ id: "1259195388561326251", name: "5w" },
{ id: "1259195023644295333", name: "6w" },
{ id: "1259195416075964518", name: "7w" },
{ id: "1259195020456628274", name: "8w" },
{ id: "1259195017969401908", name: "9w" },
{ id: "1259195482841022556", name: "10w" },
{ id: "1259195013758324787", name: "11w" },
{ id: "1259194991679635557", name: "1m" },
{ id: "1259195887536701460", name: "2m" },
{ id: "1259194988269404275", name: "3m" },
{ id: "1259195926132686899", name: "4m" },
{ id: "1259194984511574108", name: "5m" },
{ id: "1259195976334311495", name: "6m" },
{ id: "1259194981126635621", name: "7m" },
{ id: "1259194978966569053", name: "8m" },
{ id: "1259195995695091783", name: "9m" },
{ id: "1259194975430643742", name: "10m" },
{ id: "1259194973249863774", name: "11m" },
{ id: "1259194972247298108", name: "1x" },
{ id: "1259194970494210149", name: "2x" },
{ id: "1259194968946376825", name: "3x" },
{ id: "1259194967545479188", name: "4x" },
{ id: "1259194966190592144", name: "5x" },
{ id: "1259194964819181628", name: "6x" },
{ id: "1259194963015762121", name: "7x" },
];
client.once("ready", () => {
console.log(`Zalogowano jako ${client.user.tag}!`);
loadRaidManagers();
loadRaidLists(); // Load raid lists when bot starts
});
client.on("channelDelete", async (channel) => {
// Sprawdź, czy kanał jest na liście priorytetowych kanałów
if (priorityChannels.has(channel.id)) {
priorityChannels.delete(channel.id); // Usuń kanał z priorytetowych kanałów
}
// Usuń raid związany z usuniętym kanałem
const raids = Array.from(client.raids.values()).filter(raid => raid.channelId !== channel.id);
client.raids = new Map(raids.map(raid => [raid.channelId, raid]));
// Zapisz zmiany do pliku raidLists.json
saveRaidLists();
});
client.on("messageCreate", async (message) => {
try {
if (
message.content.startsWith("!newraid") ||
message.content.startsWith("!prioraid")
) {
const isPriorityRaid = message.content.startsWith("!prioraid");
const args = message.content.match(/"[^"]+"|[^\s]+/g);
const raidName = args[1].replace(/"/g, "");
const raidDay = args[2].replace(/"/g, "");
const raidTime = args[3].replace(/"/g, "");
const positions = parseInt(args[4]);
const akt = isPriorityRaid ? args[5]?.replace(/"/g, "") : null;
const channelName = `${raidName}-${raidDay}-${raidTime}`
.replace(/\s+/g, "-")
.toLowerCase();
const formattedRaidName = raidName.toUpperCase();
let parentId;
if (isPriorityRaid && message.guild.id === priorityServerId) {
if (akt === "a8") {
parentId = "1199378967300419725";
} else if (akt === "pollu") {
parentId = "1126289273780441190";
} else if (akt === "arma") {
parentId = "1126289273780441190";
} else if (akt === "carma") {
parentId = "1139537965111054496";
} else {
parentId = "1094734625298976899";
}
}
const raidChannel = await message.guild.channels.create({
name: channelName,
type: ChannelType.GuildText,
parent: parentId || undefined,
permissionOverwrites: [
{
id: message.guild.id,
allow: [PermissionsBitField.Flags.ViewChannel],
deny: [PermissionsBitField.Flags.SendMessages],
},
{
id: message.author.id,
allow: [
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.SendMessages,
PermissionsBitField.Flags.ManageChannels,
],
},
],
});
if (isPriorityRaid) {
priorityChannels.add(raidChannel.id);
}
const embed = new EmbedBuilder()
.setTitle(`Raid: ${formattedRaidName}`)
.setDescription(
`**Lider/Leader:** <@${message.author.id}>\n\n` +
`**Kiedy?/When?:** ${raidDay} ${raidTime}\n\n` +
`**Channel:** 5\n\n` +
`**Wymagania/Requirements:** C80 with huge damage, C90\n\n` +
`<:emoji1:1115315303283441814> <:emoji2:1115315272350453820> <:emoji3:1165642749110919178>\n\n` +
`---\n`
)
.setColor(0xff0000);
if (akt === "arma") {
for (let i = 1; i <= positions - 2; i++) {
embed.addFields({
name: `${i}.`,
value: "\u200B",
inline: false,
});
}
embed.addFields(
{
name: `${positions - 1}. (WK)`,
value: "\u200B",
},
{
name: `${positions}. (CRUSS)`,
value: "\u200B",
},
{
name: `Rezerwowi/Reserves:`,
value: "\u200B",
}
);
} else if (akt === "pollu") {
for (let i = 1; i <= positions - 3; i++) {
embed.addFields({
name: `${i}.`,
value: "\u200B",
});
}
embed.addFields(
{
name: `${positions - 2}. (WK)`,
value: "\u200B",
},
{
name: `${positions - 1}. (CRUSS)`,
value: "\u200B",
},
{
name: `${positions}. (SERKER)`,
value: "\u200B",
},
{
name: `Rezerwowi/Reserves:`,
value: "\u200B",
}
);
} else {
for (let i = 1; i <= positions; i++) {
embed.addFields({
name: `${i}.`,
value: "\u200B",
});
}
embed.addFields(
{
name: `Rezerwowi/Reserves:`,
value: "\u200B",
}
);
}
const emojis =
message.guild.id === priorityServerId
? priorityEmojis
: defaultEmojis;
const actionRows = [];
for (let i = 0; i < 8; i++) {
const row = new ActionRowBuilder();
for (let j = 0; j < 5; j++) {
const index = i * 5 + j;
if (index >= emojis.length) break;
row.addComponents(
new ButtonBuilder()
.setCustomId(`join${index + 1}`)
.setLabel(" ")
.setStyle(ButtonStyle.Primary)
.setEmoji(emojis[index]),
);
}
if (row.components.length > 0) {
actionRows.push(row);
}
}
const outRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("out")
.setLabel("Wypisz")
.setStyle(ButtonStyle.Danger)
.setEmoji("❌"),
);
const embedMessage = await raidChannel.send({ embeds: [embed] });
const raidId = uuidv4();
const raid = {
id: raidId,
channelId: raidChannel.id,
messageId: embedMessage.id,
name: raidName,
date: raidDay,
time: raidTime,
positions,
isPriorityRaid,
akt,
};
client.raids.set(raidChannel.id, raid);
saveRaidLists();
for (const row of actionRows) {
await raidChannel.send({ components: [row] });
}
await raidChannel.send({ components: [outRow] });
await raidChannel.send({
content: `Prio for <@&1094860225955242115>, <@&1165383754211131473>, <@&1124781716700143717> up to 12h before raid.`,
});
} else if (message.content.startsWith("!addmanager")) {
const args = message.content.split(" ");
const userId = args[1].replace(/[<@!>]/g, "");
if (message.author.id === process.env.OWNER_ID) {
addRaidManager(message.guild.id, userId);
saveRaidManagers();
message.reply(
`Użytkownik <@${userId}> został dodany jako menedżer raidu.`,
);
} else {
message.reply(
"Nie masz uprawnień do dodawania menedżerów raidu.",
);
}
} else if (message.content.startsWith("!removemanager")) {
const args = message.content.split(" ");
const userId = args[1].replace(/[<@!>]/g, "");
if (message.author.id === process.env.OWNER_ID) {
removeRaidManager(message.guild.id, userId);
saveRaidManagers();
message.reply(
`Użytkownik <@${userId}> został usunięty z menedżerów raidu.`,
);
} else {
message.reply(
"Nie masz uprawnień do usuwania menedżerów raidu.",
);
}
} else if (message.content.startsWith("!out")) {
const args = message.content.split(" ");
const userId = args[1].replace(/[<@!>]/g, "");
if (isRaidManager(message.guild.id, message.author.id)) {
const raidChannel = message.channel;
const raid = client.raids.get(raidChannel.id);
if (!raid) {
return message.reply("Nie znaleziono raidu dla tego kanału.");
}
try {
const raidMessage = await raidChannel.messages.fetch(raid.messageId);
const success = await removeUserFromList(raidMessage, userId);
if (success) {
message.reply(
`Użytkownik <@${userId}> został usunięty z listy.`,
);
saveRaidLists();
} else {
message.reply("Użytkownik nie jest zapisany na liście.");
}
await checkAndMoveReserves(raidMessage, raidChannel);
} catch (error) {
console.error("Failed to fetch message:", error);
message.reply("Wystąpił błąd podczas próby pobrania wiadomości.");
}
} else {
message.reply(
"Nie masz uprawnień do usuwania użytkowników z listy.",
);
}
} else if (message.content.startsWith("!deleteprio")) {
if (!isRaidManager(message.guild.id, message.author.id)) {
return message.reply(
"Nie masz uprawnień do usuwania priorytetu.",
);
}
priorityChannels.delete(message.channel.id);
message.reply(
"Priorytet został usunięty. Teraz każdy może się zapisać. <@&1096804534409494598>",
);
} else if (message.content.startsWith("!alt")) {
const args = message.content.match(/"[^"]+"|[^\s]+/g);
const nick = args[1];
const value = args.slice(2).join(" ");
if (isRaidManager(message.guild.id, message.author.id)) {
const raidChannel = message.channel;
const raid = client.raids.get(raidChannel.id);
if (!raid) {
return message.reply("Nie znaleziono raidu dla tego kanału.");
}
try {
const raidMessage = await raidChannel.messages.fetch(raid.messageId);
const embed = raidMessage.embeds[0];
const fields = embed.fields;
let emptyFieldIndex = -1;
for (let i = 0; i < fields.length; i++) {
if (fields[i].value === "\u200B" && emptyFieldIndex === -1) {
emptyFieldIndex = i;
}
}
if (emptyFieldIndex !== -1) {
fields[emptyFieldIndex].value = `${nick} ${value}`;
await raidMessage.edit({ embeds: [embed] });
message.reply(
`Postać ${nick} ${value} została dodana do listy.`,
);
} else {
message.reply("Brak wolnych miejsc na liście.");
}
await checkAndMoveReserves(raidMessage, raidChannel);
} catch (error) {
console.error("Failed to fetch message:", error);
message.reply("Wystąpił błąd podczas próby pobrania wiadomości.");
}
} else {
message.reply(
"Nie masz uprawnień do ręcznego dodawania postaci.",
);
}
} else if (message.content.startsWith("!removeplayer")) {
const args = message.content.split(" ");
const position = parseInt(args[1]);
if (isRaidManager(message.guild.id, message.author.id)) {
const raidChannel = message.channel;
const raid = client.raids.get(raidChannel.id);
if (!raid) {
return message.reply("Nie znaleziono raidu dla tego kanału.");
}
try {
const raidMessage = await raidChannel.messages.fetch(raid.messageId);
const embed = raidMessage.embeds[0];
const fields = embed.fields;
if (position > 0 && position <= fields.length) {
fields[position - 1].value = "\u200B";
await raidMessage.edit({ embeds: [embed] });
message.reply(`Pozycja ${position} została usunięta z listy.`);
await checkAndMoveReserves(raidMessage, raidChannel);
saveRaidLists(); // Save after removing a position from the list
} else {
message.reply("Nieprawidłowa pozycja.");
}
} catch (error) {
console.error("Failed to fetch message:", error);
message.reply("Wystąpił błąd podczas próby pobrania wiadomości.");
}
} else {
message.reply("Nie masz uprawnień do usuwania pozycji z listy.");
}
}
} catch (error) {
console.error(error);
}
});
client.on(Events.InteractionCreate, async (interaction) => {
try {
if (!interaction.isButton()) return;
let message;
try {
const raid = client.raids.get(interaction.channelId);
if (!raid) {
throw new Error("Raid data not found for this channel");
}
message = await interaction.channel.messages.fetch(raid.messageId);
} catch (error) {
console.error("Failed to fetch message:", error);
return interaction.reply({
content: "Wystąpił błąd podczas próby pobrania wiadomości.",
ephemeral: true,
});
}
const embed = message.embeds[0];
const fields = embed.fields;
const user = `<@${interaction.user.id}>`;
const emojis =
interaction.guild.id === priorityServerId
? priorityEmojis
: defaultEmojis;
const reservedEmojisPollu = ["archsp4", "warsp3", "warsp4"];
const reservedEmojisArma = ["archsp4", "warsp3"];
const reservedIndicesPollu = [fields.length - 4, fields.length - 3, fields.length - 2];
const reservedIndicesArma = [fields.length - 3, fields.length - 2];
if (interaction.customId.startsWith("join")) {
if (
priorityChannels.has(interaction.channelId) &&
!interaction.member.roles.cache.some((role) =>
priorityRoles.includes(role.id),
)
) {
return interaction.reply({
content: "Nie masz priorytetu!",
ephemeral: true,
});
}
const emojiIndex = parseInt(interaction.customId.replace("join", "")) - 1;
const emoji = emojis[emojiIndex];
const isReservedEmojiPollu = reservedEmojisPollu.includes(emoji.name);
const isReservedEmojiArma = reservedEmojisArma.includes(emoji.name);
let userFieldIndex = -1;
for (let i = 0; i < fields.length; i++) {
if (fields[i].value.includes(user)) {
userFieldIndex = i;
break;
}
}
if (userFieldIndex !== -1) {
fields[userFieldIndex].value += ` <:${emoji.name}:${emoji.id}>`;
await message.edit({ embeds: [embed] });
await interaction.deferUpdate();
await interaction.channel.send({
content: `${user} został zapisany!`,
});
// Sprawdź, czy użytkownik na liście rezerwowej dodał zarezerwowaną emotkę
await checkAndMoveReserves(message, interaction.channel, true);
} else {
let emptyFieldIndex = -1;
for (let i = 0; i < fields.length; i++) {
if (fields[i].value === "\u200B" && !reservedIndicesPollu.includes(i) && !reservedIndicesArma.includes(i)) {
emptyFieldIndex = i;
break;
}
}
if (interaction.channel.name.includes("arma") && isReservedEmojiArma) {
const reservedIndex = reservedIndicesArma[reservedEmojisArma.indexOf(emoji.name)];
if (fields[reservedIndex].value === "\u200B") {
fields[reservedIndex].value = `${user} <:${emoji.name}:${emoji.id}>`;
} else {
const reserveField = fields.find(field => field.name === 'Rezerwowi/Reserves:');
reserveField.value += `\n${user} <:${emoji.name}:${emoji.id}>`;
}
} else if (interaction.channel.name.includes("pollu") && isReservedEmojiPollu) {
const reservedIndex = reservedIndicesPollu[reservedEmojisPollu.indexOf(emoji.name)];
if (fields[reservedIndex].value === "\u200B") {
fields[reservedIndex].value = `${user} <:${emoji.name}:${emoji.id}>`;
} else {
const reserveField = fields.find(field => field.name === 'Rezerwowi/Reserves:');
reserveField.value += `\n${user} <:${emoji.name}:${emoji.id}>`;
}
} else if (emptyFieldIndex !== -1) {
fields[emptyFieldIndex].value = `${user} <:${emoji.name}:${emoji.id}>`;
await interaction.channel.send({
content: `${user} został zapisany!`,
});
} else {
const reserveField = fields.find(field => field.name === 'Rezerwowi/Reserves:');
reserveField.value += `\n${user} <:${emoji.name}:${emoji.id}>`;
}
await message.edit({ embeds: [embed] });
await interaction.deferUpdate();
}
} else if (interaction.customId === "out") {
const success = await removeUserFromList(message, interaction.user.id);
if (success) {
await interaction.channel.send({
content: `${user} wypisał się! Znajdź zastępstwo jeżeli wypisałeś się 6 godzin przed maratonem.`,
});
} else {
await interaction.reply({
content: "Nie jesteś zapisany!",
ephemeral: true,
});
}
await checkAndMoveReserves(message, interaction.channel);
}
} catch (error) {
console.error(error);
interaction.reply({
content: "Wystąpił nieoczekiwany błąd.",
ephemeral: true,
});
}
});
async function removeUserFromList(message, userId) {
const embed = message.embeds[0];
const fields = embed.fields;
const user = `<@${userId}>`;
let removed = false;
let emptyFieldIndex = -1;
for (let i = 0; i < fields.length; i++) {
if (fields[i].value.includes(user)) {
fields[i].value = "\u200B";
removed = true;
emptyFieldIndex = i;
break;
}
}
if (removed) {
await message.edit({ embeds: [embed] });
return true;
} else {
return false;
}
}
function saveRaidLists() {
const data = {
priorityChannels: Array.from(priorityChannels),
raids: Array.from(client.raids.values()),
};
fs.writeFileSync("raidLists.json", JSON.stringify(data, null, 2), "utf-8");
}
function loadRaidLists() {
if (fs.existsSync("raidLists.json")) {
const data = fs.readFileSync("raidLists.json", "utf-8");
const parsed = JSON.parse(data);
priorityChannels = new Set(parsed.priorityChannels);
parsed.raids.forEach(raid => {
client.raids.set(raid.channelId, raid);
});
}
}
async function checkAndMoveReserves(message, channel, checkReservedEmojis = false) {
const embed = message.embeds[0];
const fields = embed.fields;
let emptyFieldIndex = -1;
for (let i = 0; i < fields.length; i++) {
if (fields[i].value === "\u200B") {
emptyFieldIndex = i;
break;
}
}
if (emptyFieldIndex !== -1) {
let reservesStartIndex = fields.findIndex(field => field.name === 'Rezerwowi/Reserves:');
if (reservesStartIndex !== -1) {
const reserveField = fields[reservesStartIndex];
const reserveLines = reserveField.value.split("\n").filter(line => line.trim() !== "\u200B");
if (reserveLines.length > 0) {
const reservedEmojisPollu = ["archsp4", "warsp3", "warsp4"];
const reservedEmojisArma = ["archsp4", "warsp3"];
const reservedIndicesPollu = [fields.length - 4, fields.length - 3, fields.length - 2];
const reservedIndicesArma = [fields.length - 3, fields.length - 2];
const reservedIndexToEmojiPollu = {
[fields.length - 4]: "archsp4",
[fields.length - 3]: "warsp3",
[fields.length - 2]: "warsp4"
};
const reservedIndexToEmojiArma = {
[fields.length - 3]: "archsp4",
[fields.length - 2]: "warsp3"
};
let nextReserveUser = null;
if (channel.name.includes("arma") && reservedIndicesArma.includes(emptyFieldIndex)) {
const emojiName = reservedIndexToEmojiArma[emptyFieldIndex];
nextReserveUser = reserveLines.find(line => line.includes(emojiName));
if (nextReserveUser) {
reserveLines.splice(reserveLines.indexOf(nextReserveUser), 1);
}
} else if (channel.name.includes("pollu") && reservedIndicesPollu.includes(emptyFieldIndex)) {
const emojiName = reservedIndexToEmojiPollu[emptyFieldIndex];
nextReserveUser = reserveLines.find(line => line.includes(emojiName));
if (nextReserveUser) {
reserveLines.splice(reserveLines.indexOf(nextReserveUser), 1);
}
}
if (!nextReserveUser && !reservedIndicesPollu.includes(emptyFieldIndex) && !reservedIndicesArma.includes(emptyFieldIndex)) {
nextReserveUser = reserveLines.shift();
}
if (nextReserveUser) {
fields[emptyFieldIndex].value = nextReserveUser;
reserveField.value = reserveLines.length > 0 ? reserveLines.join("\n") : "\u200B";
await message.edit({ embeds: [embed] });
await message.channel.send({
content: `${nextReserveUser.split(' ')[0]} trafiasz na główną listę!`,
});
saveRaidLists(); // Save after moving reserves
}
}
}
} else if (checkReservedEmojis) {
const reservedEmojisPollu = ["archsp4", "warsp3", "warsp4"];
const reservedEmojisArma = ["archsp4", "warsp3"];
const reservedIndexToEmojiPollu = {
[fields.length - 4]: "archsp4",
[fields.length - 3]: "warsp3",
[fields.length - 2]: "warsp4"
};
const reservedIndexToEmojiArma = {
[fields.length - 3]: "archsp4",
[fields.length - 2]: "warsp3"
};
for (let i = 0; i < fields.length; i++) {
if (fields[i].value !== "\u200B" && fields[i].value.split(" ").length > 1) {
const emojis = fields[i].value.split(" ").slice(1);
for (let j = 0; j < emojis.length; j++) {
if (
(channel.name.includes("arma") && reservedEmojisArma.includes(emojis[j].split(":")[1])) ||
(channel.name.includes("pollu") && reservedEmojisPollu.includes(emojis[j].split(":")[1]))
) {
let userFieldIndex = i;
const user = fields[userFieldIndex].value.split(" ")[0];
fields[userFieldIndex].value = fields[userFieldIndex].value.split(" ").slice(0, 1).join(" ");
await checkAndMoveReserves(message, channel);
return;
}
}
}
}
}
}
function isRaidManager(guildId, userId) {
if (!raidManagers.has(guildId)) {
return false;
}
return raidManagers.get(guildId).has(userId);
}
function addRaidManager(guildId, userId) {
if (!raidManagers.has(guildId)) {
raidManagers.set(guildId, new Set());
}
raidManagers.get(guildId).add(userId);
saveRaidManagers(); // Zapisz zmiany
}
function removeRaidManager(guildId, userId) {
if (raidManagers.has(guildId)) {
raidManagers.get(guildId).delete(userId);
saveRaidManagers(); // Zapisz zmiany
}
}
function loadRaidManagers() {
if (fs.existsSync("raidManagers.json")) {
const data = fs.readFileSync("raidManagers.json", "utf-8");
const parsed = JSON.parse(data);
for (const guildId in parsed) {
raidManagers.set(guildId, new Set(parsed[guildId]));
}
}
}
function saveRaidManagers() {
const data = {};
raidManagers.forEach((managers, guildId) => {
data[guildId] = Array.from(managers);
});
fs.writeFileSync("raidManagers.json", JSON.stringify(data), "utf-8");
}
// Serwer Express do monitorowania pingu
app.get("/", (req, res) => {
console.log("Ping received");
res.send("Bot is running!");
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Serwer Express działa na porcie ${PORT}`);
});
require('dotenv').config();
client.login(process.env.DISCORD_BOT_TOKEN)
.then(() => console.log('Successfully logged in'))
.catch(err => console.error('Failed to login:', err));