Brozy123 commited on
Commit
3e79910
·
verified ·
1 Parent(s): f175e8d

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +14 -11
index.js CHANGED
@@ -747,9 +747,9 @@ function createLineupView(guildId) {
747
  for (const [posKey, posLabel] of formation) {
748
  const players = lineup.get(posKey) || [];
749
  if (players.length > 0) {
750
- text += `🟩 **${posLabel}** ➔ ` + players.map(p => `<@${p}>`).join(', ') + "\n";
751
  } else {
752
- text += `⬛ **${posLabel}** ➔ 🈳 *Open*\n`;
753
  }
754
  }
755
 
@@ -925,19 +925,22 @@ client.on('interactionCreate', async (interaction) => {
925
  const pos = interaction.customId.replace('join_', '');
926
  const userId = interaction.user.id;
927
 
928
- // Remove from all other positions first
 
 
 
 
 
 
 
929
  for (const [p, players] of lineup) {
930
  lineup.set(p, players.filter(id => id !== userId));
931
  }
932
 
933
- // Add to new position
934
- if (!lineup.get(pos)) lineup.set(pos, []);
935
- const targetQ = lineup.get(pos);
936
-
937
- if (targetQ.includes(userId)) {
938
- lineup.set(pos, targetQ.filter(id => id !== userId)); // toggle off
939
- } else {
940
- targetQ.push(userId);
941
  }
942
 
943
  await interaction.update(createLineupView(guildId));
 
747
  for (const [posKey, posLabel] of formation) {
748
  const players = lineup.get(posKey) || [];
749
  if (players.length > 0) {
750
+ text += `🟩 **${posLabel}** ➔ ` + players.map(p => `<@${p}>`).join(', ') + "\n\n";
751
  } else {
752
+ text += `⬛ **${posLabel}** ➔ *Open*\n\n`;
753
  }
754
  }
755
 
 
925
  const pos = interaction.customId.replace('join_', '');
926
  const userId = interaction.user.id;
927
 
928
+ // Check if they were already in this specific position
929
+ let wasInCurrentPos = false;
930
+ const currentQ = lineup.get(pos) || [];
931
+ if (currentQ.includes(userId)) {
932
+ wasInCurrentPos = true;
933
+ }
934
+
935
+ // Remove from all positions first
936
  for (const [p, players] of lineup) {
937
  lineup.set(p, players.filter(id => id !== userId));
938
  }
939
 
940
+ // Add to new position if they weren't just toggling off
941
+ if (!wasInCurrentPos) {
942
+ if (!lineup.get(pos)) lineup.set(pos, []);
943
+ lineup.get(pos).push(userId);
 
 
 
 
944
  }
945
 
946
  await interaction.update(createLineupView(guildId));