Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -38,9 +38,11 @@ console.log(">>> [BOOT] Loading Graphics Renderers...");
|
|
| 38 |
try {
|
| 39 |
const { createLineupAttachment } = require('./lineupRenderer');
|
| 40 |
const { createProfileAttachment } = require('./profileRenderer');
|
|
|
|
| 41 |
global.createLineupAttachment = createLineupAttachment;
|
| 42 |
global.createProfileAttachment = createProfileAttachment;
|
| 43 |
-
|
|
|
|
| 44 |
} catch (err) {
|
| 45 |
console.error(">>> [BOOT] ERROR LOADING GRAPHICS:", err.message);
|
| 46 |
}
|
|
@@ -342,6 +344,7 @@ client.on('messageCreate', async (message) => {
|
|
| 342 |
if (commandName === 'lineup') {
|
| 343 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 344 |
lineupOwners.set(message.guildId, message.author.id);
|
|
|
|
| 345 |
const formOptions = Object.keys(FORMATIONS).slice(0, 25).map(k => ({ label: k, value: k }));
|
| 346 |
const row = new ActionRowBuilder().addComponents(
|
| 347 |
new StringSelectMenuBuilder()
|
|
@@ -491,6 +494,7 @@ client.on('messageCreate', async (message) => {
|
|
| 491 |
const arr2 = lineup.get(pos2);
|
| 492 |
arr1[idx1] = p2.id;
|
| 493 |
arr2[idx2] = p1.id;
|
|
|
|
| 494 |
|
| 495 |
await message.reply(`✅ Swapped <@${p1.id}> with <@${p2.id}>!`);
|
| 496 |
|
|
@@ -914,6 +918,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 914 |
if (interaction.commandName === 'lineup') {
|
| 915 |
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return safeReply(interaction, { content: "❌ No Permission", flags: [MessageFlags.Ephemeral] });
|
| 916 |
lineupOwners.set(interaction.guildId, interaction.user.id);
|
|
|
|
| 917 |
const formOptions = Object.keys(FORMATIONS).slice(0, 25).map(k => ({ label: k, value: k }));
|
| 918 |
const row = new ActionRowBuilder().addComponents(
|
| 919 |
new StringSelectMenuBuilder()
|
|
@@ -969,6 +974,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 969 |
const arr2 = lineup.get(pos2);
|
| 970 |
arr1[idx1] = p2.id;
|
| 971 |
arr2[idx2] = p1.id;
|
|
|
|
| 972 |
|
| 973 |
await safeReply(interaction, { content: `✅ Swapped <@${p1.id}> with <@${p2.id}>!`, flags: [MessageFlags.Ephemeral] });
|
| 974 |
|
|
@@ -1155,6 +1161,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1155 |
guildLineups.set(guildId, map);
|
| 1156 |
await interaction.update(createLineupView(guildId));
|
| 1157 |
activeLineupMessages.set(guildId, { channelId: interaction.channelId, messageId: interaction.message.id });
|
|
|
|
| 1158 |
return;
|
| 1159 |
}
|
| 1160 |
|
|
@@ -1171,6 +1178,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1171 |
const map = new Map();
|
| 1172 |
guildLineups.set(guildId, map);
|
| 1173 |
await interaction.update(createLineupView(guildId));
|
|
|
|
| 1174 |
return;
|
| 1175 |
}
|
| 1176 |
|
|
@@ -1184,6 +1192,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1184 |
await interaction.update(editor);
|
| 1185 |
|
| 1186 |
managerBoards.set(guildId, { channelId: interaction.channelId, messageId: interaction.message.id });
|
|
|
|
| 1187 |
return;
|
| 1188 |
}
|
| 1189 |
|
|
@@ -1194,6 +1203,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1194 |
|
| 1195 |
const lineup = getGuildLineup(guildId);
|
| 1196 |
lineup.set(posKey, [targetUser]);
|
|
|
|
| 1197 |
|
| 1198 |
await interaction.update({ content: `✅ Assigned <@${targetUser}> to **${posKey}**`, components: [] });
|
| 1199 |
|
|
@@ -1241,6 +1251,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1241 |
if (!lineupBoard.get(pos)) lineupBoard.set(pos, []);
|
| 1242 |
lineupBoard.get(pos).push(userId);
|
| 1243 |
}
|
|
|
|
| 1244 |
await interaction.editReply(createLineupView(lineupGuildId));
|
| 1245 |
return;
|
| 1246 |
}
|
|
@@ -1254,6 +1265,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1254 |
}
|
| 1255 |
|
| 1256 |
lineupBoard.clear();
|
|
|
|
| 1257 |
await interaction.update(createLineupView(lineupGuildId));
|
| 1258 |
return;
|
| 1259 |
}
|
|
@@ -1447,13 +1459,13 @@ const FORMATIONS = {
|
|
| 1447 |
"2-3-2": [["GK", "GK"], ["CB1", "CB"], ["CB2", "CB"], ["CM", "CM"], ["CAM", "CAM"], ["ST1", "ST"], ["ST2", "ST"]]
|
| 1448 |
};
|
| 1449 |
|
| 1450 |
-
|
| 1451 |
-
const guildSelectedFormation = new Map();
|
| 1452 |
-
const lineupOwners = new Map();
|
| 1453 |
-
const activeLineupMessages = new Map();
|
| 1454 |
|
| 1455 |
function getGuildLineup(guildId) {
|
| 1456 |
-
if (!guildLineups.get(guildId))
|
|
|
|
|
|
|
|
|
|
| 1457 |
return guildLineups.get(guildId);
|
| 1458 |
}
|
| 1459 |
|
|
@@ -1527,8 +1539,6 @@ function createLineupView(guildId) {
|
|
| 1527 |
return { content: "@everyone\n**Lineup Session Active!**", embeds: [embed], components: rows, allowedMentions: { parse: ['everyone'] } };
|
| 1528 |
}
|
| 1529 |
|
| 1530 |
-
// --- 5. MANAGER GUI LOGIC ---
|
| 1531 |
-
const managerBoards = new Map();
|
| 1532 |
|
| 1533 |
function createManagerEditor(guildId, client) {
|
| 1534 |
const lineup = getGuildLineup(guildId);
|
|
|
|
| 38 |
try {
|
| 39 |
const { createLineupAttachment } = require('./lineupRenderer');
|
| 40 |
const { createProfileAttachment } = require('./profileRenderer');
|
| 41 |
+
const { guildLineups, guildSelectedFormation, lineupOwners, activeLineupMessages, managerBoards, save: saveLineup } = require('./lineup_persistence');
|
| 42 |
global.createLineupAttachment = createLineupAttachment;
|
| 43 |
global.createProfileAttachment = createProfileAttachment;
|
| 44 |
+
global.saveLineup = saveLineup;
|
| 45 |
+
console.log(">>> [BOOT] Graphics Renderers & Persistence loaded.");
|
| 46 |
} catch (err) {
|
| 47 |
console.error(">>> [BOOT] ERROR LOADING GRAPHICS:", err.message);
|
| 48 |
}
|
|
|
|
| 344 |
if (commandName === 'lineup') {
|
| 345 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 346 |
lineupOwners.set(message.guildId, message.author.id);
|
| 347 |
+
saveLineup();
|
| 348 |
const formOptions = Object.keys(FORMATIONS).slice(0, 25).map(k => ({ label: k, value: k }));
|
| 349 |
const row = new ActionRowBuilder().addComponents(
|
| 350 |
new StringSelectMenuBuilder()
|
|
|
|
| 494 |
const arr2 = lineup.get(pos2);
|
| 495 |
arr1[idx1] = p2.id;
|
| 496 |
arr2[idx2] = p1.id;
|
| 497 |
+
saveLineup();
|
| 498 |
|
| 499 |
await message.reply(`✅ Swapped <@${p1.id}> with <@${p2.id}>!`);
|
| 500 |
|
|
|
|
| 918 |
if (interaction.commandName === 'lineup') {
|
| 919 |
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return safeReply(interaction, { content: "❌ No Permission", flags: [MessageFlags.Ephemeral] });
|
| 920 |
lineupOwners.set(interaction.guildId, interaction.user.id);
|
| 921 |
+
saveLineup();
|
| 922 |
const formOptions = Object.keys(FORMATIONS).slice(0, 25).map(k => ({ label: k, value: k }));
|
| 923 |
const row = new ActionRowBuilder().addComponents(
|
| 924 |
new StringSelectMenuBuilder()
|
|
|
|
| 974 |
const arr2 = lineup.get(pos2);
|
| 975 |
arr1[idx1] = p2.id;
|
| 976 |
arr2[idx2] = p1.id;
|
| 977 |
+
saveLineup();
|
| 978 |
|
| 979 |
await safeReply(interaction, { content: `✅ Swapped <@${p1.id}> with <@${p2.id}>!`, flags: [MessageFlags.Ephemeral] });
|
| 980 |
|
|
|
|
| 1161 |
guildLineups.set(guildId, map);
|
| 1162 |
await interaction.update(createLineupView(guildId));
|
| 1163 |
activeLineupMessages.set(guildId, { channelId: interaction.channelId, messageId: interaction.message.id });
|
| 1164 |
+
saveLineup();
|
| 1165 |
return;
|
| 1166 |
}
|
| 1167 |
|
|
|
|
| 1178 |
const map = new Map();
|
| 1179 |
guildLineups.set(guildId, map);
|
| 1180 |
await interaction.update(createLineupView(guildId));
|
| 1181 |
+
saveLineup();
|
| 1182 |
return;
|
| 1183 |
}
|
| 1184 |
|
|
|
|
| 1192 |
await interaction.update(editor);
|
| 1193 |
|
| 1194 |
managerBoards.set(guildId, { channelId: interaction.channelId, messageId: interaction.message.id });
|
| 1195 |
+
saveLineup();
|
| 1196 |
return;
|
| 1197 |
}
|
| 1198 |
|
|
|
|
| 1203 |
|
| 1204 |
const lineup = getGuildLineup(guildId);
|
| 1205 |
lineup.set(posKey, [targetUser]);
|
| 1206 |
+
saveLineup();
|
| 1207 |
|
| 1208 |
await interaction.update({ content: `✅ Assigned <@${targetUser}> to **${posKey}**`, components: [] });
|
| 1209 |
|
|
|
|
| 1251 |
if (!lineupBoard.get(pos)) lineupBoard.set(pos, []);
|
| 1252 |
lineupBoard.get(pos).push(userId);
|
| 1253 |
}
|
| 1254 |
+
saveLineup();
|
| 1255 |
await interaction.editReply(createLineupView(lineupGuildId));
|
| 1256 |
return;
|
| 1257 |
}
|
|
|
|
| 1265 |
}
|
| 1266 |
|
| 1267 |
lineupBoard.clear();
|
| 1268 |
+
saveLineup();
|
| 1269 |
await interaction.update(createLineupView(lineupGuildId));
|
| 1270 |
return;
|
| 1271 |
}
|
|
|
|
| 1459 |
"2-3-2": [["GK", "GK"], ["CB1", "CB"], ["CB2", "CB"], ["CM", "CM"], ["CAM", "CAM"], ["ST1", "ST"], ["ST2", "ST"]]
|
| 1460 |
};
|
| 1461 |
|
| 1462 |
+
// Persistence is now handled by lineup_persistence.js
|
|
|
|
|
|
|
|
|
|
| 1463 |
|
| 1464 |
function getGuildLineup(guildId) {
|
| 1465 |
+
if (!guildLineups.get(guildId)) {
|
| 1466 |
+
guildLineups.set(guildId, new Map());
|
| 1467 |
+
saveLineup();
|
| 1468 |
+
}
|
| 1469 |
return guildLineups.get(guildId);
|
| 1470 |
}
|
| 1471 |
|
|
|
|
| 1539 |
return { content: "@everyone\n**Lineup Session Active!**", embeds: [embed], components: rows, allowedMentions: { parse: ['everyone'] } };
|
| 1540 |
}
|
| 1541 |
|
|
|
|
|
|
|
| 1542 |
|
| 1543 |
function createManagerEditor(guildId, client) {
|
| 1544 |
const lineup = getGuildLineup(guildId);
|