Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -446,33 +446,36 @@ client.on('messageCreate', async (message) => {
|
|
| 446 |
|
| 447 |
if (commandName === 'friendly') {
|
| 448 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
|
| 449 |
-
|
| 450 |
const mentionArg = args[0] ? args[0].toLowerCase().replace('@', '') : null;
|
| 451 |
-
|
| 452 |
let pingType;
|
| 453 |
-
let
|
| 454 |
-
|
| 455 |
if (mentionArg === 'here' || mentionArg === 'everyone') {
|
| 456 |
pingType = mentionArg;
|
| 457 |
guildFriendlyPingType.set(message.guildId, pingType);
|
| 458 |
saveLineup();
|
| 459 |
-
|
| 460 |
} else if (parseInt(mentionArg)) {
|
| 461 |
-
|
| 462 |
pingType = guildFriendlyPingType.get(message.guildId) || 'everyone';
|
| 463 |
} else {
|
| 464 |
pingType = guildFriendlyPingType.get(message.guildId) || 'everyone';
|
| 465 |
}
|
| 466 |
-
|
|
|
|
|
|
|
|
|
|
| 467 |
let content;
|
| 468 |
if (pingType === 'here') {
|
| 469 |
-
content = getFriendlyText(message.guildId,
|
| 470 |
} else {
|
| 471 |
-
content = getFriendlyText(message.guildId,
|
| 472 |
}
|
| 473 |
// Debug: show what will be sent
|
| 474 |
-
console.log(`[DEBUG] FRIENDLY-MSG: guild=${message.guildId} author=${message.author?.id || 'unknown'} pingType=${pingType}
|
| 475 |
-
|
| 476 |
// Always use allowedMentions parse = ['everyone'] to avoid invalid enum
|
| 477 |
const mentionParse = ['everyone'];
|
| 478 |
const msg = await message.channel.send({ content, allowedMentions: { parse: mentionParse } });
|
|
@@ -480,66 +483,61 @@ client.on('messageCreate', async (message) => {
|
|
| 480 |
await msg.react('🟥');
|
| 481 |
storage.data.active_polls[message.guildId] = msg.id;
|
| 482 |
storage.save('active_polls');
|
| 483 |
-
|
| 484 |
-
// Wait for
|
| 485 |
const joined = new Set();
|
| 486 |
const filter = (reaction, user) => (reaction.emoji.name === '🟩' || reaction.emoji.name === "I'm In") && !user.bot;
|
| 487 |
const collector = msg.createReactionCollector({ filter, time: 600000 });
|
| 488 |
collector.on('collect', (reaction, user) => {
|
| 489 |
if (!joined.has(user.id)) {
|
| 490 |
joined.add(user.id);
|
| 491 |
-
msg.edit({ content: content + `\n\n${joined.size}/
|
| 492 |
}
|
| 493 |
-
if (joined.size >=
|
| 494 |
});
|
| 495 |
collector.on('end', async (col, reason) => {
|
| 496 |
-
if (joined.size >=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
const view = createLineupView(message.guildId);
|
| 498 |
-
await
|
| 499 |
addToCleanupQueue(message.guildId, message.channelId, msg.id, 'poll');
|
| 500 |
} else {
|
| 501 |
msg.edit({ content: content + `\n\n❌ Canceled: not enough players joined.` });
|
| 502 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
});
|
| 504 |
addToCleanupQueue(message.guildId, message.channelId, msg.id, 'poll');
|
| 505 |
}
|
| 506 |
|
| 507 |
if (commandName === 'lineup') {
|
| 508 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
|
| 509 |
-
|
| 510 |
const mentionArg = args[0] ? args[0].toLowerCase().replace('@', '') : null;
|
| 511 |
const pingType = mentionArg === 'here' ? 'here' : 'everyone';
|
| 512 |
guildPingType.set(message.guildId, pingType);
|
| 513 |
-
|
| 514 |
lineupOwners.set(message.guildId, message.author.id);
|
| 515 |
saveLineup();
|
| 516 |
-
// Lineup gating: wait for 6 players to react before showing the lineup UI
|
| 517 |
-
console.log(`[DEBUG] LINEUP-MSG: guild=${message.guildId} pingType=${pingType} owner=${message.author?.id || 'unknown'}`);
|
| 518 |
-
const pingMention = pingType === 'here' ? '@here' : '@everyone';
|
| 519 |
-
const introContent = `${pingMention}\n📋 **Lineup Session Pending**\nReact with ✅ to join. Need 6 players.`;
|
| 520 |
-
const introEmbed = UI.createEmbed("Waiting for Players", "React with ✅ to join. When 6 players have joined, the lineup UI will appear.", UI.colors.primary);
|
| 521 |
-
const introMsg = await message.channel.send({ content: introContent, embeds: [introEmbed] });
|
| 522 |
-
await introMsg.react('✅');
|
| 523 |
|
| 524 |
-
|
| 525 |
-
const
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
});
|
| 534 |
-
|
| 535 |
-
if (joined.size >= 6) {
|
| 536 |
-
const view = createLineupView(message.guildId);
|
| 537 |
-
await introMsg.edit(view);
|
| 538 |
-
addToCleanupQueue(message.guildId, message.channelId, introMsg.id, 'poll');
|
| 539 |
-
} else {
|
| 540 |
-
await introMsg.edit({ content: '❌ Lineup session canceled: not enough players joined.', embeds: [], components: [] });
|
| 541 |
-
}
|
| 542 |
-
});
|
| 543 |
}
|
| 544 |
|
| 545 |
if (commandName === 'top') {
|
|
@@ -1848,6 +1846,9 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1848 |
}
|
| 1849 |
});
|
| 1850 |
|
|
|
|
|
|
|
|
|
|
| 1851 |
// Global Reaction Handler (Triggers Lineup)
|
| 1852 |
client.on('messageReactionAdd', async (reaction, user) => {
|
| 1853 |
if (user.bot) return;
|
|
@@ -1858,25 +1859,51 @@ client.on('messageReactionAdd', async (reaction, user) => {
|
|
| 1858 |
const activePollId = storage.data.active_polls[guildId];
|
| 1859 |
|
| 1860 |
if (reaction.message.id === activePollId) {
|
| 1861 |
-
const needed = 6;
|
| 1862 |
const count = reaction.count - (reaction.me ? 1 : 0);
|
| 1863 |
|
| 1864 |
if (count >= needed) {
|
| 1865 |
const embed = UI.createEmbed(`${UI.icons.success} Friendly Ready!`, `We have **${count}** players! Starting lineup board...`, UI.colors.success);
|
| 1866 |
await reaction.message.channel.send({ embeds: [embed] });
|
| 1867 |
|
| 1868 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1869 |
const boardMsg = await reaction.message.channel.send(createLineupView(guildId));
|
| 1870 |
activeLineupMessages.set(guildId, { channelId: reaction.message.channelId, messageId: boardMsg.id });
|
| 1871 |
addToCleanupQueue(guildId, reaction.message.channelId, boardMsg.id, 'lineup');
|
| 1872 |
|
| 1873 |
delete storage.data.active_polls[guildId];
|
|
|
|
| 1874 |
storage.save('active_polls');
|
| 1875 |
}
|
| 1876 |
}
|
| 1877 |
}
|
| 1878 |
});
|
| 1879 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1880 |
// Staff Onboarding System
|
| 1881 |
client.on('guildMemberUpdate', async (oldMember, newMember) => {
|
| 1882 |
try {
|
|
|
|
| 446 |
|
| 447 |
if (commandName === 'friendly') {
|
| 448 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
|
| 449 |
+
|
| 450 |
const mentionArg = args[0] ? args[0].toLowerCase().replace('@', '') : null;
|
| 451 |
+
|
| 452 |
let pingType;
|
| 453 |
+
let needed = 6; // Default to 6
|
| 454 |
+
|
| 455 |
if (mentionArg === 'here' || mentionArg === 'everyone') {
|
| 456 |
pingType = mentionArg;
|
| 457 |
guildFriendlyPingType.set(message.guildId, pingType);
|
| 458 |
saveLineup();
|
| 459 |
+
needed = parseInt(args[1]) || 6;
|
| 460 |
} else if (parseInt(mentionArg)) {
|
| 461 |
+
needed = parseInt(mentionArg);
|
| 462 |
pingType = guildFriendlyPingType.get(message.guildId) || 'everyone';
|
| 463 |
} else {
|
| 464 |
pingType = guildFriendlyPingType.get(message.guildId) || 'everyone';
|
| 465 |
}
|
| 466 |
+
|
| 467 |
+
// Store the needed count for this poll
|
| 468 |
+
pollNeededCount.set(message.guildId, needed);
|
| 469 |
+
|
| 470 |
let content;
|
| 471 |
if (pingType === 'here') {
|
| 472 |
+
content = getFriendlyText(message.guildId, needed).replace('@everyone', '@here');
|
| 473 |
} else {
|
| 474 |
+
content = getFriendlyText(message.guildId, needed);
|
| 475 |
}
|
| 476 |
// Debug: show what will be sent
|
| 477 |
+
console.log(`[DEBUG] FRIENDLY-MSG: guild=${message.guildId} author=${message.author?.id || 'unknown'} pingType=${pingType} needed=${needed} contentPreview="${content.slice(0,60)}"`);
|
| 478 |
+
|
| 479 |
// Always use allowedMentions parse = ['everyone'] to avoid invalid enum
|
| 480 |
const mentionParse = ['everyone'];
|
| 481 |
const msg = await message.channel.send({ content, allowedMentions: { parse: mentionParse } });
|
|
|
|
| 483 |
await msg.react('🟥');
|
| 484 |
storage.data.active_polls[message.guildId] = msg.id;
|
| 485 |
storage.save('active_polls');
|
| 486 |
+
|
| 487 |
+
// Wait for players to react - count is dynamic based on 'needed'
|
| 488 |
const joined = new Set();
|
| 489 |
const filter = (reaction, user) => (reaction.emoji.name === '🟩' || reaction.emoji.name === "I'm In") && !user.bot;
|
| 490 |
const collector = msg.createReactionCollector({ filter, time: 600000 });
|
| 491 |
collector.on('collect', (reaction, user) => {
|
| 492 |
if (!joined.has(user.id)) {
|
| 493 |
joined.add(user.id);
|
| 494 |
+
msg.edit({ content: content + `\n\n${joined.size}/${needed} players joined. Waiting for more...` });
|
| 495 |
}
|
| 496 |
+
if (joined.size >= needed) collector.stop('ready');
|
| 497 |
});
|
| 498 |
collector.on('end', async (col, reason) => {
|
| 499 |
+
if (joined.size >= needed) {
|
| 500 |
+
// Clear lineup before showing
|
| 501 |
+
const lineup = getGuildLineup(message.guildId);
|
| 502 |
+
lineup.clear();
|
| 503 |
+
saveLineup();
|
| 504 |
+
|
| 505 |
+
// Send NEW message with lineup (don't edit the poll message)
|
| 506 |
const view = createLineupView(message.guildId);
|
| 507 |
+
await message.channel.send(view);
|
| 508 |
addToCleanupQueue(message.guildId, message.channelId, msg.id, 'poll');
|
| 509 |
} else {
|
| 510 |
msg.edit({ content: content + `\n\n❌ Canceled: not enough players joined.` });
|
| 511 |
}
|
| 512 |
+
// Clean up
|
| 513 |
+
delete storage.data.active_polls[message.guildId];
|
| 514 |
+
pollNeededCount.delete(message.guildId);
|
| 515 |
+
storage.save('active_polls');
|
| 516 |
});
|
| 517 |
addToCleanupQueue(message.guildId, message.channelId, msg.id, 'poll');
|
| 518 |
}
|
| 519 |
|
| 520 |
if (commandName === 'lineup') {
|
| 521 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
|
| 522 |
+
|
| 523 |
const mentionArg = args[0] ? args[0].toLowerCase().replace('@', '') : null;
|
| 524 |
const pingType = mentionArg === 'here' ? 'here' : 'everyone';
|
| 525 |
guildPingType.set(message.guildId, pingType);
|
| 526 |
+
|
| 527 |
lineupOwners.set(message.guildId, message.author.id);
|
| 528 |
saveLineup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
|
| 530 |
+
// Clear lineup before showing to ensure no names in it
|
| 531 |
+
const lineup = getGuildLineup(message.guildId);
|
| 532 |
+
lineup.clear();
|
| 533 |
+
saveLineup();
|
| 534 |
+
|
| 535 |
+
// Show lineup immediately without waiting for reactions
|
| 536 |
+
console.log(`[DEBUG] LINEUP-MSG: guild=${message.guildId} pingType=${pingType} owner=${message.author?.id || 'unknown'}`);
|
| 537 |
+
const view = createLineupView(message.guildId);
|
| 538 |
+
const msg = await message.channel.send(view);
|
| 539 |
+
activeLineupMessages.set(message.guildId, { channelId: message.channelId, messageId: msg.id });
|
| 540 |
+
addToCleanupQueue(message.guildId, message.channelId, msg.id, 'lineup');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
}
|
| 542 |
|
| 543 |
if (commandName === 'top') {
|
|
|
|
| 1846 |
}
|
| 1847 |
});
|
| 1848 |
|
| 1849 |
+
// Store needed count for each active poll
|
| 1850 |
+
const pollNeededCount = new Map();
|
| 1851 |
+
|
| 1852 |
// Global Reaction Handler (Triggers Lineup)
|
| 1853 |
client.on('messageReactionAdd', async (reaction, user) => {
|
| 1854 |
if (user.bot) return;
|
|
|
|
| 1859 |
const activePollId = storage.data.active_polls[guildId];
|
| 1860 |
|
| 1861 |
if (reaction.message.id === activePollId) {
|
| 1862 |
+
const needed = pollNeededCount.get(guildId) || 6;
|
| 1863 |
const count = reaction.count - (reaction.me ? 1 : 0);
|
| 1864 |
|
| 1865 |
if (count >= needed) {
|
| 1866 |
const embed = UI.createEmbed(`${UI.icons.success} Friendly Ready!`, `We have **${count}** players! Starting lineup board...`, UI.colors.success);
|
| 1867 |
await reaction.message.channel.send({ embeds: [embed] });
|
| 1868 |
|
| 1869 |
+
// Clear lineup before showing
|
| 1870 |
+
const lineup = getGuildLineup(guildId);
|
| 1871 |
+
lineup.clear();
|
| 1872 |
+
saveLineup();
|
| 1873 |
+
|
| 1874 |
+
// Show interactive lineup board (new message, not editing old one)
|
| 1875 |
const boardMsg = await reaction.message.channel.send(createLineupView(guildId));
|
| 1876 |
activeLineupMessages.set(guildId, { channelId: reaction.message.channelId, messageId: boardMsg.id });
|
| 1877 |
addToCleanupQueue(guildId, reaction.message.channelId, boardMsg.id, 'lineup');
|
| 1878 |
|
| 1879 |
delete storage.data.active_polls[guildId];
|
| 1880 |
+
pollNeededCount.delete(guildId);
|
| 1881 |
storage.save('active_polls');
|
| 1882 |
}
|
| 1883 |
}
|
| 1884 |
}
|
| 1885 |
});
|
| 1886 |
|
| 1887 |
+
// Handle reaction removal to decrease count
|
| 1888 |
+
client.on('messageReactionRemove', async (reaction, user) => {
|
| 1889 |
+
if (user.bot) return;
|
| 1890 |
+
if (reaction.partial) await reaction.fetch();
|
| 1891 |
+
|
| 1892 |
+
if (reaction.emoji.name === '🟩') {
|
| 1893 |
+
const guildId = reaction.message.guildId;
|
| 1894 |
+
const activePollId = storage.data.active_polls[guildId];
|
| 1895 |
+
|
| 1896 |
+
if (reaction.message.id === activePollId) {
|
| 1897 |
+
const count = reaction.count - (reaction.me ? 1 : 0);
|
| 1898 |
+
const needed = pollNeededCount.get(guildId) || 6;
|
| 1899 |
+
|
| 1900 |
+
// Update the message with current count
|
| 1901 |
+
const content = getFriendlyText(guildId, needed);
|
| 1902 |
+
await reaction.message.edit({ content: content + `\n\n${count}/${needed} players joined. Waiting for more...` });
|
| 1903 |
+
}
|
| 1904 |
+
}
|
| 1905 |
+
});
|
| 1906 |
+
|
| 1907 |
// Staff Onboarding System
|
| 1908 |
client.on('guildMemberUpdate', async (oldMember, newMember) => {
|
| 1909 |
try {
|