Brozy123 commited on
Commit
dd5baed
·
verified ·
1 Parent(s): cbc99c6

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +0 -131
index.js CHANGED
@@ -2535,138 +2535,7 @@ client.on('interactionCreate', async (interaction) => {
2535
  }
2536
  }
2537
 
2538
- if (interaction.customId && interaction.customId.startsWith('tz_select_')) {
2539
- try {
2540
- await interaction.deferUpdate();
2541
- const matchId = interaction.customId.replace('tz_select_', '');
2542
- const matchData = pendingMatches.get(matchId);
2543
-
2544
- if (!matchData) {
2545
- return interaction.followUp({ content: "❌ Match session expired or bot restarted. Please try the command again.", flags: [MessageFlags.Ephemeral] });
2546
- }
2547
-
2548
- const offset = parseFloat(interaction.values[0]);
2549
- let timeStr = matchData.timeInput;
2550
-
2551
- // If they used the "Display / Actual" format, take the actual time
2552
- if (timeStr.includes(' / ')) {
2553
- timeStr = timeStr.split(' / ').pop().trim();
2554
- }
2555
-
2556
- // Normalize "9 PM" to "9:00 PM" for the parser
2557
- let normalized = timeStr.replace(/(\d+)\s*(AM|PM)/i, "$1:00 $2");
2558
-
2559
- // Use UTC methods to ensure consistent baseline
2560
- const targetDate = new Date();
2561
- const hoursMatch = normalized.match(/(\d+):(\d+)\s*(am|pm)/i) || normalized.match(/(\d+)\s*(am|pm)/i);
2562
-
2563
- if (!hoursMatch) {
2564
- return interaction.followUp({ content: "❌ Could not parse your time input. Please use a format like `9 PM` or `21:00 PM`.", flags: [MessageFlags.Ephemeral] });
2565
- }
2566
-
2567
- let hours = parseInt(hoursMatch[1]);
2568
- const minutes = parseInt(hoursMatch[2] || "0");
2569
- const ampm = (hoursMatch[3] || "").toLowerCase();
2570
-
2571
- if (ampm === 'pm' && hours !== 12) hours += 12;
2572
- if (ampm === 'am' && hours === 12) hours = 0;
2573
-
2574
- // Check for date part
2575
- const dateMatch = normalized.match(/(\d+)[/-](\d+)[/-](\d+)/) || normalized.match(/(\w+)\s+(\d+),?\s+(\d+)/);
2576
- if (dateMatch) {
2577
- const d = new Date(normalized);
2578
- if (!isNaN(d.getTime())) {
2579
- targetDate.setUTCFullYear(d.getFullYear());
2580
- targetDate.setUTCMonth(d.getMonth());
2581
- targetDate.setUTCDate(d.getDate());
2582
- }
2583
- }
2584
-
2585
- targetDate.setUTCHours(hours, minutes, 0, 0);
2586
- const finalTs = Math.floor(targetDate.getTime() / 1000) - (offset * 3600);
2587
-
2588
- if (matchData.type === 'friendly') {
2589
- // Finalize Friendly Match
2590
- if (!storage.data.scheduled_matches) storage.data.scheduled_matches = [];
2591
- storage.data.scheduled_matches.push({
2592
- guildId: interaction.guildId,
2593
- type: 'friendly',
2594
- timeInput: matchData.timeInput,
2595
- timestamp: finalTs * 1000,
2596
- reminded: false
2597
- });
2598
- storage.save('active_polls');
2599
-
2600
- await interaction.editReply({ content: `✅ Friendly scheduled for <t:${finalTs}:F>!`, components: [] });
2601
-
2602
- if (matchData.friendlyType === 'voting') {
2603
- // Send Lineup Board immediately (not the poll)
2604
- const lineup = getGuildLineup(interaction.guildId);
2605
- lineup.clear();
2606
- saveLineup();
2607
- const view = createLineupView(interaction.guildId);
2608
- const lineupMsg = await interaction.channel.send(view);
2609
-
2610
- // Add reactions for "voters"
2611
- await lineupMsg.react('🟩').catch(() => { });
2612
- await lineupMsg.react('🟥').catch(() => { });
2613
-
2614
- activeLineupMessages.set(interaction.guildId, { channelId: interaction.channelId, messageId: lineupMsg.id });
2615
- addToCleanupQueue(interaction.guildId, interaction.channelId, lineupMsg.id, 'lineup');
2616
-
2617
- // Save messageId to the match so we can check reactions later
2618
- if (storage.data.scheduled_matches && storage.data.scheduled_matches.length > 0) {
2619
- storage.data.scheduled_matches[storage.data.scheduled_matches.length - 1].messageId = lineupMsg.id;
2620
- storage.data.scheduled_matches[storage.data.scheduled_matches.length - 1].channelId = interaction.channelId;
2621
- }
2622
- storage.save('active_polls');
2623
- } else {
2624
- // Trigger Manager Editor
2625
- const guildId = interaction.guildId;
2626
- guildSelectedFormationA.set(guildId, matchData.selectedFormation);
2627
- const map = new Map();
2628
- guildLineups.set(guildId, map);
2629
- saveLineup();
2630
-
2631
- const editor = createManagerEditor(guildId, client);
2632
- const editorMsg = await interaction.channel.send(editor);
2633
- managerBoards.set(guildId, { channelId: interaction.channelId, messageId: editorMsg.id });
2634
- }
2635
- } else {
2636
- // Finalize League Match
2637
- const content = `⭐▬▬ 🏆 **LEAGUE MATCH** 🏆 ▬▬⭐\n🏟️ **${matchData.home}** vs **${matchData.away}**\n🔗 ${matchData.link}\n🕒 **Time**: <t:${finalTs}:F> (<t:${finalTs}:R>)\n🤝 Session\n⭐▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬⭐\n@everyone`;
2638
 
2639
- const channel = await client.channels.fetch(matchData.channelId).catch(() => null);
2640
- if (!channel) return interaction.followUp({ content: "❌ Original channel not found.", flags: [MessageFlags.Ephemeral] });
2641
-
2642
- const msg = await channel.send({ content, allowedMentions: { parse: ['everyone', 'roles', 'users'] } });
2643
- await msg.react('🟩').catch(() => { });
2644
- await msg.react('🟥').catch(() => { });
2645
-
2646
- storage.data.active_polls[interaction.guildId] = msg.id;
2647
- if (!storage.data.scheduled_matches) storage.data.scheduled_matches = [];
2648
- storage.data.scheduled_matches.push({
2649
- guildId: interaction.guildId,
2650
- home: matchData.home,
2651
- away: matchData.away,
2652
- link: matchData.link,
2653
- timestamp: finalTs * 1000,
2654
- reminded: false
2655
- });
2656
- storage.save('active_polls');
2657
- addToCleanupQueue(interaction.guildId, interaction.channelId, msg.id, 'poll');
2658
-
2659
- await interaction.editReply({ content: "✅ Match scheduled! I have posted it in the channel.", components: [] });
2660
- }
2661
-
2662
- pendingMatches.delete(matchId);
2663
- } catch (err) {
2664
- console.error("[TZ] Critical Error:", err);
2665
- try {
2666
- await interaction.followUp({ content: "❌ A system error occurred while processing your selection.", flags: [MessageFlags.Ephemeral] });
2667
- } catch (e) { }
2668
- }
2669
- return;
2670
  }
2671
  });
2672
 
 
2535
  }
2536
  }
2537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2538
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2539
  }
2540
  });
2541