Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Now, developers can bypass all permissions on the server.
  • Loading branch information
hwangsihu committed Aug 11, 2024
1 parent 72bee2b commit 72c4943
Showing 1 changed file with 144 additions and 142 deletions.
286 changes: 144 additions & 142 deletions src/events/client/MessageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ButtonBuilder>().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<ButtonBuilder>().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 {
Expand All @@ -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({
Expand Down

0 comments on commit 72c4943

Please sign in to comment.