2021-12-10 21:39:54 +05:00
|
|
|
const Command = require("../../base/Command.js"),
|
|
|
|
Discord = require("discord.js");
|
|
|
|
|
|
|
|
const currentGames = {};
|
|
|
|
|
|
|
|
class Number extends Command {
|
2021-12-26 19:29:37 +05:00
|
|
|
constructor(client) {
|
2021-12-10 21:39:54 +05:00
|
|
|
super(client, {
|
|
|
|
name: "number",
|
|
|
|
dirname: __dirname,
|
|
|
|
enabled: true,
|
|
|
|
guildOnly: true,
|
2022-01-01 00:50:09 +05:00
|
|
|
aliases: ["num"],
|
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,
|
2021-12-22 17:32:50 +05:00
|
|
|
cooldown: 2000
|
2021-12-10 21:39:54 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-02 00:32:57 +05:00
|
|
|
async run(message, args, data) {
|
2021-12-10 21:39:54 +05:00
|
|
|
if (currentGames[message.guild.id]) return message.error("fun/number:GAME_RUNNING");
|
|
|
|
|
2022-01-02 01:03:30 +05:00
|
|
|
const participants = [],
|
2022-01-03 01:51:26 +05:00
|
|
|
number = Math.floor(this.client.functions.randomNum(100, 10000));
|
2021-12-10 21:39:54 +05:00
|
|
|
|
|
|
|
await message.sendT("fun/number:GAME_START");
|
|
|
|
|
|
|
|
// Store the date wich the game has started
|
|
|
|
const gameCreatedAt = Date.now();
|
|
|
|
|
|
|
|
const collector = new Discord.MessageCollector(message.channel, m => !m.author.bot, {
|
|
|
|
time: 480000 // 8 minutes
|
|
|
|
});
|
|
|
|
currentGames[message.guild.id] = true;
|
|
|
|
|
|
|
|
collector.on("collect", async msg => {
|
2022-01-01 23:32:01 +05:00
|
|
|
if (this.client.functions.getPrefix(msg, data)) return;
|
2021-12-10 21:39:54 +05:00
|
|
|
if (!participants.includes(msg.author.id)) participants.push(msg.author.id);
|
|
|
|
if (isNaN(msg.content)) return;
|
|
|
|
|
|
|
|
const parsedNumber = parseInt(msg.content, 10);
|
|
|
|
|
|
|
|
if (parsedNumber === number) {
|
2021-12-11 01:11:50 +05:00
|
|
|
const time = this.client.functions.convertTime(message.guild, Date.now() - gameCreatedAt);
|
2021-12-26 19:29:37 +05:00
|
|
|
message.sendT("fun/number:GAME_STATS", {
|
|
|
|
winner: msg.author.toString(),
|
|
|
|
number,
|
|
|
|
time,
|
|
|
|
participantCount: participants.length,
|
2021-12-29 22:45:20 +05:00
|
|
|
participants: participants.map(p => `<@${p}>`).join(", ")
|
2021-12-26 19:29:37 +05:00
|
|
|
});
|
2022-01-02 01:03:30 +05:00
|
|
|
|
|
|
|
if (participants.length > 1 && data.guild.disabledCategories && !data.guild.disabledCategories.includes("Economy")) {
|
2022-01-03 01:45:20 +05:00
|
|
|
const won = 100 * (participants.length * 0.5);
|
|
|
|
|
2022-01-02 01:03:30 +05:00
|
|
|
message.sendT("fun/number:WON", {
|
2022-01-03 01:45:20 +05:00
|
|
|
winner: msg.author.username,
|
|
|
|
credits: `**${won}** ${message.getNoun(won, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`
|
2022-01-02 01:03:30 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
const userdata = await this.client.findOrCreateMember({
|
|
|
|
id: msg.author.id,
|
|
|
|
guildID: message.guild.id
|
|
|
|
});
|
2022-01-03 01:45:20 +05:00
|
|
|
userdata.money = userdata.money + won;
|
2022-01-02 01:03:30 +05:00
|
|
|
userdata.save();
|
|
|
|
collector.stop(msg.author.username);
|
|
|
|
};
|
2021-12-10 21:39:54 +05:00
|
|
|
};
|
2021-12-26 19:29:37 +05:00
|
|
|
if (parseInt(msg.content) < number) message.error("fun/number:BIG", {
|
|
|
|
user: msg.author.toString(),
|
|
|
|
number: parsedNumber
|
|
|
|
});
|
|
|
|
if (parseInt(msg.content) > number) message.error("fun/number:SMALL", {
|
|
|
|
user: msg.author.toString(),
|
|
|
|
number: parsedNumber
|
|
|
|
});
|
2021-12-10 21:39:54 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
collector.on("end", (_collected, reason) => {
|
|
|
|
delete currentGames[message.guild.id];
|
|
|
|
if (reason === "time") {
|
2021-12-26 19:29:37 +05:00
|
|
|
return message.error("fun/number:DEFEAT", {
|
|
|
|
number
|
|
|
|
});
|
2021-12-10 21:39:54 +05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Number;
|