JaBa/commands/Economy/rep.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

const Command = require("../../base/Command");
2022-01-04 02:18:28 +05:00
class Rep extends Command {
constructor(client) {
super(client, {
name: "rep",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: ["reputation"],
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.userData.cooldowns || {
rep: 0
}).rep;
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/rep:COOLDOWN", {
time: message.convertTime(isInCooldown, "to", true)
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +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();
const userData = await this.client.findOrCreateUser({
id: user.id
});
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;
message.channel.send({
content: `${user}`,
2022-01-04 02:18:28 +05:00
files: [{
name: "achievement_unlocked6.png",
2022-01-04 02:18:28 +05:00
attachment: "./assets/img/achievements/achievement_unlocked6.png"
}]
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
userData.markModified("achievements.rep");
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
await userData.save();
message.success("economy/rep:SUCCESS", {
username: user.username
});
}
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = Rep;