JaBa/commands/Economy/work.js

114 lines
3.8 KiB
JavaScript
Raw Normal View History

const Command = require("../../base/Command"),
2022-01-04 02:18:28 +05:00
Discord = require("discord.js");
class Work extends Command {
constructor(client) {
super(client, {
name: "work",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: ["salary", "daily"],
memberPermissions: [],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
async run(message, args, data) {
// if the member is already in the cooldown db
const isInCooldown = data.memberData.cooldowns.work;
if (isInCooldown) {
/*if the timestamp recorded in the database indicating
when the member will be able to execute the order again
is greater than the current date, display an error message */
if (isInCooldown > Date.now()) return message.error("economy/work:COOLDOWN", {
time: message.convertTime(isInCooldown, "to", true)
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
if (Date.now() > data.memberData.cooldowns.work + (24 * 3600000)) data.memberData.workStreak = 0;
// Records in the database the time when the member will be able to execute the command again (in 12 hours)
const toWait = Date.now() + 43200000;
data.memberData.cooldowns.work = toWait;
data.memberData.markModified("cooldowns");
data.memberData.workStreak = (data.memberData.workStreak || 0) + 1;
await data.memberData.save();
const embed = new Discord.MessageEmbed()
.setFooter({
text: message.translate("economy/work:AWARD"),
iconURL: message.author.displayAvatarURL({
size: 512,
dynamic: true,
format: "png"
})
})
2022-01-04 02:18:28 +05:00
.setColor(data.config.embed.color);
const award = [
this.client.customEmojis.letters.a,
this.client.customEmojis.letters.w,
this.client.customEmojis.letters.a,
this.client.customEmojis.letters.r,
this.client.customEmojis.letters.d
];
let won = 200;
if (data.memberData.workStreak >= 5) {
won += 200;
embed.addField(message.translate("economy/work:SALARY"), message.translate("economy/work:SALARY_CONTENT", {
2022-01-13 00:26:23 +05:00
won: `${won} ${message.getNoun(won, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`
}))
2022-01-04 02:18:28 +05:00
.addField(message.translate("economy/work:STREAK"), message.translate("economy/work:STREAK_CONTENT"));
data.memberData.workStreak = 0;
} else {
for (let i = 0; i < award.length; i++) {
if (data.memberData.workStreak > i) {
const letter = Discord.Util.parseEmoji(award[i]).name.split("_")[1];
award[i] = `:regional_indicator_${letter.toLowerCase()}:`;
2022-01-13 00:26:23 +05:00
}
}
2022-01-04 02:18:28 +05:00
embed.addField(message.translate("economy/work:SALARY"), message.translate("economy/work:SALARY_CONTENT", {
2022-01-13 00:26:23 +05:00
won: `**${won}** ${message.getNoun(won, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`
}))
2022-01-04 02:18:28 +05:00
.addField(message.translate("economy/work:STREAK"), award.join(""));
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
2022-01-05 22:04:46 +05:00
const info = {
user: message.translate("economy/work:SALARY"),
amount: won,
date: Date.now(),
type: "got"
};
data.memberData.transactions.push(info);
2022-01-04 02:18:28 +05:00
data.memberData.money = data.memberData.money + won;
data.memberData.save();
const messageOptions = {
embeds: [embed]
2022-01-04 02:18:28 +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",
attachment: "./assets/img/achievements/achievement_unlocked1.png"
}];
data.userData.achievements.work.achieved = true;
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
data.userData.markModified("achievements.work");
data.userData.save();
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
// Send the embed in the current channel
message.channel.send(messageOptions);
}
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = Work;