Расчёт награды в зависимости от кол-ва участников

This commit is contained in:
JonnyBro 2022-01-02 01:03:30 +05:00
parent e29a32485f
commit 086180f4a9
3 changed files with 25 additions and 21 deletions

View file

@ -19,7 +19,7 @@ class Eightball extends Command {
async run(message, args) { async run(message, args) {
if (!args[0] || !message.content.endsWith("?")) return message.error("fun/8ball:ERR_QUESTION"); if (!args[0] || !message.content.endsWith("?")) return message.error("fun/8ball:ERR_QUESTION");
const answerN = this.client.functions.randomNum(1, 20); const answerN = this.client.functions.randomNum(1, 19);
const answer = message.translate(`fun/8ball:RESPONSE_${answerN + 1}`); const answer = message.translate(`fun/8ball:RESPONSE_${answerN + 1}`);
message.channel.send(answer); message.channel.send(answer);

View file

@ -26,6 +26,7 @@ class FindWords extends Command {
let lang = null; let lang = null;
if (message.guild.data.language === "uk-UA") return lang = "ru-RU"; if (message.guild.data.language === "uk-UA") return lang = "ru-RU";
else lang = message.guild.data.language; else lang = message.guild.data.language;
const wordList = require(`../../assets/json/words/${lang}.json`); const wordList = require(`../../assets/json/words/${lang}.json`);
// Init some utils variables // Init some utils variables
@ -105,7 +106,7 @@ class FindWords extends Command {
id: user.id, id: user.id,
guildID: message.guild.id guildID: message.guild.id
}); });
userdata.money = userdata.money + 150; userdata.money = userdata.money + (150 * (participants.length * 0.5));
userdata.save(); userdata.save();
}; };
}; };
@ -116,15 +117,14 @@ class FindWords extends Command {
async function getWinner(array) { async function getWinner(array) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
const counts = {}; const counts = {};
let compare = 0; let compare = 0,
let mostFrequent; mostFrequent;
for (let i = 0, len = array.length; i < len; i++) { for (let i = 0, len = array.length; i < len; i++) {
const winner = array[i]; const winner = array[i];
if (!counts[winner]) { if (!counts[winner]) counts[winner] = 1;
counts[winner] = 1; else counts[winner] = counts[winner] + 1;
} else {
counts[winner] = counts[winner] + 1;
};
if (counts[winner] > compare) { if (counts[winner] > compare) {
compare = counts[winner]; compare = counts[winner];
mostFrequent = array[i]; mostFrequent = array[i];

View file

@ -22,8 +22,8 @@ class Number extends Command {
async run(message, args, data) { async run(message, args, data) {
if (currentGames[message.guild.id]) return message.error("fun/number:GAME_RUNNING"); if (currentGames[message.guild.id]) return message.error("fun/number:GAME_RUNNING");
const participants = []; const participants = [],
const number = Math.floor(Math.random() * 3000); number = Math.floor(Math.random() * 3000);
await message.sendT("fun/number:GAME_START"); await message.sendT("fun/number:GAME_START");
@ -51,16 +51,20 @@ class Number extends Command {
participantCount: participants.length, participantCount: participants.length,
participants: participants.map(p => `<@${p}>`).join(", ") participants: participants.map(p => `<@${p}>`).join(", ")
}); });
message.sendT("fun/number:WON", {
winner: msg.author.toString() if (participants.length > 1 && data.guild.disabledCategories && !data.guild.disabledCategories.includes("Economy")) {
}); message.sendT("fun/number:WON", {
const userdata = await this.client.findOrCreateMember({ winner: msg.author.username
id: msg.author.id, });
guildID: message.guild.id
}); const userdata = await this.client.findOrCreateMember({
userdata.money = userdata.money + 100; id: msg.author.id,
userdata.save(); guildID: message.guild.id
collector.stop(msg.author.username); });
userdata.money = userdata.money + (100 * (participants.length * 0.5));
userdata.save();
collector.stop(msg.author.username);
};
}; };
if (parseInt(msg.content) < number) message.error("fun/number:BIG", { if (parseInt(msg.content) < number) message.error("fun/number:BIG", {
user: msg.author.toString(), user: msg.author.toString(),