From 896ac8b1351660d6cd743df3b586ea1e67364d4a Mon Sep 17 00:00:00 2001 From: LucasB25 <50886682+LucasB25@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:22:57 +0200 Subject: [PATCH] fix --- package.json | 4 +- src/events/client/InteractionCreate.ts | 4 +- src/events/client/MessageCreate.ts | 282 ++++++++++++------------- 3 files changed, 143 insertions(+), 147 deletions(-) diff --git a/package.json b/package.json index 47c215e53..285f08439 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,11 @@ "@types/i18n": "^0.13.12", "@types/node": "^22.5.0", "@types/signale": "^1.4.7", - "prisma": "^5.18.0", + "prisma": "^5.19.0", "typescript": "^5.5.4" }, "dependencies": { - "@prisma/client": "^5.18.0", + "@prisma/client": "^5.19.0", "@top-gg/sdk": "^3.1.6", "discord.js": "^14.15.3", "dotenv": "^16.4.5", diff --git a/src/events/client/InteractionCreate.ts b/src/events/client/InteractionCreate.ts index 439f75035..04657355a 100644 --- a/src/events/client/InteractionCreate.ts +++ b/src/events/client/InteractionCreate.ts @@ -73,7 +73,7 @@ export default class InteractionCreate extends Event { const logs = this.client.channels.cache.get(this.client.config.commandLogs); if (command.permissions) { - if (command.permissions.client) { + if (command.permissions?.client) { const missingClientPermissions = command.permissions.client.filter((perm) => !clientMember.permissions.has(perm)); if (missingClientPermissions.length > 0) { @@ -86,7 +86,7 @@ export default class InteractionCreate extends Event { } } - if (command.permissions.user && !(interaction.member as GuildMember).permissions.has(command.permissions.user)) { + if (command.permissions?.user && !(interaction.member as GuildMember).permissions.has(command.permissions.user)) { await interaction.reply({ content: T(locale, "event.interaction.no_user_permission"), ephemeral: true, diff --git a/src/events/client/MessageCreate.ts b/src/events/client/MessageCreate.ts index b138fb70b..86e56e5f1 100644 --- a/src/events/client/MessageCreate.ts +++ b/src/events/client/MessageCreate.ts @@ -54,185 +54,181 @@ export default class MessageCreate extends Event { ctx.setArgs(args); ctx.guildLocale = locale; - const isDev = this.client.config.owners?.includes(message.author.id); + const clientMember = message.guild.members.resolve(this.client.user); + if (!(message.inGuild() && message.channel.permissionsFor(clientMember)?.has(PermissionFlagsBits.ViewChannel))) return; - if (!isDev) { - const clientMember = message.guild.members.resolve(this.client.user); - if (!(message.inGuild() && message.channel.permissionsFor(clientMember)?.has(PermissionFlagsBits.ViewChannel))) return; + if ( + !( + clientMember.permissions.has(PermissionFlagsBits.ViewChannel) && + clientMember.permissions.has(PermissionFlagsBits.SendMessages) && + clientMember.permissions.has(PermissionFlagsBits.EmbedLinks) && + clientMember.permissions.has(PermissionFlagsBits.ReadMessageHistory) + ) + ) { + return await message.author + .send({ + content: T(locale, "event.message.no_send_message", { + guild: message.guild.name, + channel: `<#${message.channelId}>`, + }), + }) + .catch(() => {}); + } - if ( - !( - clientMember.permissions.has(PermissionFlagsBits.ViewChannel) && - clientMember.permissions.has(PermissionFlagsBits.SendMessages) && - clientMember.permissions.has(PermissionFlagsBits.EmbedLinks) && - clientMember.permissions.has(PermissionFlagsBits.ReadMessageHistory) - ) - ) { - return await message.author - .send({ - content: T(locale, "event.message.no_send_message", { - guild: message.guild.name, - channel: `<#${message.channelId}>`, + if (command.permissions) { + if (command.permissions?.client) { + const missingClientPermissions = command.permissions.client.filter((perm) => !clientMember.permissions.has(perm)); + + if (missingClientPermissions.length > 0) { + return await message.reply({ + content: T(locale, "event.message.no_permission", { + permissions: missingClientPermissions.map((perm) => `\`${perm}\``).join(", "), }), - }) - .catch(() => {}); + }); + } + } + + if (command.permissions?.user && !(message.member as GuildMember).permissions.has(command.permissions.user)) { + return await message.reply({ + content: T(locale, "event.message.no_user_permission"), + }); } - if (command.permissions) { - if (command.permissions.client) { - const missingClientPermissions = command.permissions.client.filter((perm) => !clientMember.permissions.has(perm)); + if (command.permissions.dev && this.client.config.owners) { + const isDev = this.client.config.owners.includes(message.author.id); + if (!isDev) return; + } + } - if (missingClientPermissions.length > 0) { - return await message.reply({ - content: T(locale, "event.message.no_permission", { - permissions: missingClientPermissions.map((perm) => `\`${perm}\``).join(", "), - }), - }); - } + if (command.vote && this.client.config.topGG) { + const voted = await this.client.topGG.hasVoted(message.author.id); + if (!voted) { + const voteBtn = new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setLabel("Vote for Me!") + .setURL(`https://top.gg/bot/${this.client.config.clientId}/vote`) + .setStyle(ButtonStyle.Link), + ); + + return await message.reply({ + content: "Wait! Before using this command, you must vote on top.gg. Thank you.", + components: [voteBtn], + }); + } + } + + if (command.player) { + if (command.player.voice) { + if (!(message.member as GuildMember).voice.channel) { + return await message.reply({ + content: T(locale, "event.message.no_voice_channel", { command: command.name }), + }); } - if (command.permissions.user && !(message.member as GuildMember).permissions.has(command.permissions.user)) { + if (!clientMember.permissions.has(PermissionFlagsBits.Connect)) { return await message.reply({ - content: T(locale, "event.message.no_user_permission"), + content: T(locale, "event.message.no_connect_permission", { command: command.name }), }); } - if (command.permissions.dev && this.client.config.owners) { - const isDev = this.client.config.owners.includes(message.author.id); - if (!isDev) return; + if (!clientMember.permissions.has(PermissionFlagsBits.Speak)) { + return await message.reply({ + content: T(locale, "event.message.no_speak_permission", { command: command.name }), + }); } - } - if (command.vote && this.client.config.topGG) { - const voted = await this.client.topGG.hasVoted(message.author.id); - if (!voted) { - const voteBtn = new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setLabel("Vote for Me!") - .setURL(`https://top.gg/bot/${this.client.config.clientId}/vote`) - .setStyle(ButtonStyle.Link), - ); + if ( + (message.member as GuildMember).voice.channel.type === ChannelType.GuildStageVoice && + !clientMember.permissions.has(PermissionFlagsBits.RequestToSpeak) + ) { + return await message.reply({ + content: T(locale, "event.message.no_request_to_speak", { command: command.name }), + }); + } + if (clientMember.voice.channel && clientMember.voice.channelId !== (message.member as GuildMember).voice.channelId) { return await message.reply({ - content: "Wait! Before using this command, you must vote on top.gg. Thank you.", - components: [voteBtn], + content: T(locale, "event.message.different_voice_channel", { + channel: `<#${clientMember.voice.channelId}>`, + command: command.name, + }), }); } } - if (command.player) { - if (command.player.voice) { - if (!(message.member as GuildMember).voice.channel) { - return await message.reply({ - content: T(locale, "event.message.no_voice_channel", { command: command.name }), - }); - } - - if (!clientMember.permissions.has(PermissionFlagsBits.Connect)) { - return await message.reply({ - content: T(locale, "event.message.no_connect_permission", { command: command.name }), - }); - } - - if (!clientMember.permissions.has(PermissionFlagsBits.Speak)) { - return await message.reply({ - content: T(locale, "event.message.no_speak_permission", { command: command.name }), - }); - } - - if ( - (message.member as GuildMember).voice.channel.type === ChannelType.GuildStageVoice && - !clientMember.permissions.has(PermissionFlagsBits.RequestToSpeak) - ) { - return await message.reply({ - content: T(locale, "event.message.no_request_to_speak", { command: command.name }), - }); - } + if (command.player.active) { + const queue = this.client.queue.get(message.guildId); + if (!(queue?.queue && queue.current)) { + return await message.reply({ + content: T(locale, "event.message.no_music_playing"), + }); + } + } - if (clientMember.voice.channel && clientMember.voice.channelId !== (message.member as GuildMember).voice.channelId) { + if (command.player.dj) { + const dj = await this.client.db.getDj(message.guildId); + if (dj?.mode) { + const djRole = await this.client.db.getRoles(message.guildId); + if (!djRole) { return await message.reply({ - content: T(locale, "event.message.different_voice_channel", { - channel: `<#${clientMember.voice.channelId}>`, - command: command.name, - }), + content: T(locale, "event.message.no_dj_role"), }); } - } - if (command.player.active) { - const queue = this.client.queue.get(message.guildId); - if (!(queue?.queue && queue.current)) { + const hasDJRole = (message.member as GuildMember).roles.cache.some((role) => + djRole.map((r) => r.roleId).includes(role.id), + ); + if (!(hasDJRole && !(message.member as GuildMember).permissions.has(PermissionFlagsBits.ManageGuild))) { return await message.reply({ - content: T(locale, "event.message.no_music_playing"), + content: T(locale, "event.message.no_dj_permission"), }); } } - - if (command.player.dj) { - const dj = await this.client.db.getDj(message.guildId); - if (dj?.mode) { - const djRole = await this.client.db.getRoles(message.guildId); - if (!djRole) { - return await message.reply({ - content: T(locale, "event.message.no_dj_role"), - }); - } - - const hasDJRole = (message.member as GuildMember).roles.cache.some((role) => - djRole.map((r) => r.roleId).includes(role.id), - ); - if (!(hasDJRole && !(message.member as GuildMember).permissions.has(PermissionFlagsBits.ManageGuild))) { - return await message.reply({ - content: T(locale, "event.message.no_dj_permission"), - }); - } - } - } - } - - if (command.args && !args.length) { - const embed = this.client - .embed() - .setColor(this.client.color.red) - .setTitle(T(locale, "event.message.missing_arguments")) - .setDescription( - T(locale, "event.message.missing_arguments_description", { - command: command.name, - examples: command.description.examples ? command.description.examples.join("\n") : "None", - }), - ) - .setFooter({ text: T(locale, "event.message.syntax_footer") }); - await message.reply({ embeds: [embed] }); - return; } + } - if (!this.client.cooldown.has(cmd)) { - this.client.cooldown.set(cmd, new Collection()); - } - const now = Date.now(); - const timestamps = this.client.cooldown.get(cmd)!; - const cooldownAmount = (command.cooldown || 5) * 1000; + if (command.args && !args.length) { + const embed = this.client + .embed() + .setColor(this.client.color.red) + .setTitle(T(locale, "event.message.missing_arguments")) + .setDescription( + T(locale, "event.message.missing_arguments_description", { + command: command.name, + examples: command.description.examples ? command.description.examples.join("\n") : "None", + }), + ) + .setFooter({ text: T(locale, "event.message.syntax_footer") }); + await message.reply({ embeds: [embed] }); + return; + } - if (timestamps.has(message.author.id)) { - const expirationTime = timestamps.get(message.author.id)! + cooldownAmount; - const timeLeft = (expirationTime - now) / 1000; - if (now < expirationTime && timeLeft > 0.9) { - return await message.reply({ - content: T(locale, "event.message.cooldown", { time: timeLeft.toFixed(1), command: cmd }), - }); - } - timestamps.set(message.author.id, now); - setTimeout(() => timestamps.delete(message.author.id), cooldownAmount); - } else { - timestamps.set(message.author.id, now); - setTimeout(() => timestamps.delete(message.author.id), cooldownAmount); - } + if (!this.client.cooldown.has(cmd)) { + this.client.cooldown.set(cmd, new Collection()); + } + const now = Date.now(); + const timestamps = this.client.cooldown.get(cmd)!; + const cooldownAmount = (command.cooldown || 5) * 1000; - if (args.includes("@everyone") || args.includes("@here")) { + if (timestamps.has(message.author.id)) { + const expirationTime = timestamps.get(message.author.id)! + cooldownAmount; + const timeLeft = (expirationTime - now) / 1000; + if (now < expirationTime && timeLeft > 0.9) { return await message.reply({ - content: T(locale, "event.message.no_mention_everyone"), + content: T(locale, "event.message.cooldown", { time: timeLeft.toFixed(1), command: cmd }), }); } + timestamps.set(message.author.id, now); + setTimeout(() => timestamps.delete(message.author.id), cooldownAmount); + } else { + timestamps.set(message.author.id, now); + setTimeout(() => timestamps.delete(message.author.id), cooldownAmount); + } + + if (args.includes("@everyone") || args.includes("@here")) { + return await message.reply({ + content: T(locale, "event.message.no_mention_everyone"), + }); } try {