JaBa/commands/Economy/rep.js

70 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js");
class Rep extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "rep",
dirname: __dirname,
enabled: true,
guildOnly: true,
2021-12-26 19:29:37 +05:00
aliases: ["reputation"],
2021-12-10 21:39:54 +05:00
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 2000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
// if the member is already in the cooldown db
2021-12-26 19:29:37 +05:00
const isInCooldown = (data.userData.cooldowns || {
rep: 0
}).rep;
2021-12-10 21:39:54 +05:00
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 */
2021-12-26 19:29:37 +05:00
if (isInCooldown > Date.now()) return message.error("economy/rep:COOLDOWN", {
time: message.convertTime(isInCooldown, "to", true)
});
2021-12-10 21:39:54 +05:00
};
const user = await this.client.resolveUser(args[0]);
if (!user) return message.error("economy/rep:INVALID_USER");
if (user.bot) return message.error("economy/rep:BOT_USER");
if (user.id === message.author.id) return message.error("economy/rep:YOURSELF");
// Records in the database the time when the member will be able to execute the command again (in 12 hours)
const toWait = Date.now() + 21600000;
data.userData.cooldowns = {};
data.userData.cooldowns.rep = toWait;
data.userData.markModified("cooldowns");
data.userData.save();
2021-12-26 19:29:37 +05:00
const userData = await this.client.findOrCreateUser({
id: user.id
});
2021-12-10 21:39:54 +05:00
userData.rep++;
if (!userData.achievements.rep.achieved) {
userData.achievements.rep.progress.now = (userData.rep > userData.achievements.rep.progress.total ? userData.achievements.rep.progress.total : userData.rep);
if (userData.achievements.rep.progress.now >= userData.achievements.rep.progress.total) {
userData.achievements.rep.achieved = true;
2021-12-26 19:29:37 +05:00
message.channel.send({
files: [{
name: "unlocked.png",
attachment: "./assets/img/achievements/achievement_unlocked6.png"
}]
});
2021-12-10 21:39:54 +05:00
};
userData.markModified("achievements.rep");
};
await userData.save();
2021-12-26 19:29:37 +05:00
message.success("economy/rep:SUCCESS", {
username: user.username
});
2021-12-10 21:39:54 +05:00
}
};
module.exports = Rep;