Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasB25 committed Aug 27, 2024
1 parent 8e12b72 commit 896ac8b
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 147 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/events/client/InteractionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
282 changes: 139 additions & 143 deletions src/events/client/MessageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ButtonBuilder>().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<ButtonBuilder>().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 {
Expand Down

0 comments on commit 896ac8b

Please sign in to comment.