From 556401bc12e7dfbf9a54aae603197ef2b4268d79 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Tue, 23 Jul 2024 11:15:13 +1000 Subject: [PATCH] Discord decided that the bot shouldn't view it --- src/client.ts | 3 ++- src/commands/mp.ts | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/client.ts b/src/client.ts index f500781..8b925dd 100644 --- a/src/client.ts +++ b/src/client.ts @@ -51,7 +51,8 @@ export default class TClient extends Discord.Client { Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMembers, Discord.GatewayIntentBits.GuildModeration, Discord.GatewayIntentBits.GuildInvites, Discord.GatewayIntentBits.GuildPresences, Discord.GatewayIntentBits.MessageContent, - Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.DirectMessages + Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.DirectMessages, + Discord.GatewayIntentBits.GuildMessageReactions ], partials: [ Discord.Partials.Message, Discord.Partials.Channel diff --git a/src/commands/mp.ts b/src/commands/mp.ts index c75075b..5f79ad2 100644 --- a/src/commands/mp.ts +++ b/src/commands/mp.ts @@ -6,7 +6,7 @@ import CanvasBuilder from '../components/CanvasBuilder.js'; import RanIntoHumor from '../helpers/RanIntoHumor.js'; import MessageTool from '../helpers/MessageTool.js'; import {FSData} from 'src/interfaces'; -import {requestServerData, mpModuleDisabled, refreshTimerSecs, playtimeStat, MPChannels} from '../modules/MPModule.js'; +import {requestServerData, mpModuleDisabled, /* refreshTimerSecs, */ playtimeStat, MPChannels} from '../modules/MPModule.js'; async function fetchData(client:TClient, interaction:Discord.ChatInputCommandInteraction, serverName:string):Promise { try { @@ -31,7 +31,7 @@ export default class MP { } static async run(client:TClient, interaction:Discord.ChatInputCommandInteraction<'cached'>) { if (client.config.botSwitches.mpSys === false) return interaction.reply({embeds: [mpModuleDisabled(client)]}); - if (client.uptime < refreshTimerSecs) return interaction.reply('MPModule isn\'t initialized yet, please wait a moment and try again.'); + // if (client.uptime < refreshTimerSecs) return interaction.reply('MPModule isn\'t initialized yet, please wait a moment and try again.'); if ([MPChannels.mainMpChat, client.config.dcServer.channels.multifarm_chat].includes(interaction.channelId) && !MessageTool.isStaff(interaction.member) && ['status', 'players'].includes(interaction.options.getSubcommand())) return interaction.reply(`Please use <#${MPChannels.activePlayers}> for \`/mp status/players\` commands to prevent clutter in this channel.`).then(()=>setTimeout(()=>interaction.deleteReply(), 6000)); const choiceSelector = interaction.options.getString('server'); ({ @@ -157,20 +157,34 @@ export default class MP { } const msg_id = interaction.options.getString('message_id', true); const stripUrl = msg_id.replace(/https:\/\/discord.com\/channels\/\d+\/\d+\/(\d+)/, '$1'); - const msg = await (interaction.guild.channels.cache.get(MPChannels.announcements) as Discord.TextChannel).messages.fetch(stripUrl).catch(()=>null); + const msg: Discord.Message = await (interaction.guild.channels.cache.get(MPChannels.announcements) as Discord.TextChannel).messages.fetch(stripUrl).catch(()=>null); if (!msg) return interaction.reply('Message not found, please make sure you have the correct message ID.'); if (msg.embeds[0].title !== 'Vote for next map!') return interaction.reply('This message is not a poll!'); if (msg.embeds[0].footer?.text?.startsWith('Poll ended by')) return interaction.reply('This poll has already ended!'); + const validEmojis = ['1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣','🔟']; + const filterByDigits = msg.reactions.cache.filter(x=>validEmojis.includes(x.emoji.name)); + (client.channels.cache.get(client.config.dcServer.channels.mpmod_chat) as Discord.TextChannel).send({files: [new client.attachment( Buffer.from(JSON.stringify({ - map_names: msg.embeds[0].description.split('\n').map(x=>x.slice(3).replace(/\*\*/g, '')), - votes: msg.reactions.cache.map(x=>x.count) + map_names: msg.embeds[0].description.split('\n').map(x=>x.slice(3).replace(/\*\*/g, '').trim()), + votes: filterByDigits.map(x=>x.count) }, null, 2)), {name: `pollResults-${msg.id}.json`}) ]}); - msg.edit({content: null, embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Voting has ended!').setDescription('The next map will be '+msg.embeds[0].description.split('\n')[msg.reactions.cache.map(x=>x.count).indexOf(Math.max(...msg.reactions.cache.map(x=>x.count)))].slice(3)).setFooter({text: `Poll ended by ${interaction.user.tag}`, iconURL: interaction.member.displayAvatarURL({extension: 'webp', size: 1024})})]}).then(()=>msg.reactions.removeAll()); + const map_index = msg.reactions.cache.map(x=>x.count).indexOf(Math.max(...msg.reactions.cache.map(x=>x.count))); + const next_map = msg.embeds[0].description.split('\n')[map_index].slice(3); + + msg.edit({ + content: null, + embeds: [new client.embed() + .setColor(client.config.embedColor) + .setTitle('Voting has ended!') + .setDescription(`The next map will be ${next_map}`) + .setFooter({text: `Poll ended by ${interaction.user.tag}`, iconURL: interaction.member.displayAvatarURL({extension: 'webp', size: 1024})}) + ] + }).then(()=>msg.reactions.removeAll()); await interaction.reply(`Successfully ended the [poll]() in <#${MPChannels.announcements}>`) }, maps: async()=>{