fix quote deletion, move some functions

This commit is contained in:
Jonny_Bro (Nikita) 2024-10-04 12:13:41 +05:00 committed by GitHub
parent 6967581788
commit 80c93c95e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 50 deletions

View file

@ -15,6 +15,8 @@ class CommandHandler extends BaseEvent {
* @param {import("discord.js").CommandInteraction} interaction * @param {import("discord.js").CommandInteraction} interaction
*/ */
async execute(client, interaction) { async execute(client, interaction) {
if (interaction.isButton() && interaction.customId === "quote_delete" && interaction.message.deletable) return interaction.message.delete();
const command = client.commands.get(interaction.commandName); const command = client.commands.get(interaction.commandName);
if (!command) return interaction.reply({ content: "Command not found!", ephemeral: true }); if (!command) return interaction.reply({ content: "Command not found!", ephemeral: true });
@ -27,7 +29,6 @@ class CommandHandler extends BaseEvent {
interaction.data = data; interaction.data = data;
if (interaction.isButton() && interaction.customId === "quote_delete" && interaction.message.deletable) return interaction.message.delete();
if (interaction.isAutocomplete()) return await command.autocompleteRun(client, interaction); if (interaction.isAutocomplete()) return await command.autocompleteRun(client, interaction);
if (interaction.type !== InteractionType.ApplicationCommand || !interaction.isCommand()) return; if (interaction.type !== InteractionType.ApplicationCommand || !interaction.isCommand()) return;
@ -47,13 +48,13 @@ class CommandHandler extends BaseEvent {
await interaction.data.user.save(); await interaction.data.user.save();
const achievementMessage = { const message = {
content: interaction.user.toString(), content: interaction.user.toString(),
files: [{ name: "achievement_unlocked2.png", attachment: "./assets/img/achievements/achievement_unlocked2.png" }], files: [{ name: "achievement_unlocked2.png", attachment: "./assets/img/achievements/achievement_unlocked2.png" }],
}; };
try { try {
await interaction.user.send(achievementMessage); await interaction.user.send(message);
} catch (e) { } catch (e) {
client.logger.warn("Failed to send achievement message to user:", e); client.logger.warn("Failed to send achievement message to user:", e);
} }

View file

@ -18,18 +18,7 @@ class MessageCreate extends BaseEvent {
*/ */
async execute(client, message) { async execute(client, message) {
if (message.author.bot) return; if (message.author.bot) return;
if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) return message.replyT("misc:HELLO_SERVER", null, { mention: true });
const data = await this.initializeMessageData(client, message);
message.data = data;
if (message.guild)
await this.handleGuildMessage(client, message);
return;
}
async initializeMessageData(client, message) {
const data = { user: await client.getUserData(message.author.id) }; const data = { user: await client.getUserData(message.author.id) };
if (message.guild) { if (message.guild) {
@ -38,12 +27,12 @@ class MessageCreate extends BaseEvent {
data.guild = await client.getGuildData(message.guildId); data.guild = await client.getGuildData(message.guildId);
data.member = await client.getMemberData(message.author.id, message.guildId); data.member = await client.getMemberData(message.author.id, message.guildId);
} }
message.data = data;
return data; if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) return message.replyT("misc:HELLO_SERVER", null, { mention: true, locale: message.data.guild.language });
}
async handleGuildMessage(client, message) { if (message.guild) {
await updateXp(message); await this.updateXp(message);
if (message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)) await this.handleLinkQuote(client, message); if (message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)) await this.handleLinkQuote(client, message);
if (message.data.guild.plugins.automod.enabled && !message.data.guild.plugins.automod.ignored.includes(message.channelId)) await this.checkAutomod(message); if (message.data.guild.plugins.automod.enabled && !message.data.guild.plugins.automod.ignored.includes(message.channelId)) await this.checkAutomod(message);
@ -52,6 +41,14 @@ class MessageCreate extends BaseEvent {
await this.checkMentionedUsersAfk(client, message); await this.checkMentionedUsersAfk(client, message);
} }
return;
}
/**
*
* @param {import("../base/Client")} client
* @param {import("discord.js").Message} message
*/
async handleLinkQuote(client, message) { async handleLinkQuote(client, message) {
const link = message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)[0]; const link = message.content.match(/(https|http):\/\/(ptb\.|canary\.)?(discord.com)\/(channels)\/\d+\/\d+\/\d+/g)[0];
const ids = link.match(/\d+/g); const ids = link.match(/\d+/g);
@ -94,6 +91,10 @@ class MessageCreate extends BaseEvent {
} }
} }
/**
*
* @param {import("discord.js").Message} message
*/
async checkAutomod(message) { async checkAutomod(message) {
const inviteRegex = /(discord\.(gg|io|me|li)\/.+|discordapp\.com\/invite\/.+)/i; const inviteRegex = /(discord\.(gg|io|me|li)\/.+|discordapp\.com\/invite\/.+)/i;
if (inviteRegex.test(message.content) && !message.channel.permissionsFor(message.member).has(PermissionsBitField.Flags.ManageMessages)) { if (inviteRegex.test(message.content) && !message.channel.permissionsFor(message.member).has(PermissionsBitField.Flags.ManageMessages)) {
@ -102,6 +103,11 @@ class MessageCreate extends BaseEvent {
} }
} }
/**
*
* @param {import("../base/Client")} client
* @param {import("discord.js").Message} message
*/
async checkAfkStatus(client, message) { async checkAfkStatus(client, message) {
if (message.data.user.afk) { if (message.data.user.afk) {
message.data.user.afk = null; message.data.user.afk = null;
@ -111,6 +117,11 @@ class MessageCreate extends BaseEvent {
} }
} }
/**
*
* @param {import("../base/Client")} client
* @param {import("discord.js").Message} message
*/
async checkMentionedUsersAfk(client, message) { async checkMentionedUsersAfk(client, message) {
for (const user of message.mentions.users.values()) { for (const user of message.mentions.users.values()) {
const userData = await client.getUserData(user.id); const userData = await client.getUserData(user.id);
@ -118,15 +129,12 @@ class MessageCreate extends BaseEvent {
if (userData.afk) message.replyT("general/afk:IS_AFK", { user: user.getUsername(), message: userData.afk }, { ephemeral: true }); if (userData.afk) message.replyT("general/afk:IS_AFK", { user: user.getUsername(), message: userData.afk }, { ephemeral: true });
} }
} }
}
/** /**
* *
* @param {import("../base/Client")} client
* @param {import("discord.js").Message} message * @param {import("discord.js").Message} message
* @returns
*/ */
async function updateXp(message) { async updateXp(message) {
const memberData = message.data.member; const memberData = message.data.member;
const isInCooldown = xpCooldown[message.author.id]; const isInCooldown = xpCooldown[message.author.id];
@ -149,6 +157,7 @@ async function updateXp(message) {
} }
await memberData.save(); await memberData.save();
}
} }
module.exports = MessageCreate; module.exports = MessageCreate;