From 8b9392d97a18f4d7dac202041595e9e1ad69e64c Mon Sep 17 00:00:00 2001 From: GramingFoxTeam Date: Sun, 13 Aug 2023 19:32:53 +0300 Subject: [PATCH] fix(bot-discord): fix shit yea --- apps/bot-discord/src/commands/ban.js | 2 +- apps/bot-discord/src/commands/exile.js | 8 ++++--- .../src/commands/exileMemberCtx.js | 7 ++++-- apps/bot-discord/src/commands/mute.js | 8 ++++--- apps/bot-discord/src/commands/unexile.js | 5 ++-- apps/bot-discord/src/commands/unmute.js | 5 ++-- apps/bot-discord/src/events/ready.js | 2 +- apps/bot-discord/src/msgCommands/exile.js | 7 +++--- .../src/utils/exileMemberToChannel.js | 2 +- apps/bot-discord/src/utils/muteMember.js | 24 +++++++++---------- apps/bot-discord/src/utils/setMuteTimeout.js | 4 ++-- 11 files changed, 41 insertions(+), 33 deletions(-) diff --git a/apps/bot-discord/src/commands/ban.js b/apps/bot-discord/src/commands/ban.js index 85bb8c9..5ca51c3 100644 --- a/apps/bot-discord/src/commands/ban.js +++ b/apps/bot-discord/src/commands/ban.js @@ -37,7 +37,7 @@ export default { reportToLogs(config, interaction.client, 'banned', null, { reason: interaction.options.getString('reason'), - actionTo: await client.users.fetch(interaction.options.getUser('user')), + actionTo: interaction.options.getUser('user'), actionBy: interaction.member, channel: interaction.channel }, interaction); diff --git a/apps/bot-discord/src/commands/exile.js b/apps/bot-discord/src/commands/exile.js index 8db04d0..8c6a860 100644 --- a/apps/bot-discord/src/commands/exile.js +++ b/apps/bot-discord/src/commands/exile.js @@ -29,19 +29,21 @@ export default { await interaction.deferReply(); - const member = interaction.options.getUser('user'); + const user = interaction.options.getUser('user'); + const member = await interaction.guild.members.fetch(user); const reason = interaction.options.getString('reason'); const parsedDuration = await muteMember(config, member, { reason, - supportMute: true + supportMute: true, + guild: interaction.guild }); exileMemberToChannel(member, interaction.channel, null, config, true); reportToLogs(config, interaction.client, 'muted', null, { reason, - actionTo: await client.users.fetch(interaction.options.getString('user')), + actionTo: user, actionBy: interaction.member, channel: interaction.channel, expire: parsedDuration diff --git a/apps/bot-discord/src/commands/exileMemberCtx.js b/apps/bot-discord/src/commands/exileMemberCtx.js index b951312..bbab464 100644 --- a/apps/bot-discord/src/commands/exileMemberCtx.js +++ b/apps/bot-discord/src/commands/exileMemberCtx.js @@ -17,10 +17,13 @@ export default { }); const targetMsg = interaction.targetMessage; - muteMember(config, targetMsg.author, { + + const member = await interaction.guild.members.fetch(targetMsg.author.id); + muteMember(config, member, { channel: interaction.channel, reason: null, - supportMute: true + supportMute: true, + guild: interaction.guild }); exileMemberToChannel(targetMsg.author, interaction.channel, targetMsg.content, config, true); diff --git a/apps/bot-discord/src/commands/mute.js b/apps/bot-discord/src/commands/mute.js index 3304592..6a4b9a0 100644 --- a/apps/bot-discord/src/commands/mute.js +++ b/apps/bot-discord/src/commands/mute.js @@ -34,18 +34,20 @@ export default { await interaction.deferReply(); - const member = interaction.options.getUser('user'); + const user = interaction.options.getUser('user'); + const member = await interaction.guild.members.fetch(user); const reason = interaction.options.getString('reason'); const parsedDuration = await muteMember(config, member, { duration: interaction.options.getString('duration'), reason, - supportMute: false + supportMute: false, + guild: interaction.guild }); reportToLogs(config, interaction.client, 'muted', null, { reason, - actionTo: member, + actionTo: user, actionBy: interaction.member, channel: interaction.channel, expire: parsedDuration diff --git a/apps/bot-discord/src/commands/unexile.js b/apps/bot-discord/src/commands/unexile.js index 6d0d806..afd7790 100644 --- a/apps/bot-discord/src/commands/unexile.js +++ b/apps/bot-discord/src/commands/unexile.js @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from 'discord.js'; -import { checkForPerms } from '../utils/checkModPerms.js'; +import { checkForPerms } from '../utils/checkSupporterPerms.js'; import reportToLogs from '../utils/reportToLogs.js'; import unmuteMember from '../utils/unmuteMember.js'; @@ -23,7 +23,6 @@ export default { await interaction.deferReply(); const member = interaction.options.getUser('user'); - const isExiled = await unmuteMember(config, member, true); if (!isExiled) { @@ -36,7 +35,7 @@ export default { reportToLogs(config, interaction.client, 'unmuted', null, { reason: null, - actionTo: await client.users.fetch(interaction.options.getString('user')), + actionTo: member, actionBy: interaction.member, channel: interaction.channel, }, interaction); diff --git a/apps/bot-discord/src/commands/unmute.js b/apps/bot-discord/src/commands/unmute.js index b58cfa0..cb554d5 100644 --- a/apps/bot-discord/src/commands/unmute.js +++ b/apps/bot-discord/src/commands/unmute.js @@ -22,8 +22,9 @@ export default { await interaction.deferReply(); - const member = interaction.options.getUser('user'); + const user = interaction.options.getUser('user'); + const member = await interaction.guild.members.fetch(user); const isMuted = await unmuteMember(config, member); if (!isMuted) { @@ -36,7 +37,7 @@ export default { reportToLogs(config, interaction.client, 'unmuted', null, { reason: null, - actionTo: await client.users.fetch(interaction.options.getString('user')), + actionTo: member, actionBy: interaction.member, channel: interaction.channel, }, interaction); diff --git a/apps/bot-discord/src/events/ready.js b/apps/bot-discord/src/events/ready.js index 6a018f4..dd7337e 100644 --- a/apps/bot-discord/src/events/ready.js +++ b/apps/bot-discord/src/events/ready.js @@ -10,7 +10,7 @@ export default { const mutes = await client.db.collection('muted').find().toArray(); for (const mute of mutes) { - await setMuteTimeout(mute, client.mutes, client); + await setMuteTimeout(mute, client, config); } console.log(`Loaded ${mutes.length} mutes.`); diff --git a/apps/bot-discord/src/msgCommands/exile.js b/apps/bot-discord/src/msgCommands/exile.js index 4954b6d..113a3c1 100644 --- a/apps/bot-discord/src/msgCommands/exile.js +++ b/apps/bot-discord/src/msgCommands/exile.js @@ -10,7 +10,7 @@ export default { if (!msg.reference) return msg.reply('You did not reply to anyone!'); const referencedMsg = await msg.channel.messages.fetch(msg.reference.messageId); let message = referencedMsg.content; - if (args[0]) { + if (args && args[0]) { if (isNaN(args[0])) return msg.reply('The argument you entered is not a number!'); const msgsByAuthor = (await msg.channels.fetch({ limit: 50 })).filter( @@ -19,8 +19,9 @@ export default { message = msgsByAuthor.slice(Number(`-${args[0]}`)); } - await muteMember(config, referencedMsg.author, { - supportMute: true + await muteMember(config, referencedMsg.member, { + supportMute: true, + guild: msg.guild }); exileMemberToChannel(referencedMsg.author, msg.channel, message, config, false); diff --git a/apps/bot-discord/src/utils/exileMemberToChannel.js b/apps/bot-discord/src/utils/exileMemberToChannel.js index db6e794..26b480d 100644 --- a/apps/bot-discord/src/utils/exileMemberToChannel.js +++ b/apps/bot-discord/src/utils/exileMemberToChannel.js @@ -34,7 +34,7 @@ export default async function exileMemberToChannel(member, channel, message, con ] }; - if (isSlash) channel.reply(messageParams); + if (isSlash) channel.editReply(messageParams); else channel.send(messageParams); } \ No newline at end of file diff --git a/apps/bot-discord/src/utils/muteMember.js b/apps/bot-discord/src/utils/muteMember.js index fda341d..46c90ba 100644 --- a/apps/bot-discord/src/utils/muteMember.js +++ b/apps/bot-discord/src/utils/muteMember.js @@ -3,7 +3,7 @@ import setMuteTimeout from './setMuteTimeout.js'; parse['mo'] = parse['month'] -export default async function muteMember(config, member, { duration, reason, supportMute }) { +export default async function muteMember(config, member, { duration, reason, supportMute, guild }) { let expires; if (supportMute) { @@ -23,16 +23,16 @@ export default async function muteMember(config, member, { duration, reason, sup } } - const existingMute = await member.client.db.collection('muted').findOne({ - guild_id: member.guild.id, + const existingMute = await guild.client.db.collection('muted').findOne({ + guild_id: guild.id, user_id: member.id }); if (existingMute) { // Update existing mute - await member.client.db.collection('muted').updateOne({ - guild_id: member.guild.id, + await guild.client.db.collection('muted').updateOne({ + guild_id: guild.id, user_id: member.id }, { $set: { @@ -42,13 +42,13 @@ export default async function muteMember(config, member, { duration, reason, sup } }); - if (member.client.mutes.has(member.id)) { - clearTimeout(member.client.mutes.get(member.id)) - member.client.mutes.delete(member.id); + if (guild.client.mutes.has(member.id)) { + clearTimeout(guild.client.mutes.get(member.id)) + guild.client.mutes.delete(member.id); } } else { - await member.client.db.collection('muted').insertOne({ - guild_id: member.guild.id, + await guild.client.db.collection('muted').insertOne({ + guild_id: guild.id, user_id: member.id, taken_roles: takenRoles, expires, @@ -75,12 +75,12 @@ export default async function muteMember(config, member, { duration, reason, sup // Start a timeout. setMuteTimeout({ - guild_id: member.guild.id, + guild_id: guild.id, user_id: member.id, taken_roles: takenRoles, expires, support_mute: supportMute - }, member.client.mutes, member.client, config); + }, guild.client, config); // Return parsed time for the mute command to resolve. return expires; diff --git a/apps/bot-discord/src/utils/setMuteTimeout.js b/apps/bot-discord/src/utils/setMuteTimeout.js index 00755e7..415638d 100644 --- a/apps/bot-discord/src/utils/setMuteTimeout.js +++ b/apps/bot-discord/src/utils/setMuteTimeout.js @@ -1,6 +1,6 @@ -export default async function setMuteTimeout(mute, mutes, client, config) { +export default async function setMuteTimeout(mute, client, config) { const duration = (mute.expires - Math.floor(new Date() / 1000)) * 1000; - mutes.set(mute.user_id, setTimeout(async() => { + client.mutes.set(mute.user_id, setTimeout(async() => { const guild = await client.guilds.fetch(mute.guild_id); let member; try {