2022-08-09 23:48:33 +05:00
|
|
|
const { SlashCommandBuilder, EmbedBuilder, parseEmoji } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Work extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("work")
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDescription(client.translate("economy/work:DESCRIPTION"))
|
|
|
|
.setDMPermission(false),
|
2022-08-09 23:48:33 +05:00
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
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.memberData.cooldowns?.work;
|
|
|
|
if (isInCooldown) {
|
|
|
|
if (isInCooldown > Date.now()) return interaction.error("economy/work:COOLDOWN", {
|
2022-12-15 21:02:38 +05:00
|
|
|
time: client.convertTime(isInCooldown, true, true, data.guildData.language),
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
2022-08-26 00:21:26 +05:00
|
|
|
if (Date.now() > data.memberData.cooldowns.work + (24 * 60 * 60 * 1000)) data.memberData.workStreak = 0;
|
2022-08-09 23:48:33 +05:00
|
|
|
|
2022-08-26 00:21:26 +05:00
|
|
|
const toWait = Date.now() + (24 * 60 * 60 * 1000); // 24 hours
|
2022-08-09 23:48:33 +05:00
|
|
|
data.memberData.cooldowns.work = toWait;
|
|
|
|
data.memberData.markModified("cooldowns");
|
|
|
|
|
|
|
|
data.memberData.workStreak = (data.memberData.workStreak || 0) + 1;
|
|
|
|
await data.memberData.save();
|
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setFooter({
|
|
|
|
text: interaction.translate("economy/work:AWARD"),
|
2022-12-15 21:02:38 +05:00
|
|
|
iconURL: interaction.member.displayAvatarURL(),
|
2022-08-09 23:48:33 +05:00
|
|
|
})
|
|
|
|
.setColor(client.config.embed.color);
|
|
|
|
|
|
|
|
const award = [
|
|
|
|
client.customEmojis.letters.a,
|
|
|
|
client.customEmojis.letters.w,
|
|
|
|
client.customEmojis.letters.a,
|
|
|
|
client.customEmojis.letters.r,
|
2022-12-15 21:02:38 +05:00
|
|
|
client.customEmojis.letters.d,
|
2022-08-09 23:48:33 +05:00
|
|
|
];
|
|
|
|
let won = 200;
|
|
|
|
|
|
|
|
if (data.memberData.workStreak >= 5) {
|
|
|
|
won += 200;
|
|
|
|
embed.addFields([
|
|
|
|
{
|
|
|
|
name: interaction.translate("economy/work:SALARY"),
|
|
|
|
value: interaction.translate("economy/work:SALARY_CONTENT", {
|
2022-12-15 21:02:38 +05:00
|
|
|
won: `**${won}** ${client.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
|
|
}),
|
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"),
|
|
|
|
},
|
2022-08-09 23:48:33 +05:00
|
|
|
]);
|
|
|
|
data.memberData.workStreak = 0;
|
|
|
|
} else {
|
|
|
|
for (let i = 0; i < award.length; i++) {
|
|
|
|
if (data.memberData.workStreak > i) {
|
|
|
|
const letter = parseEmoji(award[i]).name.split("_")[1];
|
|
|
|
award[i] = `:regional_indicator_${letter.toLowerCase()}:`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
embed.addFields([
|
|
|
|
{
|
|
|
|
name: interaction.translate("economy/work:SALARY"),
|
|
|
|
value: interaction.translate("economy/work:SALARY_CONTENT", {
|
2022-12-15 21:02:38 +05:00
|
|
|
won: `**${won}** ${client.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
|
|
}),
|
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(""),
|
|
|
|
},
|
2022-08-09 23:48:33 +05:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-10-09 14:26:22 +05:00
|
|
|
data.memberData.money += won;
|
|
|
|
await data.memberData.save();
|
|
|
|
|
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
|
|
|
};
|
|
|
|
data.memberData.transactions.push(info);
|
|
|
|
|
|
|
|
const messageOptions = {
|
2022-12-15 21:02:38 +05:00
|
|
|
embeds: [embed],
|
2022-08-09 23:48:33 +05:00
|
|
|
};
|
|
|
|
if (!data.userData.achievements.work.achieved) {
|
|
|
|
data.userData.achievements.work.progress.now += 1;
|
|
|
|
if (data.userData.achievements.work.progress.now === data.userData.achievements.work.progress.total) {
|
|
|
|
messageOptions.files = [{
|
|
|
|
name: "unlocked.png",
|
2022-12-15 21:02:38 +05:00
|
|
|
attachment: "./assets/img/achievements/achievement_unlocked1.png",
|
2022-08-09 23:48:33 +05:00
|
|
|
}];
|
|
|
|
data.userData.achievements.work.achieved = true;
|
|
|
|
}
|
|
|
|
data.userData.markModified("achievements.work");
|
|
|
|
await data.userData.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
interaction.reply(messageOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Work;
|