2024-09-19 23:58:06 +05:00
|
|
|
const { InteractionType } = require("discord.js");
|
2022-08-04 21:02:45 +05:00
|
|
|
const BaseEvent = require("../base/BaseEvent");
|
2022-07-23 17:14:42 +05:00
|
|
|
|
|
|
|
class CommandHandler extends BaseEvent {
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
name: "interactionCreate",
|
2022-12-15 21:02:38 +05:00
|
|
|
once: false,
|
2022-07-23 17:14:42 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-03 11:07:02 +05:00
|
|
|
* Handles command interaction events.
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../base/Client")} client
|
2023-11-06 18:23:02 +05:00
|
|
|
* @param {import("discord.js").CommandInteraction} interaction
|
2022-07-23 17:14:42 +05:00
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
|
|
|
const command = client.commands.get(interaction.commandName);
|
2024-10-03 11:07:02 +05:00
|
|
|
if (!command) return interaction.reply({ content: "Command not found!", ephemeral: true });
|
2024-02-09 23:26:57 +05:00
|
|
|
|
2024-10-03 11:07:02 +05:00
|
|
|
const data = { user: await client.getUserData(interaction.user.id) };
|
2022-07-23 17:14:42 +05:00
|
|
|
|
|
|
|
if (interaction.inGuild()) {
|
2024-05-24 23:11:03 +05:00
|
|
|
data.guild = await client.getGuildData(interaction.guildId);
|
|
|
|
data.member = await client.getMemberData(interaction.member.id, interaction.guildId);
|
2022-07-23 17:14:42 +05:00
|
|
|
}
|
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
interaction.data = data;
|
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
if (interaction.isButton() && interaction.customId === "quote_delete" && interaction.message.deletable) return interaction.message.delete();
|
2024-02-09 23:26:57 +05:00
|
|
|
if (interaction.isAutocomplete()) return await command.autocompleteRun(client, interaction);
|
2024-10-03 11:07:02 +05:00
|
|
|
if (interaction.type !== InteractionType.ApplicationCommand || !interaction.isCommand()) return;
|
2024-02-09 23:26:57 +05:00
|
|
|
|
2024-10-03 11:07:02 +05:00
|
|
|
// IAT Guild Command Check
|
|
|
|
if (command?.dirname.includes("IAT") && interaction.guildId !== "1039187019957555252")
|
|
|
|
return interaction.reply({ content: "IAT only", ephemeral: true });
|
2023-06-17 16:46:31 +05:00
|
|
|
|
2024-10-03 11:07:02 +05:00
|
|
|
// Owner-only command check
|
|
|
|
if (command.ownerOnly && interaction.user.id !== client.config.owner.id)
|
|
|
|
return interaction.error("misc:OWNER_ONLY", null, { ephemeral: true });
|
2023-05-25 22:49:27 +05:00
|
|
|
|
2024-10-03 11:07:02 +05:00
|
|
|
// First command achievement check
|
|
|
|
const { firstCommand } = interaction.data.user.achievements;
|
|
|
|
if (!firstCommand.achieved) {
|
|
|
|
firstCommand.progress.now = 1;
|
|
|
|
firstCommand.achieved = true;
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
await interaction.data.user.save();
|
2023-05-25 22:49:27 +05:00
|
|
|
|
2024-10-03 11:07:02 +05:00
|
|
|
const achievementMessage = {
|
|
|
|
content: interaction.user.toString(),
|
|
|
|
files: [{ name: "achievement_unlocked2.png", attachment: "./assets/img/achievements/achievement_unlocked2.png" }],
|
|
|
|
};
|
|
|
|
|
2024-02-07 20:46:56 +05:00
|
|
|
try {
|
2024-10-03 11:07:02 +05:00
|
|
|
await interaction.user.send(achievementMessage);
|
|
|
|
} catch (e) {
|
|
|
|
client.logger.warn("Failed to send achievement message to user:", e);
|
|
|
|
}
|
2022-07-23 17:14:42 +05:00
|
|
|
}
|
|
|
|
|
2024-10-03 11:07:02 +05:00
|
|
|
// Command logging
|
|
|
|
const args = interaction.options.data.map(arg => `${arg.name}: ${arg.value}`).join(", ");
|
|
|
|
client.logger.cmd(`[${interaction.guild ? interaction.guild.name : "DM/Private Channel"}]: [${interaction.user.tag}] => /${command.command.name}${args ? `, args: [${args}]` : ""}`);
|
2022-11-16 14:37:16 +05:00
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
return command.execute(client, interaction);
|
2022-07-23 17:14:42 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = CommandHandler;
|