1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-12-27 04:15:38 -05:00

Discord decided that the bot shouldn't view it

This commit is contained in:
toast-ts 2024-07-23 11:15:13 +10:00
parent b5c9de9df8
commit 9b49f88901
2 changed files with 20 additions and 5 deletions

View File

@ -51,7 +51,8 @@ export default class TClient extends Discord.Client {
Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMembers, Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildModeration, Discord.GatewayIntentBits.GuildInvites, Discord.GatewayIntentBits.GuildModeration, Discord.GatewayIntentBits.GuildInvites,
Discord.GatewayIntentBits.GuildPresences, Discord.GatewayIntentBits.MessageContent, Discord.GatewayIntentBits.GuildPresences, Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.DirectMessages Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.DirectMessages,
Discord.GatewayIntentBits.GuildMessageReactions
], ],
partials: [ partials: [
Discord.Partials.Message, Discord.Partials.Channel Discord.Partials.Message, Discord.Partials.Channel

View File

@ -157,20 +157,34 @@ export default class MP {
} }
const msg_id = interaction.options.getString('message_id', true); const msg_id = interaction.options.getString('message_id', true);
const stripUrl = msg_id.replace(/https:\/\/discord.com\/channels\/\d+\/\d+\/(\d+)/, '$1'); 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) 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].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!'); 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( (client.channels.cache.get(client.config.dcServer.channels.mpmod_chat) as Discord.TextChannel).send({files: [new client.attachment(
Buffer.from(JSON.stringify({ Buffer.from(JSON.stringify({
map_names: msg.embeds[0].description.split('\n').map(x=>x.slice(3).replace(/\*\*/g, '')), map_names: msg.embeds[0].description.split('\n').map(x=>x.slice(3).replace(/\*\*/g, '').trim()),
votes: msg.reactions.cache.map(x=>x.count) votes: filterByDigits.map(x=>x.count)
}, null, 2)), {name: `pollResults-${msg.id}.json`}) }, 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](<https://discord.com/channels/${interaction.guildId}/${MPChannels.announcements}/${msg.id}>) in <#${MPChannels.announcements}>`) await interaction.reply(`Successfully ended the [poll](<https://discord.com/channels/${interaction.guildId}/${MPChannels.announcements}/${msg.id}>) in <#${MPChannels.announcements}>`)
}, },
maps: async()=>{ maps: async()=>{