From 72c49439ef3768061a7ae21d9f1c8ca8cd36a91b Mon Sep 17 00:00:00 2001 From: hwangsihu Date: Mon, 12 Aug 2024 01:08:54 +0900 Subject: [PATCH] Update Now, developers can bypass all permissions on the server. --- src/events/client/MessageCreate.ts | 286 +++++++++++++++-------------- 1 file changed, 144 insertions(+), 142 deletions(-) diff --git a/src/events/client/MessageCreate.ts b/src/events/client/MessageCreate.ts index 3bafa99e8..3306e87ec 100644 --- a/src/events/client/MessageCreate.ts +++ b/src/events/client/MessageCreate.ts @@ -52,195 +52,196 @@ export default class MessageCreate extends Event { const ctx = new Context(message, args); ctx.setArgs(args); ctx.guildLocale = locale; - if (!message.guild.members.resolve(this.client.user)?.permissions.has(PermissionFlagsBits.ViewChannel)) return; - const clientMember = message.guild.members.resolve(this.client.user); - if (!clientMember.permissions.has(PermissionFlagsBits.SendMessages)) { - await message.author - .send({ - content: T(locale, "event.message.no_send_message", { - guild: message.guild.name, - channel: `<#${message.channelId}>`, - }), - }) - .catch(() => {}); - return; - } + const isDev = this.client.config.owners?.includes(message.author.id); - if (!clientMember.permissions.has(PermissionFlagsBits.EmbedLinks)) { - await message.reply({ - content: T(locale, "event.message.no_embed_links"), - }); - return; - } + if (!isDev) { + if (!message.guild.members.resolve(this.client.user)?.permissions.has(PermissionFlagsBits.ViewChannel)) return; - const logs = this.client.channels.cache.get(this.client.config.commandLogs); - - if (command.permissions) { - if (command.permissions.client && !clientMember.permissions.has(command.permissions.client)) { - await message.reply({ - content: T(locale, "event.message.no_permission"), - }); + const clientMember = message.guild.members.resolve(this.client.user); + if (!clientMember.permissions.has(PermissionFlagsBits.SendMessages)) { + await message.author + .send({ + content: T(locale, "event.message.no_send_message", { + guild: message.guild.name, + channel: `<#${message.channelId}>`, + }), + }) + .catch(() => {}); return; } - if (command.permissions.user && !message.member.permissions.has(command.permissions.user)) { + if (!clientMember.permissions.has(PermissionFlagsBits.EmbedLinks)) { await message.reply({ - content: T(locale, "event.message.no_user_permission"), + content: T(locale, "event.message.no_embed_links"), }); return; } - if (command.permissions.dev && this.client.config.owners) { - const isDev = this.client.config.owners.includes(message.author.id); - if (!isDev) return; - } - } - 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), - ); - - 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.voice.channel) { + if (command.permissions) { + if (command.permissions.client && !clientMember.permissions.has(command.permissions.client)) { await message.reply({ - content: T(locale, "event.message.no_voice_channel", { - command: command.name, - }), + content: T(locale, "event.message.no_permission"), }); return; } - if (!clientMember.permissions.has(PermissionFlagsBits.Connect)) { + if (command.permissions.user && !message.member.permissions.has(command.permissions.user)) { await message.reply({ - content: T(locale, "event.message.no_connect_permission", { command: command.name }), - }); - return; - } - - if (!clientMember.permissions.has(PermissionFlagsBits.Speak)) { - await message.reply({ - content: T(locale, "event.message.no_speak_permission", { command: command.name }), + content: T(locale, "event.message.no_user_permission"), }); return; } + } - if ( - message.member.voice.channel.type === ChannelType.GuildStageVoice && - !clientMember.permissions.has(PermissionFlagsBits.RequestToSpeak) - ) { - await message.reply({ - content: T(locale, "event.message.no_request_to_speak", { command: command.name }), - }); - return; - } + 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 (clientMember.voice.channel && clientMember.voice.channelId !== message.member.voice.channelId) { await message.reply({ - content: T(locale, "event.message.different_voice_channel", { - channel: `<#${clientMember.voice.channelId}>`, - command: command.name, - }), + content: "Wait! Before using this command, you must vote on top.gg. Thank you.", + components: [voteBtn], }); return; } } - if (command.player.active) { - const queue = this.client.queue.get(message.guildId); - if (!queue?.queue && queue.current) { - await message.reply({ - content: T(locale, "event.message.no_music_playing"), - }); - return; + if (command.player) { + if (command.player.voice) { + if (!message.member.voice.channel) { + await message.reply({ + content: T(locale, "event.message.no_voice_channel", { + command: command.name, + }), + }); + return; + } + + if (!clientMember.permissions.has(PermissionFlagsBits.Connect)) { + await message.reply({ + content: T(locale, "event.message.no_connect_permission", { command: command.name }), + }); + return; + } + + if (!clientMember.permissions.has(PermissionFlagsBits.Speak)) { + await message.reply({ + content: T(locale, "event.message.no_speak_permission", { command: command.name }), + }); + return; + } + + if ( + message.member.voice.channel.type === ChannelType.GuildStageVoice && + !clientMember.permissions.has(PermissionFlagsBits.RequestToSpeak) + ) { + await message.reply({ + content: T(locale, "event.message.no_request_to_speak", { command: command.name }), + }); + return; + } + + if (clientMember.voice.channel && clientMember.voice.channelId !== message.member.voice.channelId) { + await message.reply({ + content: T(locale, "event.message.different_voice_channel", { + channel: `<#${clientMember.voice.channelId}>`, + command: command.name, + }), + }); + return; + } } - } - 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) { + if (command.player.active) { + const queue = this.client.queue.get(message.guildId); + if (!queue?.queue && queue.current) { await message.reply({ - content: T(locale, "event.message.no_dj_role"), + content: T(locale, "event.message.no_music_playing"), }); return; } - const findDJRole = message.member.roles.cache.find((x: any) => djRole.map((y: any) => y.roleId).includes(x.id)); - if (!findDJRole) { - if (!message.member.permissions.has(PermissionFlagsBits.ManageGuild)) { - await message - .reply({ - content: T(locale, "event.message.no_dj_permission"), - }) - .then((msg) => setTimeout(() => msg.delete(), 5000)); + } + + 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) { + await message.reply({ + content: T(locale, "event.message.no_dj_role"), + }); return; } + const findDJRole = message.member.roles.cache.find((x: any) => djRole.map((y: any) => y.roleId).includes(x.id)); + if (!findDJRole) { + if (!message.member.permissions.has(PermissionFlagsBits.ManageGuild)) { + await message + .reply({ + content: T(locale, "event.message.no_dj_permission"), + }) + .then((msg) => setTimeout(() => msg.delete(), 5000)); + return; + } + } } } } - } - 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 (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()); - } + 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; + const now = Date.now(); + const timestamps = this.client.cooldown.get(cmd)!; + const cooldownAmount = (command.cooldown || 5) * 1000; - 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) { + 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) { + await message.reply({ + content: T(locale, "event.message.cooldown", { + time: timeLeft.toFixed(1), + command: cmd, + }), + }); + return; + } + 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")) { await message.reply({ - content: T(locale, "event.message.cooldown", { - time: timeLeft.toFixed(1), - command: cmd, - }), + content: T(locale, "event.message.no_mention_everyone"), }); return; } - 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")) { - await message.reply({ - content: T(locale, "event.message.no_mention_everyone"), - }); - return; } try { @@ -251,6 +252,7 @@ export default class MessageCreate extends Event { content: T(locale, "event.message.error", { error }), }); } finally { + const logs = this.client.channels.cache.get(this.client.config.commandLogs); if (logs) { const embed = new EmbedBuilder() .setAuthor({