Brozy123 commited on
Commit
6b2064d
·
verified ·
1 Parent(s): 13f2987

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +209 -29
index.js CHANGED
@@ -40,8 +40,11 @@ const guildActiveCategory = new Map(); // Stores the currently selected category
40
  try {
41
  const { createLineupAttachment } = require('./lineupRenderer');
42
  const { createProfileAttachment } = require('./profileRenderer');
 
43
  global.createLineupAttachment = createLineupAttachment;
44
  global.createProfileAttachment = createProfileAttachment;
 
 
45
  global.saveLineup = saveLineup;
46
  console.log(">>> [BOOT] Graphics Renderers & Persistence loaded.");
47
  } catch (err) {
@@ -51,7 +54,6 @@ try {
51
  const { UI } = require('./NewBotStyle');
52
  const broadcastSystem = require('./broadcast_system');
53
  const grantSystem = require('./grant_system');
54
- const dmall = require('./dmall');
55
  console.log(`[SYSTEM] Starting FriendlyBot v4.0 (Watchdog Relaxed: ${new Date().toISOString()})`);
56
 
57
  process.on('unhandledRejection', (reason, promise) => {
@@ -175,6 +177,37 @@ const commandsData = [
175
  { name: 'sendlink', description: 'Send a match link publicly', options: [{ name: 'link', type: 3, description: 'The link to send', required: true }] },
176
  { name: 'profile', description: 'Generate a custom profile card', options: [{ name: 'user', type: 6, description: 'The user to check', required: false }] },
177
  { name: 'profileimage', description: 'Generate a high-quality visual profile card', options: [{ name: 'user', type: 6, description: 'The user to check', required: false }] },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  { name: 'giverole', description: 'Give a role to members (Admin)', options: [{ name: 'role', type: 8, description: 'The role', required: true }] },
179
  { name: 'uptime', description: 'Show how long the bot has been online' },
180
  { name: 'motm', description: 'Award Man of the Match to a player', options: [{ name: 'player', type: 6, description: 'The player to award', required: true }] },
@@ -362,7 +395,7 @@ async function logTransaction(client, commandName, user, guild, member) {
362
  let isOwner = app && app.owner ? (user.id === app.owner.ownerId || user.id === app.owner.id) : false;
363
 
364
  const whitelistCmds = ['friendly', 'lineup', 'win', 'loss', 'draw', 'leaguematch', 'clear', 'lock', 'unlock', 'sendlink', 'lineupimage', 'managerlineup'];
365
- const adminCmds = ['setup', 'addrole', 'removerole', 'sync', 'sync_cmds', 'dmall'];
366
  const ownerCmds = ['reboot', 'grantservers'];
367
 
368
  if (whitelistCmds.includes(commandName) && !isWhiteListed && !isAdmin && !isOwner) worked = false;
@@ -399,26 +432,7 @@ client.on('messageCreate', async (message) => {
399
  const prefix = '!';
400
  if (!message.content.startsWith(prefix)) return;
401
 
402
- const args = message.content.slice(prefix.length).trim().split(/ +/);
403
- const commandName = args.shift().toLowerCase();
404
-
405
- if (commandName === 'friendlymute') {
406
- storage.data.muted_users = storage.data.muted_users || {};
407
- storage.data.muted_users[message.author.id] = true;
408
- storage.save('active_polls');
409
- await message.reply("🔕 **Friendly Muted** - You will no longer receive friendly match DMs. Use `!friendlyunmute` to re-enable.");
410
- return;
411
- }
412
-
413
- if (commandName === 'friendlyunmute') {
414
- storage.data.muted_users = storage.data.muted_users || {};
415
- delete storage.data.muted_users[message.author.id];
416
- storage.save('active_polls');
417
- await message.reply("🔔 **Friendly Unmuted** - You will now receive friendly match DMs.");
418
- return;
419
- }
420
-
421
- return; // Ignore other commands in DM
422
  }
423
 
424
  const prefix = storage.getPrefix(message.guildId);
@@ -427,7 +441,7 @@ client.on('messageCreate', async (message) => {
427
  const args = message.content.slice(prefix.length).trim().split(/ +/);
428
  const commandName = args.shift().toLowerCase();
429
 
430
- const allCommands = [...commandsData.map(c => c.name), 'sync', 'sync_cmds', 'reboot', 'grantservers', 'servers', 'help', 'motm', 'profileimage', 'swap', 'dmall'];
431
  if (allCommands.includes(commandName)) {
432
  logTransaction(client, commandName, message.author, message.guild, message.member);
433
  }
@@ -437,10 +451,6 @@ client.on('messageCreate', async (message) => {
437
  msg.edit(`Pong! Latency: ${msg.createdTimestamp - message.createdTimestamp}ms`);
438
  }
439
 
440
- if (commandName === 'dmall') {
441
- await dmall.initiateDMAll(message);
442
- }
443
-
444
  if (commandName === 'friendly') {
445
  if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
446
 
@@ -574,6 +584,126 @@ client.on('messageCreate', async (message) => {
574
  await message.reply(`🟢 **Online**\nWhitelist: ${rInfo}`);
575
  }
576
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
  if (commandName === 'win' || commandName === 'loss' || commandName === 'draw') {
578
  if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
579
  const type = commandName;
@@ -894,9 +1024,8 @@ client.on('messageCreate', async (message) => {
894
  !clear /clear - (Admin/Staff) Clear messages.
895
  !lock /lock - (Admin/Staff) Lock the current channel.
896
  !unlock /unlock - (Admin/Staff) Unlock the current channel.
897
- !dmall - (Admin Only) DM every member and track availability.
898
 
899
- ⭐▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬⭐
900
  Tip: All commands support Discord Slash Commands (/) for a better experience!`;
901
  await message.reply(`\`\`\`\n${h}\n\`\`\``);
902
  }
@@ -1371,6 +1500,57 @@ client.on('interactionCreate', async (interaction) => {
1371
  }
1372
  }
1373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1374
  if (interaction.commandName === 'giverole') {
1375
  await safeReply(interaction, { content: `🖌️ **Feature Migration in Progress!**\nThe \`${interaction.commandName}\` feature is currently being updated to Next-Gen graphics. Check back shortly!`, ephemeral: true });
1376
  }
 
40
  try {
41
  const { createLineupAttachment } = require('./lineupRenderer');
42
  const { createProfileAttachment } = require('./profileRenderer');
43
+ const { TACTICS, createTacticAttachment } = require('./tacticRenderer');
44
  global.createLineupAttachment = createLineupAttachment;
45
  global.createProfileAttachment = createProfileAttachment;
46
+ global.createTacticAttachment = createTacticAttachment;
47
+ global.TACTICS = TACTICS;
48
  global.saveLineup = saveLineup;
49
  console.log(">>> [BOOT] Graphics Renderers & Persistence loaded.");
50
  } catch (err) {
 
54
  const { UI } = require('./NewBotStyle');
55
  const broadcastSystem = require('./broadcast_system');
56
  const grantSystem = require('./grant_system');
 
57
  console.log(`[SYSTEM] Starting FriendlyBot v4.0 (Watchdog Relaxed: ${new Date().toISOString()})`);
58
 
59
  process.on('unhandledRejection', (reason, promise) => {
 
177
  { name: 'sendlink', description: 'Send a match link publicly', options: [{ name: 'link', type: 3, description: 'The link to send', required: true }] },
178
  { name: 'profile', description: 'Generate a custom profile card', options: [{ name: 'user', type: 6, description: 'The user to check', required: false }] },
179
  { name: 'profileimage', description: 'Generate a high-quality visual profile card', options: [{ name: 'user', type: 6, description: 'The user to check', required: false }] },
180
+ {
181
+ name: 'tactic',
182
+ description: 'View tactical information for 7v7 formations with current lineup',
183
+ options: [
184
+ {
185
+ name: 'formation',
186
+ type: 3,
187
+ description: 'Choose a 7v7 formation',
188
+ required: true,
189
+ choices: [
190
+ { name: 'default (4-2-1)', value: 'default' },
191
+ { name: '3-1-2', value: '3-1-2' },
192
+ { name: '3-0-3', value: '3-0-3' },
193
+ { name: '3-2-1', value: '3-2-1' },
194
+ { name: '2-3-1', value: '2-3-1' },
195
+ { name: '2-2-2', value: '2-2-2' },
196
+ { name: '4-1-1', value: '4-1-1' },
197
+ { name: '3-3-0', value: '3-3-0' },
198
+ { name: '2-1-3', value: '2-1-3' },
199
+ { name: '1-4-1', value: '1-4-1' },
200
+ { name: '4-2-0', value: '4-2-0' },
201
+ { name: '3-1-3', value: '3-1-3' },
202
+ { name: '5-0-1', value: '5-0-1' },
203
+ { name: '3-1-1-1', value: '3-1-1-1' },
204
+ { name: '2-2-1-1', value: '2-2-1-1' },
205
+ { name: '4-1-2', value: '4-1-2' },
206
+ { name: '2-3-2', value: '2-3-2' }
207
+ ]
208
+ }
209
+ ]
210
+ },
211
  { name: 'giverole', description: 'Give a role to members (Admin)', options: [{ name: 'role', type: 8, description: 'The role', required: true }] },
212
  { name: 'uptime', description: 'Show how long the bot has been online' },
213
  { name: 'motm', description: 'Award Man of the Match to a player', options: [{ name: 'player', type: 6, description: 'The player to award', required: true }] },
 
395
  let isOwner = app && app.owner ? (user.id === app.owner.ownerId || user.id === app.owner.id) : false;
396
 
397
  const whitelistCmds = ['friendly', 'lineup', 'win', 'loss', 'draw', 'leaguematch', 'clear', 'lock', 'unlock', 'sendlink', 'lineupimage', 'managerlineup'];
398
+ const adminCmds = ['setup', 'addrole', 'removerole', 'sync', 'sync_cmds'];
399
  const ownerCmds = ['reboot', 'grantservers'];
400
 
401
  if (whitelistCmds.includes(commandName) && !isWhiteListed && !isAdmin && !isOwner) worked = false;
 
432
  const prefix = '!';
433
  if (!message.content.startsWith(prefix)) return;
434
 
435
+ return; // Ignore commands in DM
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  }
437
 
438
  const prefix = storage.getPrefix(message.guildId);
 
441
  const args = message.content.slice(prefix.length).trim().split(/ +/);
442
  const commandName = args.shift().toLowerCase();
443
 
444
+ const allCommands = [...commandsData.map(c => c.name), 'sync', 'sync_cmds', 'reboot', 'grantservers', 'servers', 'help', 'motm', 'profileimage', 'swap'];
445
  if (allCommands.includes(commandName)) {
446
  logTransaction(client, commandName, message.author, message.guild, message.member);
447
  }
 
451
  msg.edit(`Pong! Latency: ${msg.createdTimestamp - message.createdTimestamp}ms`);
452
  }
453
 
 
 
 
 
454
  if (commandName === 'friendly') {
455
  if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
456
 
 
584
  await message.reply(`🟢 **Online**\nWhitelist: ${rInfo}`);
585
  }
586
 
587
+ if (commandName === 'tactic') {
588
+ if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
589
+
590
+ const formationArg = args[0] || 'default';
591
+ const formation = FORMATIONS[formationArg];
592
+
593
+ if (!formation || formation.length !== 7) {
594
+ return message.reply("❌ Please specify a valid 7v7 formation. Usage: `!tactic [formation_name]`\nExample: `!tactic 3-1-2`");
595
+ }
596
+
597
+ try {
598
+ // Get current lineup
599
+ const lineup = getGuildLineup(message.guildId);
600
+
601
+ // Get tactic data
602
+ const tacticData = global.TACTICS[formationArg] || global.TACTICS["default"];
603
+
604
+ // Generate tactic image
605
+ const attachment = await global.createTacticAttachment(formationArg, formation, lineup, tacticData, client);
606
+
607
+ // Build numbered position list with player names
608
+ let positionList = "";
609
+ formation.forEach(([posKey, posLabel], index) => {
610
+ const number = index + 1;
611
+ const players = lineup.get(posKey) || [];
612
+ const playerDisplay = players.length > 0 ? `<@${players[0]}>` : '*Empty*';
613
+ positionList += `**${number}.** ${posLabel} - ${playerDisplay}\n`;
614
+ });
615
+
616
+ // Create embed
617
+ const embed = UI.createEmbed(
618
+ `📋 TACTIC — ${tacticData.name}`,
619
+ `${tacticData.summary}\n\n${positionList}`
620
+ );
621
+ embed.setImage('attachment://tactic.png');
622
+ embed.addFields(
623
+ { name: '⚽ Attack', value: tacticData.attack, inline: false },
624
+ { name: '🛡️ Defense', value: tacticData.defense, inline: false },
625
+ { name: '🎯 Key Points', value: tacticData.keyPoints.join('\n'), inline: false }
626
+ );
627
+ embed.setFooter({ text: 'FriendlyBot Tactics | 7v7 Only' });
628
+ embed.setTimestamp();
629
+
630
+ await message.channel.send({ embeds: [embed], files: [attachment] });
631
+ } catch (e) {
632
+ console.error('[Tactic] Error:', e);
633
+ await message.reply('❌ Failed to generate tactic.');
634
+ }
635
+ }
636
+
637
+ if (commandName === 'teamrandom') {
638
+ if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
639
+
640
+ const count = parseInt(args[0]) || 2;
641
+ const lineup = getGuildLineup(message.guildId);
642
+
643
+ let allPlayers = [];
644
+ for (const [pos, players] of lineup) {
645
+ allPlayers.push(...players);
646
+ }
647
+
648
+ if (allPlayers.length === 0) {
649
+ return message.reply("❌ No players in the lineup! Use `!lineup` first and add players.");
650
+ }
651
+
652
+ const shuffled = allPlayers.sort(() => Math.random() - 0.5);
653
+ const teamSize = Math.ceil(shuffled.length / count);
654
+ let teams = [];
655
+ for (let i = 0; i < count; i++) {
656
+ teams.push(shuffled.slice(i * teamSize, (i + 1) * teamSize));
657
+ }
658
+
659
+ let description = "";
660
+ teams.forEach((team, index) => {
661
+ if (team.length > 0) {
662
+ description += `**Team ${index + 1}:**\n`;
663
+ team.forEach(playerId => {
664
+ description += `• <@${playerId}>\n`;
665
+ });
666
+ description += "\n";
667
+ }
668
+ });
669
+
670
+ const embed = UI.createEmbed("🎲 Random Teams", description || "No players found.", UI.colors.success);
671
+ await message.channel.send({ embeds: [embed] });
672
+ }
673
+
674
+ if (commandName === 'playerstats') {
675
+ const target = message.mentions.users.first() || message.author;
676
+ const stats = storage.data.stats[target.id] || { matches: 0, goals: 0, mvps: 0 };
677
+ const record = storage.getRecord(message.guildId);
678
+
679
+ const embed = UI.createEmbed(`🎴 Player Stats — ${target.username}`,
680
+ `**Matches:** ${stats.matches || 0}\n**Goals:** ${stats.goals || 0}\n**MVPs:** ${stats.mvps || 0}`,
681
+ UI.colors.primary);
682
+ embed.setThumbnail(target.displayAvatarURL({ dynamic: true }));
683
+ await message.channel.send({ embeds: [embed] });
684
+ }
685
+
686
+ if (commandName === 'matchpredict') {
687
+ const lineup = getGuildLineup(message.guildId);
688
+ let playerCount = 0;
689
+ for (const [pos, players] of lineup) {
690
+ playerCount += players.length;
691
+ }
692
+
693
+ if (playerCount === 0) {
694
+ return message.reply("❌ No players in the lineup! Add some players first.");
695
+ }
696
+
697
+ const outcomes = ["🏆 Victory", "🤝 Draw", "🟥 Defeat"];
698
+ const prediction = outcomes[Math.floor(Math.random() * outcomes.length)];
699
+ const confidence = Math.floor(Math.random() * 30) + 70;
700
+
701
+ const embed = UI.createEmbed("🎯 Match Prediction",
702
+ `Based on current lineup of **${playerCount}** players:\n\n**Predicted Result:** ${prediction}\n**Confidence:** ${confidence}%`,
703
+ UI.colors.warning);
704
+ await message.channel.send({ embeds: [embed] });
705
+ }
706
+
707
  if (commandName === 'win' || commandName === 'loss' || commandName === 'draw') {
708
  if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
709
  const type = commandName;
 
1024
  !clear /clear - (Admin/Staff) Clear messages.
1025
  !lock /lock - (Admin/Staff) Lock the current channel.
1026
  !unlock /unlock - (Admin/Staff) Unlock the current channel.
 
1027
 
1028
+ ⭐▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬⭐
1029
  Tip: All commands support Discord Slash Commands (/) for a better experience!`;
1030
  await message.reply(`\`\`\`\n${h}\n\`\`\``);
1031
  }
 
1500
  }
1501
  }
1502
 
1503
+ if (interaction.commandName === 'tactic') {
1504
+ if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member))
1505
+ return safeReply(interaction, { content: "❌ No Permission", flags: [MessageFlags.Ephemeral] });
1506
+
1507
+ try {
1508
+ const formationName = interaction.options.getString('formation');
1509
+ const formation = FORMATIONS[formationName];
1510
+
1511
+ if (!formation || formation.length !== 7) {
1512
+ return safeReply(interaction, { content: "❌ Please select a valid 7v7 formation.", flags: [MessageFlags.Ephemeral] });
1513
+ }
1514
+
1515
+ // Get current lineup
1516
+ const lineup = getGuildLineup(interaction.guildId);
1517
+
1518
+ // Get tactic data
1519
+ const tacticData = global.TACTICS[formationName] || global.TACTICS["default"];
1520
+
1521
+ // Generate tactic image with numbered positions and player names
1522
+ const attachment = await global.createTacticAttachment(formationName, formation, lineup, tacticData, client);
1523
+
1524
+ // Build numbered position list with player names
1525
+ let positionList = "";
1526
+ formation.forEach(([posKey, posLabel], index) => {
1527
+ const number = index + 1;
1528
+ const players = lineup.get(posKey) || [];
1529
+ const playerDisplay = players.length > 0 ? `<@${players[0]}>` : '*Empty*';
1530
+ positionList += `**${number}.** ${posLabel} - ${playerDisplay}\n`;
1531
+ });
1532
+
1533
+ // Create embed
1534
+ const embed = UI.createEmbed(
1535
+ `📋 TACTIC — ${tacticData.name}`,
1536
+ `${tacticData.summary}\n\n${positionList}`
1537
+ );
1538
+ embed.setImage('attachment://tactic.png');
1539
+ embed.addFields(
1540
+ { name: '⚽ Attack', value: tacticData.attack, inline: false },
1541
+ { name: '🛡️ Defense', value: tacticData.defense, inline: false },
1542
+ { name: '🎯 Key Points', value: tacticData.keyPoints.join('\n'), inline: false }
1543
+ );
1544
+ embed.setFooter({ text: 'FriendlyBot Tactics | 7v7 Only' });
1545
+ embed.setTimestamp();
1546
+
1547
+ await safeReply(interaction, { embeds: [embed], files: [attachment] });
1548
+ } catch (e) {
1549
+ console.error('[Tactic] Error:', e);
1550
+ await safeReply(interaction, '❌ Failed to generate tactic.');
1551
+ }
1552
+ }
1553
+
1554
  if (interaction.commandName === 'giverole') {
1555
  await safeReply(interaction, { content: `🖌️ **Feature Migration in Progress!**\nThe \`${interaction.commandName}\` feature is currently being updated to Next-Gen graphics. Check back shortly!`, ephemeral: true });
1556
  }