Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -418,15 +418,26 @@ client.on('messageCreate', async (message) => {
|
|
| 418 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
|
| 419 |
lineupOwners.set(message.guildId, message.author.id);
|
| 420 |
saveLineup();
|
| 421 |
-
|
| 422 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
new StringSelectMenuBuilder()
|
| 424 |
.setCustomId('formation_select_initial')
|
| 425 |
-
.setPlaceholder('Step 1: Select Formation...')
|
| 426 |
.addOptions(formOptions)
|
| 427 |
);
|
| 428 |
-
const
|
| 429 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
addToCleanupQueue(message.guildId, message.channelId, msg.id, 'poll');
|
| 431 |
}
|
| 432 |
|
|
@@ -837,11 +848,13 @@ Tip: All commands support Discord Slash Commands (/) for a better experience!`;
|
|
| 837 |
|
| 838 |
if (commandName === 'managerlineup') {
|
| 839 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
|
| 840 |
-
const formOptions = Object.
|
|
|
|
|
|
|
| 841 |
const row = new ActionRowBuilder().addComponents(
|
| 842 |
new StringSelectMenuBuilder()
|
| 843 |
.setCustomId('manager_formation_select')
|
| 844 |
-
.setPlaceholder('Step 1: Select Formation...')
|
| 845 |
.addOptions(formOptions)
|
| 846 |
);
|
| 847 |
await message.channel.send({ content: "📋 **Step 1: Choose Formation for GUI Editor**", components: [row] });
|
|
@@ -1007,15 +1020,26 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1007 |
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return sendNoPermission(interaction);
|
| 1008 |
lineupOwners.set(interaction.guildId, interaction.user.id);
|
| 1009 |
saveLineup();
|
| 1010 |
-
|
| 1011 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1012 |
new StringSelectMenuBuilder()
|
| 1013 |
.setCustomId('formation_select_initial')
|
| 1014 |
-
.setPlaceholder('Step 1: Select Formation...')
|
| 1015 |
.addOptions(formOptions)
|
| 1016 |
);
|
| 1017 |
-
const
|
| 1018 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1019 |
}
|
| 1020 |
|
| 1021 |
if (interaction.commandName === 'clear') {
|
|
@@ -1110,11 +1134,13 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1110 |
|
| 1111 |
if (interaction.commandName === 'managerlineup') {
|
| 1112 |
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", flags: [MessageFlags.Ephemeral] });
|
| 1113 |
-
const formOptions = Object.
|
|
|
|
|
|
|
| 1114 |
const row = new ActionRowBuilder().addComponents(
|
| 1115 |
new StringSelectMenuBuilder()
|
| 1116 |
.setCustomId('manager_formation_select')
|
| 1117 |
-
.setPlaceholder('Step 1: Select Formation...')
|
| 1118 |
.addOptions(formOptions)
|
| 1119 |
);
|
| 1120 |
await safeReply(interaction, { content: "📋 **Step 1: Choose Formation for GUI Editor**", components: [row] });
|
|
@@ -1197,6 +1223,33 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1197 |
}
|
| 1198 |
|
| 1199 |
if (interaction.isButton()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1200 |
if (interaction.customId === 'toggle_auto_friendly') {
|
| 1201 |
if (!interaction.member.permissions.has('Administrator')) return safeReply(interaction, { content: "❌ Admin Only", ephemeral: true });
|
| 1202 |
const config = storage.data.config[interaction.guildId] || {};
|
|
@@ -1223,6 +1276,60 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 1223 |
}
|
| 1224 |
|
| 1225 |
if (interaction.isModalSubmit()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1226 |
if (interaction.customId === 'auto_friendly_interval_modal') {
|
| 1227 |
const interval = parseInt(interaction.fields.getTextInputValue('interval_input'));
|
| 1228 |
if (isNaN(interval) || interval < 1) {
|
|
@@ -1746,12 +1853,28 @@ function createLineupView(guildId) {
|
|
| 1746 |
|
| 1747 |
const rows = [];
|
| 1748 |
|
| 1749 |
-
// Formation Dropdown
|
| 1750 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1751 |
rows.push(new ActionRowBuilder().addComponents(
|
| 1752 |
new StringSelectMenuBuilder()
|
| 1753 |
.setCustomId('formation_select')
|
| 1754 |
-
.setPlaceholder(`Current
|
| 1755 |
.addOptions(formOptions)
|
| 1756 |
));
|
| 1757 |
|
|
@@ -1760,7 +1883,7 @@ function createLineupView(guildId) {
|
|
| 1760 |
let currentPosCount = 0;
|
| 1761 |
|
| 1762 |
formation.forEach(([posKey, posLabel]) => {
|
| 1763 |
-
if (currentPosCount ===
|
| 1764 |
rows.push(currentRow);
|
| 1765 |
currentRow = new ActionRowBuilder();
|
| 1766 |
currentPosCount = 0;
|
|
@@ -1781,9 +1904,10 @@ function createLineupView(guildId) {
|
|
| 1781 |
});
|
| 1782 |
if (currentPosCount > 0) rows.push(currentRow);
|
| 1783 |
|
| 1784 |
-
// Clear and Done Buttons
|
| 1785 |
rows.push(new ActionRowBuilder().addComponents(
|
| 1786 |
new ButtonBuilder().setCustomId('lineup_done').setLabel('Show Final Image').setStyle(ButtonStyle.Success).setEmoji("🖼️"),
|
|
|
|
| 1787 |
new ButtonBuilder().setCustomId('lineup_clear').setLabel('Clear Board').setStyle(ButtonStyle.Danger)
|
| 1788 |
));
|
| 1789 |
|
|
|
|
| 418 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
|
| 419 |
lineupOwners.set(message.guildId, message.author.id);
|
| 420 |
saveLineup();
|
| 421 |
+
|
| 422 |
+
const formOptions = Object.entries(FORMATIONS)
|
| 423 |
+
.filter(([name, pos]) => pos.length === 7)
|
| 424 |
+
.map(([k, v]) => ({ label: `${k} (7v7)`, value: k }));
|
| 425 |
+
|
| 426 |
+
const row1 = new ActionRowBuilder().addComponents(
|
| 427 |
new StringSelectMenuBuilder()
|
| 428 |
.setCustomId('formation_select_initial')
|
| 429 |
+
.setPlaceholder('Step 1: Select 7v7 Formation...')
|
| 430 |
.addOptions(formOptions)
|
| 431 |
);
|
| 432 |
+
const row2 = new ActionRowBuilder().addComponents(
|
| 433 |
+
new ButtonBuilder()
|
| 434 |
+
.setCustomId('open_custom_lineup_modal')
|
| 435 |
+
.setLabel('Custom / Other Sizes (6v6 - 11v11)')
|
| 436 |
+
.setStyle(ButtonStyle.Primary)
|
| 437 |
+
.setEmoji("🛠️")
|
| 438 |
+
);
|
| 439 |
+
const embed = UI.createEmbed("📋 Initialize Lineup", "Select a **7v7 formation** from the dropdown, or click the button for **other sizes** (6v6 to 11v11) and **custom positions**.", UI.colors.primary);
|
| 440 |
+
const msg = await message.channel.send({ embeds: [embed], components: [row1, row2] });
|
| 441 |
addToCleanupQueue(message.guildId, message.channelId, msg.id, 'poll');
|
| 442 |
}
|
| 443 |
|
|
|
|
| 848 |
|
| 849 |
if (commandName === 'managerlineup') {
|
| 850 |
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
|
| 851 |
+
const formOptions = Object.entries(FORMATIONS)
|
| 852 |
+
.filter(([name, pos]) => pos.length === 7)
|
| 853 |
+
.map(([k, v]) => ({ label: `${k} (7v7)`, value: k }));
|
| 854 |
const row = new ActionRowBuilder().addComponents(
|
| 855 |
new StringSelectMenuBuilder()
|
| 856 |
.setCustomId('manager_formation_select')
|
| 857 |
+
.setPlaceholder('Step 1: Select 7v7 Formation...')
|
| 858 |
.addOptions(formOptions)
|
| 859 |
);
|
| 860 |
await message.channel.send({ content: "📋 **Step 1: Choose Formation for GUI Editor**", components: [row] });
|
|
|
|
| 1020 |
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return sendNoPermission(interaction);
|
| 1021 |
lineupOwners.set(interaction.guildId, interaction.user.id);
|
| 1022 |
saveLineup();
|
| 1023 |
+
|
| 1024 |
+
const formOptions = Object.entries(FORMATIONS)
|
| 1025 |
+
.filter(([name, pos]) => pos.length === 7)
|
| 1026 |
+
.map(([k, v]) => ({ label: `${k} (7v7)`, value: k }));
|
| 1027 |
+
|
| 1028 |
+
const row1 = new ActionRowBuilder().addComponents(
|
| 1029 |
new StringSelectMenuBuilder()
|
| 1030 |
.setCustomId('formation_select_initial')
|
| 1031 |
+
.setPlaceholder('Step 1: Select 7v7 Formation...')
|
| 1032 |
.addOptions(formOptions)
|
| 1033 |
);
|
| 1034 |
+
const row2 = new ActionRowBuilder().addComponents(
|
| 1035 |
+
new ButtonBuilder()
|
| 1036 |
+
.setCustomId('open_custom_lineup_modal')
|
| 1037 |
+
.setLabel('Custom / Other Sizes (6v6 - 11v11)')
|
| 1038 |
+
.setStyle(ButtonStyle.Primary)
|
| 1039 |
+
.setEmoji("🛠️")
|
| 1040 |
+
);
|
| 1041 |
+
const embed = UI.createEmbed("📋 Initialize Lineup", "Select a **7v7 formation** from the dropdown, or click the button for **other sizes** (6v6 to 11v11) and **custom positions**.", UI.colors.primary);
|
| 1042 |
+
await safeReply(interaction, { embeds: [embed], components: [row1, row2] });
|
| 1043 |
}
|
| 1044 |
|
| 1045 |
if (interaction.commandName === 'clear') {
|
|
|
|
| 1134 |
|
| 1135 |
if (interaction.commandName === 'managerlineup') {
|
| 1136 |
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", flags: [MessageFlags.Ephemeral] });
|
| 1137 |
+
const formOptions = Object.entries(FORMATIONS)
|
| 1138 |
+
.filter(([name, pos]) => pos.length === 7)
|
| 1139 |
+
.map(([k, v]) => ({ label: `${k} (7v7)`, value: k }));
|
| 1140 |
const row = new ActionRowBuilder().addComponents(
|
| 1141 |
new StringSelectMenuBuilder()
|
| 1142 |
.setCustomId('manager_formation_select')
|
| 1143 |
+
.setPlaceholder('Step 1: Select 7v7 Formation...')
|
| 1144 |
.addOptions(formOptions)
|
| 1145 |
);
|
| 1146 |
await safeReply(interaction, { content: "📋 **Step 1: Choose Formation for GUI Editor**", components: [row] });
|
|
|
|
| 1223 |
}
|
| 1224 |
|
| 1225 |
if (interaction.isButton()) {
|
| 1226 |
+
if (interaction.customId === 'open_custom_lineup_modal') {
|
| 1227 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return sendNoPermission(interaction);
|
| 1228 |
+
|
| 1229 |
+
const modal = new ModalBuilder()
|
| 1230 |
+
.setCustomId('custom_lineup_modal')
|
| 1231 |
+
.setTitle('Custom Lineup / Other Sizes');
|
| 1232 |
+
|
| 1233 |
+
const presetInput = new TextInputBuilder()
|
| 1234 |
+
.setCustomId('preset_input')
|
| 1235 |
+
.setLabel("Preset (e.g. 4-3-3 (11v11) or 6v6)")
|
| 1236 |
+
.setPlaceholder("Type a preset name like: 4-3-3 (11v11), 2-2-1 (6v6), etc.")
|
| 1237 |
+
.setStyle(TextInputStyle.Short)
|
| 1238 |
+
.setRequired(false);
|
| 1239 |
+
|
| 1240 |
+
const customInput = new TextInputBuilder()
|
| 1241 |
+
.setCustomId('custom_input')
|
| 1242 |
+
.setLabel("OR Custom Positions (Comma separated)")
|
| 1243 |
+
.setPlaceholder("Example: GK, LB, CB, CB, RB, CDM, CM, LW, ST, RW")
|
| 1244 |
+
.setStyle(TextInputStyle.Paragraph)
|
| 1245 |
+
.setRequired(false);
|
| 1246 |
+
|
| 1247 |
+
modal.addComponents(
|
| 1248 |
+
new ActionRowBuilder().addComponents(presetInput),
|
| 1249 |
+
new ActionRowBuilder().addComponents(customInput)
|
| 1250 |
+
);
|
| 1251 |
+
await interaction.showModal(modal);
|
| 1252 |
+
}
|
| 1253 |
if (interaction.customId === 'toggle_auto_friendly') {
|
| 1254 |
if (!interaction.member.permissions.has('Administrator')) return safeReply(interaction, { content: "❌ Admin Only", ephemeral: true });
|
| 1255 |
const config = storage.data.config[interaction.guildId] || {};
|
|
|
|
| 1276 |
}
|
| 1277 |
|
| 1278 |
if (interaction.isModalSubmit()) {
|
| 1279 |
+
if (interaction.customId === 'custom_lineup_modal') {
|
| 1280 |
+
const preset = interaction.fields.getTextInputValue('preset_input').trim();
|
| 1281 |
+
const custom = interaction.fields.getTextInputValue('custom_input').trim();
|
| 1282 |
+
|
| 1283 |
+
let formation = null;
|
| 1284 |
+
let formName = "Custom";
|
| 1285 |
+
|
| 1286 |
+
if (preset && FORMATIONS[preset]) {
|
| 1287 |
+
formation = FORMATIONS[preset];
|
| 1288 |
+
formName = preset;
|
| 1289 |
+
} else if (custom) {
|
| 1290 |
+
formation = autoDetectFormation(custom);
|
| 1291 |
+
formName = `Custom (${formation.length}v${formation.length})`;
|
| 1292 |
+
} else if (preset) {
|
| 1293 |
+
// Try to find preset by partial match
|
| 1294 |
+
const match = Object.keys(FORMATIONS).find(k => k.toLowerCase().includes(preset.toLowerCase()));
|
| 1295 |
+
if (match) {
|
| 1296 |
+
formation = FORMATIONS[match];
|
| 1297 |
+
formName = match;
|
| 1298 |
+
}
|
| 1299 |
+
}
|
| 1300 |
+
|
| 1301 |
+
if (!formation) {
|
| 1302 |
+
return safeReply(interaction, { content: "❌ Could not find that preset or parse your custom positions. Example: `GK, CB, CM, ST`", ephemeral: true });
|
| 1303 |
+
}
|
| 1304 |
+
|
| 1305 |
+
const guildId = interaction.guildId;
|
| 1306 |
+
// Store this custom formation in the FORMATIONS object for this guild session
|
| 1307 |
+
const tempKey = `custom_${guildId}`;
|
| 1308 |
+
FORMATIONS[tempKey] = formation;
|
| 1309 |
+
guildSelectedFormation.set(guildId, tempKey);
|
| 1310 |
+
|
| 1311 |
+
// Clear current lineup as formation changed
|
| 1312 |
+
const map = new Map();
|
| 1313 |
+
guildLineups.set(guildId, map);
|
| 1314 |
+
saveLineup();
|
| 1315 |
+
|
| 1316 |
+
await interaction.reply({ content: `✅ Formation set to **${formName}**!`, ephemeral: true });
|
| 1317 |
+
|
| 1318 |
+
// Update the board if it exists, or tell them to use /lineup
|
| 1319 |
+
const boardInfo = activeLineupMessages.get(guildId);
|
| 1320 |
+
if (boardInfo) {
|
| 1321 |
+
try {
|
| 1322 |
+
const channel = await client.channels.fetch(boardInfo.channelId);
|
| 1323 |
+
const msg = await channel.messages.fetch(boardInfo.messageId);
|
| 1324 |
+
if (msg) await msg.edit(createLineupView(guildId));
|
| 1325 |
+
} catch (e) { }
|
| 1326 |
+
} else {
|
| 1327 |
+
// If no board, send the view as a new message
|
| 1328 |
+
const view = createLineupView(guildId);
|
| 1329 |
+
await interaction.channel.send(view);
|
| 1330 |
+
}
|
| 1331 |
+
return;
|
| 1332 |
+
}
|
| 1333 |
if (interaction.customId === 'auto_friendly_interval_modal') {
|
| 1334 |
const interval = parseInt(interaction.fields.getTextInputValue('interval_input'));
|
| 1335 |
if (isNaN(interval) || interval < 1) {
|
|
|
|
| 1853 |
|
| 1854 |
const rows = [];
|
| 1855 |
|
| 1856 |
+
// Formation Dropdown (Default to 7v7)
|
| 1857 |
+
const currentIs7v7 = formation.length === 7;
|
| 1858 |
+
const allFormKeys = Object.keys(FORMATIONS);
|
| 1859 |
+
|
| 1860 |
+
// Filter options: if current is 7v7, show only 7v7. If not, show all for that size or just show all.
|
| 1861 |
+
// User requested "only 7v7 in the dropdown", so let's stick to that for the main view.
|
| 1862 |
+
let filteredKeys = allFormKeys.filter(k => FORMATIONS[k].length === 7);
|
| 1863 |
+
|
| 1864 |
+
// If the current formation is NOT 7v7, we should include it in the dropdown so it's visible as selected
|
| 1865 |
+
if (!currentIs7v7 && !filteredKeys.includes(formKey)) {
|
| 1866 |
+
filteredKeys.push(formKey);
|
| 1867 |
+
}
|
| 1868 |
+
|
| 1869 |
+
const formOptions = filteredKeys.slice(0, 25).map(k => ({
|
| 1870 |
+
label: k.includes('(') ? k : `${k} (7v7)`,
|
| 1871 |
+
value: k
|
| 1872 |
+
}));
|
| 1873 |
+
|
| 1874 |
rows.push(new ActionRowBuilder().addComponents(
|
| 1875 |
new StringSelectMenuBuilder()
|
| 1876 |
.setCustomId('formation_select')
|
| 1877 |
+
.setPlaceholder(`Current: ${formKey} (${formation.length}v${formation.length})`)
|
| 1878 |
.addOptions(formOptions)
|
| 1879 |
));
|
| 1880 |
|
|
|
|
| 1883 |
let currentPosCount = 0;
|
| 1884 |
|
| 1885 |
formation.forEach(([posKey, posLabel]) => {
|
| 1886 |
+
if (currentPosCount === 5) { // 5 buttons per row for better fit on mobile
|
| 1887 |
rows.push(currentRow);
|
| 1888 |
currentRow = new ActionRowBuilder();
|
| 1889 |
currentPosCount = 0;
|
|
|
|
| 1904 |
});
|
| 1905 |
if (currentPosCount > 0) rows.push(currentRow);
|
| 1906 |
|
| 1907 |
+
// Clear, Custom and Done Buttons
|
| 1908 |
rows.push(new ActionRowBuilder().addComponents(
|
| 1909 |
new ButtonBuilder().setCustomId('lineup_done').setLabel('Show Final Image').setStyle(ButtonStyle.Success).setEmoji("🖼️"),
|
| 1910 |
+
new ButtonBuilder().setCustomId('open_custom_lineup_modal').setLabel('Custom / Other Sizes').setStyle(ButtonStyle.Primary).setEmoji("🛠️"),
|
| 1911 |
new ButtonBuilder().setCustomId('lineup_clear').setLabel('Clear Board').setStyle(ButtonStyle.Danger)
|
| 1912 |
));
|
| 1913 |
|