JaBa/events/CommandHandler.js

66 lines
2.4 KiB
JavaScript
Raw Normal View History

const { InteractionType } = require("discord.js");
2022-08-04 21:02:45 +05:00
const BaseEvent = require("../base/BaseEvent");
class CommandHandler extends BaseEvent {
constructor() {
super({
name: "interactionCreate",
once: false,
});
}
/**
*
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
*/
async execute(client, interaction) {
const command = client.commands.get(interaction.commandName);
const data = [];
2023-10-30 21:45:10 +05:00
const userData = await client.findOrCreateUser(interaction.user.id);
data.userData = userData;
if (interaction.inGuild()) {
2023-10-15 15:05:10 +05:00
const guildData = await client.findOrCreateGuild(interaction.guildId);
2023-06-27 21:19:55 +05:00
const memberData = await client.findOrCreateMember({ id: interaction.member.id, guildId: interaction.guildId });
2023-06-29 14:00:08 +05:00
interaction.guild.data = data.guildData = guildData;
data.memberData = memberData;
}
2023-11-21 01:19:46 +05:00
if (command?.dirname.includes("IAT") && interaction.guildId !== "1039187019957555252") return interaction.reply({ content: "IAT Only", ephemeral: true });
2023-07-03 19:30:47 +05:00
if (interaction.isAutocomplete()) return await command.autocompleteRun(client, interaction);
if (interaction.isButton() && interaction.customId === "quote_delete" && interaction.message.deletable) return interaction.message.delete();
if (interaction.type !== InteractionType.ApplicationCommand && !interaction.isCommand()) return;
2023-11-06 18:18:16 +05:00
if (command.ownerOnly && interaction.user.id !== client.config.owner.id) return interaction.error("misc:OWNER_ONLY", null, { ephemeral: true });
if (!userData.achievements.firstCommand.achieved) {
2023-05-25 22:49:27 +05:00
const args = {
content: interaction.user.toString(),
2023-07-05 00:58:06 +05:00
files: [
{
name: "achievement_unlocked2.png",
attachment: "./assets/img/achievements/achievement_unlocked2.png",
},
],
2023-05-25 22:49:27 +05:00
};
userData.achievements.firstCommand.progress.now = 1;
userData.achievements.firstCommand.achieved = true;
2023-10-30 21:45:10 +05:00
userData.markModified("achievements");
2023-05-25 22:49:27 +05:00
await userData.save();
2023-06-27 21:19:55 +05:00
interaction.user.send(args);
}
2023-07-05 00:58:06 +05:00
client.logger.log(`User ${interaction.user.getUsername()} used ${command.command.name} in ${interaction.guild ? interaction.guild.name : "DM"} with arguments: ${interaction.options.data.length > 0 ? interaction.options.data.map(arg => { return `${arg.name}: ${arg.value}`; }).join(", ") : "no args" }`, "cmd");
return command.execute(client, interaction, data);
}
}
2023-07-05 00:58:06 +05:00
module.exports = CommandHandler;