JaBa/commands/Economy/rep.js

98 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-08-09 23:48:33 +05:00
const { SlashCommandBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
class Rep extends BaseCommand {
/**
*
* @param {import("../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("rep")
.setDescription(client.translate("economy/rep:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("economy/rep:DESCRIPTION", null, "uk-UA"),
ru: client.translate("economy/rep:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
2023-07-05 00:58:06 +05:00
.addUserOption(option =>
option
.setName("user")
.setDescription(client.translate("common:USER"))
.setDescriptionLocalizations({
uk: client.translate("common:USER", null, "uk-UA"),
ru: client.translate("common:USER", null, "ru-RU"),
})
.setRequired(true),
),
2022-08-09 23:48:33 +05:00
aliases: [],
dirname: __dirname,
ownerOnly: false,
2022-08-09 23:48:33 +05:00
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @param {Object} data
*/
async execute(client, interaction, data) {
const isInCooldown = data.userData.cooldowns?.rep;
if (isInCooldown) {
2023-07-05 00:58:06 +05:00
if (isInCooldown > Date.now())
return interaction.error("economy/rep:COOLDOWN", {
time: client.functions.convertTime(client, isInCooldown, true, true, data.guildData.language),
});
2022-08-09 23:48:33 +05:00
}
const user = interaction.options.getUser("user");
if (user.bot) return interaction.error("economy/rep:BOT_USER");
if (user.id === interaction.user.id) return interaction.error("economy/rep:YOURSELF");
const toWait = Date.now() + 21600000; // 12 hours
if (!data.userData.cooldowns) data.userData.cooldowns = {};
2022-08-09 23:48:33 +05:00
data.userData.cooldowns.rep = toWait;
2023-10-30 21:45:10 +05:00
data.userData.markModified();
2022-08-09 23:48:33 +05:00
await data.userData.save();
2023-10-30 21:45:10 +05:00
const userData = await client.findOrCreateUser(user.id);
2022-08-09 23:48:33 +05:00
userData.rep++;
if (!userData.achievements.rep.achieved) {
2023-07-05 00:58:06 +05:00
userData.achievements.rep.progress.now = userData.rep > userData.achievements.rep.progress.total ? userData.achievements.rep.progress.total : userData.rep;
2022-08-09 23:48:33 +05:00
if (userData.achievements.rep.progress.now >= userData.achievements.rep.progress.total) {
userData.achievements.rep.achieved = true;
interaction.followUp({
content: `${user}`,
2023-07-05 00:58:06 +05:00
files: [
{
name: "achievement_unlocked6.png",
attachment: "./assets/img/achievements/achievement_unlocked6.png",
},
],
2022-08-09 23:48:33 +05:00
});
}
}
2023-10-19 22:48:38 +05:00
2023-10-30 21:45:10 +05:00
userData.markModified();
2022-08-09 23:48:33 +05:00
await userData.save();
interaction.success("economy/rep:SUCCESS", {
user: user.toString(),
2022-08-09 23:48:33 +05:00
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Rep;