Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -102,6 +102,54 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 102 |
}
|
| 103 |
});
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
// Start the health server
|
| 106 |
server.startServer();
|
| 107 |
|
|
@@ -109,6 +157,5 @@ server.startServer();
|
|
| 109 |
client.on('error', (e) => console.error(`[!] Discord Client Error: ${e}`));
|
| 110 |
|
| 111 |
client.login(TOKEN).catch(e => {
|
| 112 |
-
console.error(`[!] Login Failed:
|
| 113 |
-
process.exit(1);
|
| 114 |
});
|
|
|
|
| 102 |
}
|
| 103 |
});
|
| 104 |
|
| 105 |
+
// --- 4. LINEUP LOGIC ---
|
| 106 |
+
const POSITIONS = ['GK', 'LB', 'CB', 'RB', 'LCM', 'RCM', 'ST'];
|
| 107 |
+
const guildLineups = new Map();
|
| 108 |
+
|
| 109 |
+
function getGuildLineup(guildId) {
|
| 110 |
+
if (!guildLineups.has(guildId)) {
|
| 111 |
+
guildLineups.set(guildId, new Map(POSITIONS.map(p => [p, []])));
|
| 112 |
+
}
|
| 113 |
+
return guildLineups.get(guildId);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
function formatLineup(guildId) {
|
| 117 |
+
const lineup = getGuildLineup(guildId);
|
| 118 |
+
let text = "";
|
| 119 |
+
for (const pos of POSITIONS) {
|
| 120 |
+
const players = lineup.get(pos);
|
| 121 |
+
text += `**${pos}**: ${players.length > 0 ? players.map(p => `<@${p}>`).join(', ') : "_Empty_"}\n`;
|
| 122 |
+
}
|
| 123 |
+
return text;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// Global Reaction Handler
|
| 127 |
+
client.on('messageReactionAdd', async (reaction, user) => {
|
| 128 |
+
if (user.bot) return;
|
| 129 |
+
if (reaction.partial) await reaction.fetch();
|
| 130 |
+
|
| 131 |
+
if (reaction.emoji.name === '🟩') {
|
| 132 |
+
const guildId = reaction.message.guildId;
|
| 133 |
+
const activePollId = storage.data.active_polls[guildId];
|
| 134 |
+
|
| 135 |
+
if (reaction.message.id === activePollId) {
|
| 136 |
+
const needed = 6;
|
| 137 |
+
const count = reaction.count - (reaction.me ? 1 : 0);
|
| 138 |
+
|
| 139 |
+
if (count >= needed) {
|
| 140 |
+
const embed = UI.createEmbed(`${UI.icons.success} Friendly Ready!`, `We have **${count}** players! Starting lineup board...`, UI.colors.success);
|
| 141 |
+
await reaction.message.channel.send({ embeds: [embed] });
|
| 142 |
+
|
| 143 |
+
const lineupEmbed = UI.createEmbed("📋 Match Lineup", formatLineup(guildId));
|
| 144 |
+
await reaction.message.channel.send({ embeds: [lineupEmbed] });
|
| 145 |
+
|
| 146 |
+
delete storage.data.active_polls[guildId];
|
| 147 |
+
storage.save('polls');
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
});
|
| 152 |
+
|
| 153 |
// Start the health server
|
| 154 |
server.startServer();
|
| 155 |
|
|
|
|
| 157 |
client.on('error', (e) => console.error(`[!] Discord Client Error: ${e}`));
|
| 158 |
|
| 159 |
client.login(TOKEN).catch(e => {
|
| 160 |
+
console.error(`[!] Login Failed: Check your BOT_TOKEN in .env or HF Secrets.`);
|
|
|
|
| 161 |
});
|