2022-07-31 17:08:00 +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",
|
|
|
|
once: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").Interaction} interaction
|
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
2022-07-31 17:08:00 +05:00
|
|
|
if (interaction.type !== InteractionType.ApplicationCommand && !interaction.isCommand()) return;
|
2022-07-25 22:09:02 +05:00
|
|
|
|
2022-07-23 17:14:42 +05:00
|
|
|
const command = client.commands.get(interaction.commandName);
|
|
|
|
const data = [];
|
|
|
|
|
|
|
|
const userData = await client.findOrCreateUser({
|
2022-08-14 14:35:35 +05:00
|
|
|
id: interaction.user.id
|
2022-07-23 17:14:42 +05:00
|
|
|
});
|
|
|
|
data.userData = userData;
|
|
|
|
|
2022-07-26 17:20:10 +05:00
|
|
|
if (command.guildOnly && !interaction.inGuild()) return interaction.replyT("misc:GUILD_ONLY", { ephemeral: true });
|
2022-10-09 18:16:10 +05:00
|
|
|
if (command.ownerOnly && interaction.user.id !== client.config.owner.id) return interaction.replyT("misc:OWNER_ONLY", { ephemeral: true });
|
2022-07-23 17:14:42 +05:00
|
|
|
|
|
|
|
if (interaction.inGuild()) {
|
|
|
|
const guildData = await client.findOrCreateGuild({
|
|
|
|
id: interaction.guildId
|
|
|
|
});
|
2022-07-26 19:46:32 +05:00
|
|
|
interaction.guild.data = data.guildData = guildData;
|
2022-07-23 17:14:42 +05:00
|
|
|
|
|
|
|
const memberData = await client.findOrCreateMember({
|
|
|
|
id: interaction.member.id,
|
2022-10-03 20:21:42 +05:00
|
|
|
guildId: interaction.guildId
|
2022-07-23 17:14:42 +05:00
|
|
|
});
|
|
|
|
data.memberData = memberData;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!userData.achievements.firstCommand.achieved) {
|
|
|
|
userData.achievements.firstCommand.progress.now = 1;
|
|
|
|
userData.achievements.firstCommand.achieved = true;
|
|
|
|
userData.markModified("achievements.firstCommand");
|
|
|
|
await userData.save();
|
2022-08-09 23:48:33 +05:00
|
|
|
await interaction.followUp({
|
2022-07-23 17:14:42 +05:00
|
|
|
files: [{
|
|
|
|
name: "achievement_unlocked2.png",
|
|
|
|
attachment: "./assets/img/achievements/achievement_unlocked2.png"
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return command.execute(client, interaction, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CommandHandler;
|