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"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.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"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.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,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +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;
|
2024-02-06 21:45:53 +05:00
|
|
|
|
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", {
|
2024-02-06 21:45:53 +05:00
|
|
|
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");
|
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
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 = {};
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
userData.cooldowns.rep = toWait;
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
userData.markModified("cooldowns");
|
|
|
|
await userData.save();
|
2022-08-09 23:48:33 +05:00
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
const otherUserData = await client.findOrCreateUser(user.id);
|
2023-06-15 19:46:27 +05:00
|
|
|
|
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-02-09 23:26:57 +05:00
|
|
|
otherUserData.markModified("rep");
|
|
|
|
await otherUserData.save();
|
2022-08-09 23:48:33 +05:00
|
|
|
|
|
|
|
interaction.success("economy/rep:SUCCESS", {
|
2022-12-15 21:02:38 +05:00
|
|
|
user: user.toString(),
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Rep;
|