2024-02-06 21:45:53 +05:00
|
|
|
const { SlashCommandBuilder, parseEmoji } = require("discord.js");
|
2022-08-09 23:48:33 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Work 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("work")
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDescription(client.translate("economy/work:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("economy/work:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("economy/work:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(false),
|
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 { member: memberData, user: userData } = interaction.data,
|
|
|
|
isInCooldown = memberData.cooldowns?.work;
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2024-05-24 23:02:12 +05:00
|
|
|
if (isInCooldown && isInCooldown > 0 && isInCooldown > Math.floor(Date.now() / 1000))
|
|
|
|
return interaction.error("economy/work:COOLDOWN", {
|
|
|
|
time: `<t:${Math.floor(isInCooldown)}:R>`,
|
|
|
|
});
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2024-05-24 23:02:12 +05:00
|
|
|
if (Math.floor(Date.now() / 1000) > Math.floor(memberData.cooldowns.work + 24 * 60 * 60)) memberData.workStreak = 0;
|
2022-08-09 23:48:33 +05:00
|
|
|
|
2024-05-24 23:02:12 +05:00
|
|
|
memberData.cooldowns.work = Math.floor(Date.now() / 1000) + 24 * 60 * 60; // 24 hours
|
2024-02-09 23:26:57 +05:00
|
|
|
memberData.workStreak = (memberData.workStreak || 0) + 1;
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
const embed = client.embed({
|
|
|
|
footer: {
|
2022-08-09 23:48:33 +05:00
|
|
|
text: interaction.translate("economy/work:AWARD"),
|
2022-12-15 21:02:38 +05:00
|
|
|
iconURL: interaction.member.displayAvatarURL(),
|
2024-02-06 21:45:53 +05:00
|
|
|
},
|
|
|
|
});
|
2022-08-09 23:48:33 +05:00
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
const award = [client.customEmojis.letters.a, client.customEmojis.letters.w, client.customEmojis.letters.a, client.customEmojis.letters.r, client.customEmojis.letters.d];
|
2022-08-09 23:48:33 +05:00
|
|
|
let won = 200;
|
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
if (memberData.workStreak >= 5) {
|
2022-08-09 23:48:33 +05:00
|
|
|
won += 200;
|
2024-02-12 17:03:14 +05:00
|
|
|
embed.data.fields = [
|
2022-08-09 23:48:33 +05:00
|
|
|
{
|
|
|
|
name: interaction.translate("economy/work:SALARY"),
|
|
|
|
value: interaction.translate("economy/work:SALARY_CONTENT", {
|
2023-04-20 11:47:47 +05:00
|
|
|
won: `**${won}** ${client.functions.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
2022-12-15 21:02:38 +05:00
|
|
|
}),
|
2022-08-09 23:48:33 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("economy/work:STREAK"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: interaction.translate("economy/work:STREAK_CONTENT"),
|
|
|
|
},
|
2024-02-06 21:45:53 +05:00
|
|
|
];
|
2024-02-09 23:26:57 +05:00
|
|
|
|
|
|
|
memberData.workStreak = 0;
|
2022-08-09 23:48:33 +05:00
|
|
|
} else {
|
|
|
|
for (let i = 0; i < award.length; i++) {
|
2024-02-09 23:26:57 +05:00
|
|
|
if (memberData.workStreak > i) {
|
2022-08-09 23:48:33 +05:00
|
|
|
const letter = parseEmoji(award[i]).name.split("_")[1];
|
|
|
|
award[i] = `:regional_indicator_${letter.toLowerCase()}:`;
|
|
|
|
}
|
|
|
|
}
|
2024-02-12 17:03:14 +05:00
|
|
|
embed.data.fields = [
|
2022-08-09 23:48:33 +05:00
|
|
|
{
|
|
|
|
name: interaction.translate("economy/work:SALARY"),
|
|
|
|
value: interaction.translate("economy/work:SALARY_CONTENT", {
|
2023-04-20 11:47:47 +05:00
|
|
|
won: `**${won}** ${client.functions.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
2022-12-15 21:02:38 +05:00
|
|
|
}),
|
2022-08-09 23:48:33 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("economy/work:STREAK"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: award.join(""),
|
|
|
|
},
|
2024-02-06 21:45:53 +05:00
|
|
|
];
|
2022-08-09 23:48:33 +05:00
|
|
|
}
|
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
memberData.money += won;
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
const info = {
|
|
|
|
user: interaction.translate("economy/work:SALARY"),
|
|
|
|
amount: won,
|
|
|
|
date: Date.now(),
|
2022-12-15 21:02:38 +05:00
|
|
|
type: "got",
|
2022-08-09 23:48:33 +05:00
|
|
|
};
|
2024-02-09 23:26:57 +05:00
|
|
|
memberData.transactions.push(info);
|
2022-08-09 23:48:33 +05:00
|
|
|
|
|
|
|
const messageOptions = {
|
2022-12-15 21:02:38 +05:00
|
|
|
embeds: [embed],
|
2022-08-09 23:48:33 +05:00
|
|
|
};
|
2023-07-05 00:58:06 +05:00
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
if (!userData.achievements.work.achieved) {
|
|
|
|
userData.achievements.work.progress.now += 1;
|
|
|
|
if (userData.achievements.work.progress.now === userData.achievements.work.progress.total) {
|
2023-07-05 00:58:06 +05:00
|
|
|
messageOptions.files = [
|
|
|
|
{
|
|
|
|
name: "unlocked.png",
|
|
|
|
attachment: "./assets/img/achievements/achievement_unlocked1.png",
|
|
|
|
},
|
|
|
|
];
|
2024-02-09 23:26:57 +05:00
|
|
|
userData.achievements.work.achieved = true;
|
2022-08-09 23:48:33 +05:00
|
|
|
}
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
await userData.save();
|
2022-08-09 23:48:33 +05:00
|
|
|
}
|
|
|
|
|
2024-05-24 23:02:12 +05:00
|
|
|
await memberData.save();
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
interaction.reply(messageOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Work;
|