Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -34,7 +34,7 @@ console.log(">>> [BOOT] Loading Web Server module...");
|
|
| 34 |
const server = require('./server');
|
| 35 |
console.log(">>> [BOOT] Web Server module loaded.");
|
| 36 |
|
| 37 |
-
const { guildLineups, guildLineupsB, guildScrimMode,
|
| 38 |
const guildActiveCategory = new Map(); // Stores the currently selected category in the UI for each guild
|
| 39 |
|
| 40 |
try {
|
|
@@ -1890,7 +1890,12 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1890 |
return interaction.reply({ content: `❌ Only <@${ownerId}> can change the formation!`, ephemeral: true });
|
| 1891 |
}
|
| 1892 |
const guildId = interaction.guildId;
|
| 1893 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1894 |
const map = new Map();
|
| 1895 |
guildLineups.set(guildId, map);
|
| 1896 |
await interaction.update(createLineupView(guildId));
|
|
@@ -1901,14 +1906,19 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1901 |
if (interaction.isStringSelectMenu() && interaction.customId.startsWith('formation_select_')) {
|
| 1902 |
if (interaction.customId.includes('_initial_') || interaction.customId.includes('_active')) return;
|
| 1903 |
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return sendNoPermission(interaction);
|
| 1904 |
-
|
| 1905 |
const ownerId = lineupOwners.get(interaction.guildId);
|
| 1906 |
if (ownerId && interaction.user.id !== ownerId) {
|
| 1907 |
return interaction.reply({ content: `❌ Only <@${ownerId}> can change the formation!`, ephemeral: true });
|
| 1908 |
}
|
| 1909 |
-
|
| 1910 |
const guildId = interaction.guildId;
|
| 1911 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1912 |
const map = new Map();
|
| 1913 |
guildLineups.set(guildId, map);
|
| 1914 |
await interaction.update(createLineupView(guildId));
|
|
@@ -1918,13 +1928,18 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1918 |
|
| 1919 |
if (interaction.isStringSelectMenu() && interaction.customId.startsWith('manager_formation_select_')) {
|
| 1920 |
const guildId = interaction.guildId;
|
| 1921 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1922 |
const map = new Map();
|
| 1923 |
guildLineups.set(guildId, map);
|
| 1924 |
-
|
| 1925 |
const editor = createManagerEditor(guildId, client);
|
| 1926 |
await interaction.update(editor);
|
| 1927 |
-
|
| 1928 |
managerBoards.set(guildId, { channelId: interaction.channelId, messageId: interaction.message.id });
|
| 1929 |
saveLineup();
|
| 1930 |
return;
|
|
@@ -1970,19 +1985,19 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1970 |
|
| 1971 |
if (interaction.customId.startsWith('join_')) {
|
| 1972 |
await interaction.deferUpdate().catch(() => { });
|
| 1973 |
-
|
| 1974 |
const isScrim = guildScrimMode.get(lineupGuildId) === true;
|
| 1975 |
let targetLineup = lineupBoard;
|
| 1976 |
let pos = interaction.customId.replace('join_', '');
|
| 1977 |
-
|
| 1978 |
-
if (isScrim && pos.startsWith('
|
| 1979 |
-
pos = pos.replace('
|
| 1980 |
targetLineup = lineupBoard;
|
| 1981 |
-
} else if (isScrim && pos.startsWith('
|
| 1982 |
-
pos = pos.replace('
|
| 1983 |
targetLineup = getGuildLineupB(lineupGuildId);
|
| 1984 |
}
|
| 1985 |
-
|
| 1986 |
const userId = interaction.user.id;
|
| 1987 |
let wasInCurrentPos = false;
|
| 1988 |
const currentQ = targetLineup.get(pos) || [];
|
|
@@ -2041,42 +2056,52 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 2041 |
|
| 2042 |
await interaction.deferReply().catch(() => { });
|
| 2043 |
|
| 2044 |
-
|
| 2045 |
-
|
| 2046 |
-
|
| 2047 |
-
|
| 2048 |
-
|
| 2049 |
-
|
| 2050 |
-
|
| 2051 |
-
|
| 2052 |
-
|
| 2053 |
-
|
| 2054 |
-
|
| 2055 |
-
|
| 2056 |
-
|
| 2057 |
-
|
| 2058 |
-
|
| 2059 |
-
|
| 2060 |
-
|
| 2061 |
-
|
| 2062 |
-
|
| 2063 |
-
|
| 2064 |
-
|
| 2065 |
-
|
| 2066 |
-
|
| 2067 |
-
|
| 2068 |
-
|
| 2069 |
-
|
| 2070 |
-
|
| 2071 |
-
|
| 2072 |
-
|
| 2073 |
-
|
| 2074 |
-
|
| 2075 |
-
|
| 2076 |
-
|
| 2077 |
-
|
| 2078 |
-
|
| 2079 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2080 |
console.error("Failed to generate lineup image:", err);
|
| 2081 |
await interaction.editReply({ content: "❌ Failed to generate lineup image. Please try again." }).catch(() => { });
|
| 2082 |
}
|
|
@@ -2574,16 +2599,20 @@ function createLineupView(guildId) {
|
|
| 2574 |
function createScrimLineupView(guildId) {
|
| 2575 |
const lineupA = getGuildLineup(guildId);
|
| 2576 |
const lineupB = getGuildLineupB(guildId);
|
| 2577 |
-
const
|
| 2578 |
-
const
|
| 2579 |
-
const
|
| 2580 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2581 |
let textA = "";
|
| 2582 |
let textB = "";
|
| 2583 |
-
for (const [posKey, posLabel] of
|
| 2584 |
const resolvedLabel = resolveEmojis(posLabel, guildId);
|
| 2585 |
const playersA = lineupA.get(posKey) || [];
|
| 2586 |
-
const playersB = lineupB.get(posKey) || [];
|
| 2587 |
if (playersA.length > 0) {
|
| 2588 |
const starter = playersA[0];
|
| 2589 |
const subs = playersA.slice(1);
|
|
@@ -2591,6 +2620,10 @@ function createScrimLineupView(guildId) {
|
|
| 2591 |
if (subs.length > 0) line += ` (Sub: ` + subs.map(p => `<@${p}>`).join(', ') + `)`;
|
| 2592 |
textA += line + "\n\n";
|
| 2593 |
} else { textA += `⬛ **${resolvedLabel}** ➔ *Open*\n\n`; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2594 |
if (playersB.length > 0) {
|
| 2595 |
const starter = playersB[0];
|
| 2596 |
const subs = playersB.slice(1);
|
|
@@ -2599,28 +2632,52 @@ function createScrimLineupView(guildId) {
|
|
| 2599 |
textB += line + "\n\n";
|
| 2600 |
} else { textB += `⬛ **${resolvedLabel}** ➔ *Open*\n\n`; }
|
| 2601 |
}
|
| 2602 |
-
const embedA = UI.createEmbed(`🔵 TEAM A — ${resolveEmojis(
|
| 2603 |
-
embedA.setFooter({ text: "
|
| 2604 |
-
const embedB = UI.createEmbed(`🔴 TEAM B — ${resolveEmojis(
|
|
|
|
| 2605 |
const rows = [];
|
| 2606 |
-
|
| 2607 |
-
|
| 2608 |
-
|
| 2609 |
-
|
| 2610 |
-
|
| 2611 |
-
|
| 2612 |
-
|
| 2613 |
-
|
| 2614 |
-
|
| 2615 |
-
|
| 2616 |
-
|
| 2617 |
-
|
| 2618 |
-
.
|
| 2619 |
-
.
|
| 2620 |
-
|
| 2621 |
-
|
| 2622 |
-
|
| 2623 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2624 |
rows.push(new ActionRowBuilder().addComponents(
|
| 2625 |
new StringSelectMenuBuilder()
|
| 2626 |
.setCustomId('formation_category_select')
|
|
|
|
| 34 |
const server = require('./server');
|
| 35 |
console.log(">>> [BOOT] Web Server module loaded.");
|
| 36 |
|
| 37 |
+
const { guildLineups, guildLineupsB, guildScrimMode, guildSelectedFormationA, guildSelectedFormationB, lineupOwners, activeLineupMessages, managerBoards, guildCustomFormations, guildCustomFormationNames, guildPingType, guildFriendlyPingType, save: saveLineup } = require('./lineup_persistence');
|
| 38 |
const guildActiveCategory = new Map(); // Stores the currently selected category in the UI for each guild
|
| 39 |
|
| 40 |
try {
|
|
|
|
| 1890 |
return interaction.reply({ content: `❌ Only <@${ownerId}> can change the formation!`, ephemeral: true });
|
| 1891 |
}
|
| 1892 |
const guildId = interaction.guildId;
|
| 1893 |
+
if (guildScrimMode.get(guildId)) {
|
| 1894 |
+
guildSelectedFormationA.set(guildId, interaction.values[0]);
|
| 1895 |
+
guildSelectedFormationB.set(guildId, interaction.values[0]);
|
| 1896 |
+
} else {
|
| 1897 |
+
guildSelectedFormationA.set(guildId, interaction.values[0]);
|
| 1898 |
+
}
|
| 1899 |
const map = new Map();
|
| 1900 |
guildLineups.set(guildId, map);
|
| 1901 |
await interaction.update(createLineupView(guildId));
|
|
|
|
| 1906 |
if (interaction.isStringSelectMenu() && interaction.customId.startsWith('formation_select_')) {
|
| 1907 |
if (interaction.customId.includes('_initial_') || interaction.customId.includes('_active')) return;
|
| 1908 |
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return sendNoPermission(interaction);
|
| 1909 |
+
|
| 1910 |
const ownerId = lineupOwners.get(interaction.guildId);
|
| 1911 |
if (ownerId && interaction.user.id !== ownerId) {
|
| 1912 |
return interaction.reply({ content: `❌ Only <@${ownerId}> can change the formation!`, ephemeral: true });
|
| 1913 |
}
|
| 1914 |
+
|
| 1915 |
const guildId = interaction.guildId;
|
| 1916 |
+
if (guildScrimMode.get(guildId)) {
|
| 1917 |
+
guildSelectedFormationA.set(guildId, interaction.values[0]);
|
| 1918 |
+
guildSelectedFormationB.set(guildId, interaction.values[0]);
|
| 1919 |
+
} else {
|
| 1920 |
+
guildSelectedFormationA.set(guildId, interaction.values[0]);
|
| 1921 |
+
}
|
| 1922 |
const map = new Map();
|
| 1923 |
guildLineups.set(guildId, map);
|
| 1924 |
await interaction.update(createLineupView(guildId));
|
|
|
|
| 1928 |
|
| 1929 |
if (interaction.isStringSelectMenu() && interaction.customId.startsWith('manager_formation_select_')) {
|
| 1930 |
const guildId = interaction.guildId;
|
| 1931 |
+
if (guildScrimMode.get(guildId)) {
|
| 1932 |
+
guildSelectedFormationA.set(guildId, interaction.values[0]);
|
| 1933 |
+
guildSelectedFormationB.set(guildId, interaction.values[0]);
|
| 1934 |
+
} else {
|
| 1935 |
+
guildSelectedFormationA.set(guildId, interaction.values[0]);
|
| 1936 |
+
}
|
| 1937 |
const map = new Map();
|
| 1938 |
guildLineups.set(guildId, map);
|
| 1939 |
+
|
| 1940 |
const editor = createManagerEditor(guildId, client);
|
| 1941 |
await interaction.update(editor);
|
| 1942 |
+
|
| 1943 |
managerBoards.set(guildId, { channelId: interaction.channelId, messageId: interaction.message.id });
|
| 1944 |
saveLineup();
|
| 1945 |
return;
|
|
|
|
| 1985 |
|
| 1986 |
if (interaction.customId.startsWith('join_')) {
|
| 1987 |
await interaction.deferUpdate().catch(() => { });
|
| 1988 |
+
|
| 1989 |
const isScrim = guildScrimMode.get(lineupGuildId) === true;
|
| 1990 |
let targetLineup = lineupBoard;
|
| 1991 |
let pos = interaction.customId.replace('join_', '');
|
| 1992 |
+
|
| 1993 |
+
if (isScrim && pos.startsWith('scrim_join_a_')) {
|
| 1994 |
+
pos = pos.replace('scrim_join_a_', '');
|
| 1995 |
targetLineup = lineupBoard;
|
| 1996 |
+
} else if (isScrim && pos.startsWith('scrim_join_b_')) {
|
| 1997 |
+
pos = pos.replace('scrim_join_b_', '');
|
| 1998 |
targetLineup = getGuildLineupB(lineupGuildId);
|
| 1999 |
}
|
| 2000 |
+
|
| 2001 |
const userId = interaction.user.id;
|
| 2002 |
let wasInCurrentPos = false;
|
| 2003 |
const currentQ = targetLineup.get(pos) || [];
|
|
|
|
| 2056 |
|
| 2057 |
await interaction.deferReply().catch(() => { });
|
| 2058 |
|
| 2059 |
+
try {
|
| 2060 |
+
const isScrim = guildScrimMode.get(lineupGuildId) === true;
|
| 2061 |
+
|
| 2062 |
+
if (isScrim) {
|
| 2063 |
+
const formKeyA = guildSelectedFormationA.get(lineupGuildId) || 'default';
|
| 2064 |
+
const formationA = formKeyA === `custom_${lineupGuildId}` ? guildCustomFormations.get(lineupGuildId) : FORMATIONS[formKeyA];
|
| 2065 |
+
const formDisplayNameA = formKeyA === `custom_${lineupGuildId}` ? (guildCustomFormationNames.get(lineupGuildId) || "Custom") : formKeyA;
|
| 2066 |
+
const effFormationA = formationA || FORMATIONS["default"];
|
| 2067 |
+
|
| 2068 |
+
const formKeyB = guildSelectedFormationB.get(lineupGuildId) || 'default';
|
| 2069 |
+
const formationB = formKeyB === `custom_${lineupGuildId}` ? guildCustomFormations.get(lineupGuildId) : FORMATIONS[formKeyB];
|
| 2070 |
+
const formDisplayNameB = formKeyB === `custom_${lineupGuildId}` ? (guildCustomFormationNames.get(lineupGuildId) || "Custom") : formKeyB;
|
| 2071 |
+
const effFormationB = formationB || FORMATIONS["default"];
|
| 2072 |
+
|
| 2073 |
+
const teamABuffer = await renderLineupImage(lineupBoard, `TEAM A - ${formDisplayNameA}`, effFormationA, client);
|
| 2074 |
+
const lineupB = getGuildLineupB(lineupGuildId);
|
| 2075 |
+
const teamBBuffer = await renderLineupImage(lineupB, `TEAM B - ${formDisplayNameB}`, effFormationB, client, true);
|
| 2076 |
+
|
| 2077 |
+
const attA = new AttachmentBuilder(teamABuffer, { name: 'team_a.png' });
|
| 2078 |
+
const attB = new AttachmentBuilder(teamBBuffer, { name: 'team_b.png' });
|
| 2079 |
+
|
| 2080 |
+
const embedA = new EmbedBuilder()
|
| 2081 |
+
.setColor('#5865F2')
|
| 2082 |
+
.setTitle(`TEAM A — ${formDisplayNameA}`)
|
| 2083 |
+
.setDescription('Team A lineup (attacking upward)')
|
| 2084 |
+
.setImage('attachment://team_a.png');
|
| 2085 |
+
|
| 2086 |
+
const embedB = new EmbedBuilder()
|
| 2087 |
+
.setColor('#ff4444')
|
| 2088 |
+
.setTitle(`TEAM B — ${formDisplayNameB}`)
|
| 2089 |
+
.setDescription('Team B lineup (attacking downward, facing Team A)')
|
| 2090 |
+
.setImage('attachment://team_b.png');
|
| 2091 |
+
|
| 2092 |
+
await interaction.editReply({ embeds: [embedA, embedB], files: [attA, attB] });
|
| 2093 |
+
} else {
|
| 2094 |
+
const formKey = guildSelectedFormationA.get(lineupGuildId) || 'default';
|
| 2095 |
+
const formation = formKey === `custom_${lineupGuildId}` ? guildCustomFormations.get(lineupGuildId) : FORMATIONS[formKey];
|
| 2096 |
+
const formDisplayName = formKey === `custom_${lineupGuildId}` ? (guildCustomFormationNames.get(lineupGuildId) || "Custom") : formKey;
|
| 2097 |
+
const effFormation = formation || FORMATIONS["default"];
|
| 2098 |
+
|
| 2099 |
+
const attachment = await createLineupAttachment(lineupBoard, formDisplayName, effFormation, client);
|
| 2100 |
+
const embed = UI.createEmbed(`⚽ Final Lineup — ${formDisplayName}`, "Here is the visual representation of the starting lineup.");
|
| 2101 |
+
embed.setImage('attachment://lineup.png');
|
| 2102 |
+
await interaction.editReply({ embeds: [embed], files: [attachment] });
|
| 2103 |
+
}
|
| 2104 |
+
} catch (err) {
|
| 2105 |
console.error("Failed to generate lineup image:", err);
|
| 2106 |
await interaction.editReply({ content: "❌ Failed to generate lineup image. Please try again." }).catch(() => { });
|
| 2107 |
}
|
|
|
|
| 2599 |
function createScrimLineupView(guildId) {
|
| 2600 |
const lineupA = getGuildLineup(guildId);
|
| 2601 |
const lineupB = getGuildLineupB(guildId);
|
| 2602 |
+
const formKeyA = guildSelectedFormationA.get(guildId) || 'default';
|
| 2603 |
+
const formationA = formKeyA === `custom_${guildId}` ? guildCustomFormations.get(guildId) : FORMATIONS[formKeyA];
|
| 2604 |
+
const formDisplayNameA = formKeyA === `custom_${guildId}` ? (guildCustomFormationNames.get(guildId) || "Custom") : formKeyA;
|
| 2605 |
+
|
| 2606 |
+
const formKeyB = guildSelectedFormationB.get(guildId) || 'default';
|
| 2607 |
+
const formationB = formKeyB === `custom_${guildId}` ? guildCustomFormations.get(guildId) : FORMATIONS[formKeyB];
|
| 2608 |
+
const formDisplayNameB = formKeyB === `custom_${guildId}` ? (guildCustomFormationNames.get(guildId) || "Custom") : formKeyB;
|
| 2609 |
+
|
| 2610 |
+
if (!formationA || !formationB) return { content: "❌ Error: Formation not found." };
|
| 2611 |
let textA = "";
|
| 2612 |
let textB = "";
|
| 2613 |
+
for (const [posKey, posLabel] of formationA) {
|
| 2614 |
const resolvedLabel = resolveEmojis(posLabel, guildId);
|
| 2615 |
const playersA = lineupA.get(posKey) || [];
|
|
|
|
| 2616 |
if (playersA.length > 0) {
|
| 2617 |
const starter = playersA[0];
|
| 2618 |
const subs = playersA.slice(1);
|
|
|
|
| 2620 |
if (subs.length > 0) line += ` (Sub: ` + subs.map(p => `<@${p}>`).join(', ') + `)`;
|
| 2621 |
textA += line + "\n\n";
|
| 2622 |
} else { textA += `⬛ **${resolvedLabel}** ➔ *Open*\n\n`; }
|
| 2623 |
+
}
|
| 2624 |
+
for (const [posKey, posLabel] of formationB) {
|
| 2625 |
+
const resolvedLabel = resolveEmojis(posLabel, guildId);
|
| 2626 |
+
const playersB = lineupB.get(posKey) || [];
|
| 2627 |
if (playersB.length > 0) {
|
| 2628 |
const starter = playersB[0];
|
| 2629 |
const subs = playersB.slice(1);
|
|
|
|
| 2632 |
textB += line + "\n\n";
|
| 2633 |
} else { textB += `⬛ **${resolvedLabel}** ➔ *Open*\n\n`; }
|
| 2634 |
}
|
| 2635 |
+
const embedA = UI.createEmbed(`🔵 TEAM A — ${resolveEmojis(formDisplayNameA, guildId)}`, textA, UI.colors.primary);
|
| 2636 |
+
embedA.setFooter({ text: "Click buttons below to join Team A" });
|
| 2637 |
+
const embedB = UI.createEmbed(`🔴 TEAM B — ${resolveEmojis(formDisplayNameB, guildId)}`, textB, 0xff4444);
|
| 2638 |
+
embedB.setFooter({ text: "Click buttons below to join Team B" });
|
| 2639 |
const rows = [];
|
| 2640 |
+
|
| 2641 |
+
// Team A Buttons
|
| 2642 |
+
let rowA = new ActionRowBuilder();
|
| 2643 |
+
let countA = 0;
|
| 2644 |
+
formationA.forEach(([pk, pl]) => {
|
| 2645 |
+
if (countA === 5) {
|
| 2646 |
+
rows.push(rowA);
|
| 2647 |
+
rowA = new ActionRowBuilder();
|
| 2648 |
+
countA = 0;
|
| 2649 |
+
}
|
| 2650 |
+
const pA = lineupA.get(pk) || [];
|
| 2651 |
+
const btn = new ButtonBuilder()
|
| 2652 |
+
.setCustomId(`scrim_join_a_${pk}`)
|
| 2653 |
+
.setLabel(pA.length > 0 ? `${pl}: ✅` : pl)
|
| 2654 |
+
.setStyle(pA.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Primary);
|
| 2655 |
+
if (pA.length > 0) btn.setEmoji("✅");
|
| 2656 |
+
rowA.addComponents(btn);
|
| 2657 |
+
countA++;
|
| 2658 |
+
});
|
| 2659 |
+
if (countA > 0) rows.push(rowA);
|
| 2660 |
+
|
| 2661 |
+
// Team B Buttons
|
| 2662 |
+
let rowB = new ActionRowBuilder();
|
| 2663 |
+
let countB = 0;
|
| 2664 |
+
formationB.forEach(([pk, pl]) => {
|
| 2665 |
+
if (countB === 5) {
|
| 2666 |
+
rows.push(rowB);
|
| 2667 |
+
rowB = new ActionRowBuilder();
|
| 2668 |
+
countB = 0;
|
| 2669 |
+
}
|
| 2670 |
+
const pB = lineupB.get(pk) || [];
|
| 2671 |
+
const btn = new ButtonBuilder()
|
| 2672 |
+
.setCustomId(`scrim_join_b_${pk}`)
|
| 2673 |
+
.setLabel(pB.length > 0 ? `${pl}: ✅` : pl)
|
| 2674 |
+
.setStyle(pB.length > 0 ? ButtonStyle.Secondary : ButtonStyle.Primary);
|
| 2675 |
+
if (pB.length > 0) btn.setEmoji("✅");
|
| 2676 |
+
rowB.addComponents(btn);
|
| 2677 |
+
countB++;
|
| 2678 |
+
});
|
| 2679 |
+
if (countB > 0) rows.push(rowB);
|
| 2680 |
+
|
| 2681 |
rows.push(new ActionRowBuilder().addComponents(
|
| 2682 |
new StringSelectMenuBuilder()
|
| 2683 |
.setCustomId('formation_category_select')
|