Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -1398,13 +1398,56 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1398 |
return interaction.reply({ content: `❌ Only <@${ownerId}> can manage this lineup!`, ephemeral: true });
|
| 1399 |
}
|
| 1400 |
|
| 1401 |
-
await interaction.deferUpdate();
|
| 1402 |
const cat = interaction.values[0];
|
| 1403 |
const guildId = interaction.guildId;
|
| 1404 |
|
| 1405 |
-
|
| 1406 |
-
|
| 1407 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1408 |
return;
|
| 1409 |
}
|
| 1410 |
|
|
@@ -1978,43 +2021,19 @@ function createLineupView(guildId) {
|
|
| 1978 |
const rows = [];
|
| 1979 |
|
| 1980 |
// In the active board, we condense the 3 dropdowns into 2 rows to fit within Discord's 5-row limit
|
| 1981 |
-
//
|
| 1982 |
const categoryRow = new ActionRowBuilder().addComponents(
|
| 1983 |
new StringSelectMenuBuilder()
|
| 1984 |
.setCustomId('formation_category_select')
|
| 1985 |
-
.setPlaceholder('
|
| 1986 |
.addOptions([
|
| 1987 |
-
{ label: '⚽ 7v7 Formations', value: 'cat_7v7' },
|
| 1988 |
-
{ label: '🏆 11v11 Formations', value: 'cat_11v11' },
|
| 1989 |
-
{ label: '🎮 Other Sizes (6v6, 8v8, 9v9, 10v10)', value: 'cat_other' }
|
| 1990 |
])
|
| 1991 |
);
|
| 1992 |
rows.push(categoryRow);
|
| 1993 |
|
| 1994 |
-
// Row 2: Formations in current category (or category selected in session)
|
| 1995 |
-
const activeCat = guildActiveCategory.get(guildId) || (formation.length === 7 ? 'cat_7v7' : (formation.length === 11 ? 'cat_11v11' : 'cat_other'));
|
| 1996 |
-
|
| 1997 |
-
let filteredKeys = [];
|
| 1998 |
-
let catLabel = "";
|
| 1999 |
-
if (activeCat === 'cat_7v7') {
|
| 2000 |
-
filteredKeys = Object.keys(FORMATIONS).filter(k => FORMATIONS[k].length === 7);
|
| 2001 |
-
catLabel = "7v7";
|
| 2002 |
-
} else if (activeCat === 'cat_11v11') {
|
| 2003 |
-
filteredKeys = Object.keys(FORMATIONS).filter(k => FORMATIONS[k].length === 11);
|
| 2004 |
-
catLabel = "11v11";
|
| 2005 |
-
} else {
|
| 2006 |
-
filteredKeys = Object.keys(FORMATIONS).filter(k => FORMATIONS[k].length !== 7 && FORMATIONS[k].length !== 11);
|
| 2007 |
-
catLabel = "Other Sizes";
|
| 2008 |
-
}
|
| 2009 |
-
|
| 2010 |
-
const formRow = new ActionRowBuilder().addComponents(
|
| 2011 |
-
new StringSelectMenuBuilder()
|
| 2012 |
-
.setCustomId('formation_select_active')
|
| 2013 |
-
.setPlaceholder(`⚽ Select ${catLabel} Formation...`)
|
| 2014 |
-
.addOptions(filteredKeys.slice(0, 25).map(k => ({ label: k, value: k })))
|
| 2015 |
-
);
|
| 2016 |
-
rows.push(formRow);
|
| 2017 |
-
|
| 2018 |
// Position Buttons
|
| 2019 |
let currentRow = new ActionRowBuilder();
|
| 2020 |
let currentPosCount = 0;
|
|
|
|
| 1398 |
return interaction.reply({ content: `❌ Only <@${ownerId}> can manage this lineup!`, ephemeral: true });
|
| 1399 |
}
|
| 1400 |
|
|
|
|
| 1401 |
const cat = interaction.values[0];
|
| 1402 |
const guildId = interaction.guildId;
|
| 1403 |
|
| 1404 |
+
let filteredKeys = [];
|
| 1405 |
+
let catLabel = "";
|
| 1406 |
+
if (cat === 'cat_7v7') {
|
| 1407 |
+
filteredKeys = Object.keys(FORMATIONS).filter(k => FORMATIONS[k].length === 7);
|
| 1408 |
+
catLabel = "7v7";
|
| 1409 |
+
} else if (cat === 'cat_11v11') {
|
| 1410 |
+
filteredKeys = Object.keys(FORMATIONS).filter(k => FORMATIONS[k].length === 11);
|
| 1411 |
+
catLabel = "11v11";
|
| 1412 |
+
} else {
|
| 1413 |
+
filteredKeys = Object.keys(FORMATIONS).filter(k => FORMATIONS[k].length !== 7 && FORMATIONS[k].length !== 11);
|
| 1414 |
+
catLabel = "Other Sizes";
|
| 1415 |
+
}
|
| 1416 |
+
|
| 1417 |
+
const row = new ActionRowBuilder().addComponents(
|
| 1418 |
+
new StringSelectMenuBuilder()
|
| 1419 |
+
.setCustomId(`formation_select_ephemeral_${interaction.message.id}`)
|
| 1420 |
+
.setPlaceholder(`⚽ Pick a ${catLabel} Formation...`)
|
| 1421 |
+
.addOptions(filteredKeys.slice(0, 25).map(k => ({ label: k, value: k })))
|
| 1422 |
+
);
|
| 1423 |
+
|
| 1424 |
+
await interaction.reply({
|
| 1425 |
+
content: `📂 **Browsing ${catLabel} Formations**\nSelect an option below to update the public board.`,
|
| 1426 |
+
components: [row],
|
| 1427 |
+
flags: [MessageFlags.Ephemeral]
|
| 1428 |
+
});
|
| 1429 |
+
return;
|
| 1430 |
+
}
|
| 1431 |
+
|
| 1432 |
+
if (interaction.isStringSelectMenu() && interaction.customId.startsWith('formation_select_ephemeral_')) {
|
| 1433 |
+
const publicMessageId = interaction.customId.replace('formation_select_ephemeral_', '');
|
| 1434 |
+
const formKey = interaction.values[0];
|
| 1435 |
+
const guildId = interaction.guildId;
|
| 1436 |
+
|
| 1437 |
+
guildSelectedFormation.set(guildId, formKey);
|
| 1438 |
+
const map = new Map();
|
| 1439 |
+
guildLineups.set(guildId, map);
|
| 1440 |
+
saveLineup();
|
| 1441 |
+
|
| 1442 |
+
await interaction.update({ content: `✅ Updated public board to **${formKey}**!`, components: [] });
|
| 1443 |
+
|
| 1444 |
+
try {
|
| 1445 |
+
const channel = interaction.channel;
|
| 1446 |
+
const publicMsg = await channel.messages.fetch(publicMessageId);
|
| 1447 |
+
await publicMsg.edit(createLineupView(guildId));
|
| 1448 |
+
} catch (e) {
|
| 1449 |
+
console.error("[!] Failed to update public board from ephemeral menu:", e.message);
|
| 1450 |
+
}
|
| 1451 |
return;
|
| 1452 |
}
|
| 1453 |
|
|
|
|
| 2021 |
const rows = [];
|
| 2022 |
|
| 2023 |
// In the active board, we condense the 3 dropdowns into 2 rows to fit within Discord's 5-row limit
|
| 2024 |
+
// Condense UI: Only the Category Selection is on the public board
|
| 2025 |
const categoryRow = new ActionRowBuilder().addComponents(
|
| 2026 |
new StringSelectMenuBuilder()
|
| 2027 |
.setCustomId('formation_category_select')
|
| 2028 |
+
.setPlaceholder('📂 Change Formation Size (7v7, 11v11, others...)')
|
| 2029 |
.addOptions([
|
| 2030 |
+
{ label: '⚽ 7v7 Formations', value: 'cat_7v7', emoji: '⚽' },
|
| 2031 |
+
{ label: '🏆 11v11 Formations', value: 'cat_11v11', emoji: '🏆' },
|
| 2032 |
+
{ label: '🎮 Other Sizes (6v6, 8v8, 9v9, 10v10)', value: 'cat_other', emoji: '🎮' }
|
| 2033 |
])
|
| 2034 |
);
|
| 2035 |
rows.push(categoryRow);
|
| 2036 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2037 |
// Position Buttons
|
| 2038 |
let currentRow = new ActionRowBuilder();
|
| 2039 |
let currentPosCount = 0;
|