JaBa/commands/Economy/rep.js

89 lines
2.6 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 {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
2022-08-09 23:48:33 +05:00
*/
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
dirname: __dirname,
ownerOnly: false,
2022-08-09 23:48:33 +05:00
});
}
2022-08-09 23:48:33 +05:00
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
2022-08-09 23:48:33 +05:00
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
2024-02-09 23:26:57 +05:00
async execute(client, interaction) {
const userData = interaction.data.user,
isInCooldown = userData.cooldowns?.rep;
2022-08-09 23:48:33 +05:00
if (isInCooldown) {
2023-07-05 00:58:06 +05:00
if (isInCooldown > Date.now())
return interaction.error("economy/rep:COOLDOWN", {
time: `<t:${Math.floor(isInCooldown / 1000)}:R>`,
2023-07-05 00:58:06 +05:00
});
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 = Math.floor((Date.now() + 12 * 60 * 60 * 1000) / 1000); // 12 hours
2024-02-09 23:26:57 +05:00
if (!userData.cooldowns) userData.cooldowns = {};
2024-02-09 23:26:57 +05:00
userData.cooldowns.rep = toWait;
const otherUserData = await client.getUserData(user.id);
2024-02-09 23:26:57 +05:00
otherUserData.rep++;
2022-08-09 23:48:33 +05:00
2024-02-09 23:26:57 +05:00
if (!otherUserData.achievements.rep.achieved) {
otherUserData.achievements.rep.progress.now = otherUserData.rep > otherUserData.achievements.rep.progress.total ? otherUserData.achievements.rep.progress.total : otherUserData.rep;
if (otherUserData.achievements.rep.progress.now >= otherUserData.achievements.rep.progress.total) {
otherUserData.achievements.rep.achieved = true;
2022-08-09 23:48:33 +05:00
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
2024-05-24 23:02:12 +05:00
await userData.save();
2024-02-09 23:26:57 +05:00
await otherUserData.save();
2022-08-09 23:48:33 +05:00
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;