2022-08-09 23:48:33 +05:00
|
|
|
const { SlashCommandBuilder, MessageCollector } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand"),
|
|
|
|
currentGames = {};
|
|
|
|
|
|
|
|
class Number extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("number")
|
2023-06-06 22:48:46 +05:00
|
|
|
.setDescription(client.translate("fun/number:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("fun/number:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("fun/number:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.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) {
|
2023-06-06 22:48:46 +05:00
|
|
|
if (currentGames[interaction.guildId]) return interaction.error("fun/number:GAME_RUNNING");
|
2022-08-09 23:48:33 +05:00
|
|
|
|
|
|
|
const participants = [],
|
|
|
|
number = client.functions.randomNum(1000, 5000);
|
|
|
|
|
2023-06-06 22:48:46 +05:00
|
|
|
await interaction.replyT("fun/number:GAME_START");
|
2022-08-09 23:48:33 +05:00
|
|
|
|
|
|
|
const gameCreatedAt = Date.now();
|
|
|
|
|
|
|
|
const filter = m => !m.author.bot;
|
|
|
|
const collector = new MessageCollector(interaction.channel, {
|
|
|
|
filter,
|
2023-07-05 00:58:06 +05:00
|
|
|
time: 5 * 60 * 1000,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
currentGames[interaction.guildId] = true;
|
|
|
|
|
|
|
|
collector.on("collect", async msg => {
|
|
|
|
if (!participants.includes(msg.author.id)) participants.push(msg.author.id);
|
|
|
|
if (msg.content === "STOP") return collector.stop("force");
|
|
|
|
if (isNaN(msg.content)) return;
|
|
|
|
|
|
|
|
const parsedNumber = parseInt(msg.content, 10);
|
|
|
|
|
|
|
|
if (parsedNumber === number) {
|
2023-05-30 15:28:41 +05:00
|
|
|
const time = client.functions.convertTime(client, gameCreatedAt, false, false, data.guildData.language);
|
2022-08-09 23:48:33 +05:00
|
|
|
interaction.channel.send({
|
2023-06-06 22:48:46 +05:00
|
|
|
content: interaction.translate("fun/number:GAME_STATS", {
|
2022-08-09 23:48:33 +05:00
|
|
|
winner: msg.author.toString(),
|
|
|
|
number,
|
|
|
|
time,
|
|
|
|
participantCount: participants.length,
|
2022-12-15 21:02:38 +05:00
|
|
|
participants: participants.map(p => `<@${p}>`).join(", "),
|
|
|
|
}),
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
if (participants.length > 1) {
|
|
|
|
const won = 100 * (participants.length * 0.5);
|
|
|
|
|
|
|
|
interaction.channel.send({
|
2023-06-06 22:48:46 +05:00
|
|
|
content: interaction.translate("fun/number:WON", {
|
2022-08-09 23:48:33 +05:00
|
|
|
winner: msg.author.username,
|
2023-04-20 11:47:47 +05:00
|
|
|
credits: `**${won}** ${client.functions.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
2022-12-15 21:02:38 +05:00
|
|
|
}),
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
const memberData = await client.findOrCreateMember({
|
|
|
|
id: msg.author.id,
|
2022-12-15 21:02:38 +05:00
|
|
|
guildId: interaction.guildId,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
2022-10-09 14:26:22 +05:00
|
|
|
memberData.money += won;
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
const info = {
|
|
|
|
user: interaction.translate("economy/transactions:NUMBERS"),
|
|
|
|
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);
|
|
|
|
|
2023-07-03 19:30:47 +05:00
|
|
|
data.memberData.markModified("transactions");
|
2022-08-09 23:48:33 +05:00
|
|
|
await memberData.save();
|
|
|
|
}
|
|
|
|
collector.stop();
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
if (parseInt(msg.content) < number)
|
|
|
|
msg.reply({
|
|
|
|
content: interaction.translate("fun/number:TOO_BIG", { user: msg.author.toString(), number: parsedNumber }),
|
|
|
|
});
|
|
|
|
if (parseInt(msg.content) > number)
|
|
|
|
msg.reply({
|
|
|
|
content: interaction.translate("fun/number:TOO_SMALL", { user: msg.author.toString(), number: parsedNumber }),
|
|
|
|
});
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
2022-08-26 00:21:26 +05:00
|
|
|
collector.on("end", (_, reason) => {
|
2022-08-09 23:48:33 +05:00
|
|
|
delete currentGames[interaction.guildId];
|
2023-06-06 22:48:46 +05:00
|
|
|
if (reason === "time") return interaction.editReply({ content: interaction.translate("fun/number:DEFEAT", { number }) });
|
|
|
|
else if (reason === "force") return interaction.editReply({ content: interaction.translate("misc:FORCE_STOP", { user: interaction.member.toString(), number }) });
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Number;
|