mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-25 06:34:58 +05:00
(4.1.7) Возвращена команда leaderboard
This commit is contained in:
parent
fe2e598c7b
commit
60ec94558a
4 changed files with 40 additions and 27 deletions
|
@ -1,6 +1,14 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
const BaseCommand = require("../../base/BaseCommand");
|
||||
|
||||
const asyncForEach = async (collection, callback) => {
|
||||
const allPromises = collection.map(async key => {
|
||||
await callback(key);
|
||||
});
|
||||
|
||||
return await Promise.all(allPromises);
|
||||
};
|
||||
|
||||
class Leaderboard extends BaseCommand {
|
||||
/**
|
||||
*
|
||||
|
@ -40,6 +48,7 @@ class Leaderboard extends BaseCommand {
|
|||
*/
|
||||
async execute(client, interaction) {
|
||||
await interaction.deferReply();
|
||||
|
||||
const type = interaction.options.getString("type");
|
||||
const isOnMobile = JSON.stringify(Object.keys(interaction.member.presence.clientStatus)) === JSON.stringify(["mobile"]);
|
||||
if (isOnMobile) interaction.followUp({
|
||||
|
@ -48,15 +57,16 @@ class Leaderboard extends BaseCommand {
|
|||
});
|
||||
|
||||
if (type === "money") {
|
||||
const members = await client.membersData.find({
|
||||
guildID: interaction.guildId
|
||||
}).lean(),
|
||||
membersLeaderboard = members.map(m => {
|
||||
return {
|
||||
id: m.id,
|
||||
money: m.money + m.bankSold
|
||||
};
|
||||
}).sort((a, b) => b.money - a.money);
|
||||
const membersLeaderboard = [],
|
||||
membersData = await client.membersData.find({ guildID: interaction.guildId }).lean();
|
||||
|
||||
await asyncForEach(membersData, async member => {
|
||||
membersLeaderboard.push({
|
||||
id: member.id,
|
||||
money: member.money + member.bankSold
|
||||
});
|
||||
});
|
||||
membersLeaderboard.sort((a, b) => b.money - a.money);
|
||||
if (membersLeaderboard.length > 20) membersLeaderboard.length = 20;
|
||||
|
||||
let userNames = "";
|
||||
|
@ -91,14 +101,14 @@ class Leaderboard extends BaseCommand {
|
|||
embeds: [embed]
|
||||
});
|
||||
} else if (type === "level") {
|
||||
const membersLeaderboard = [];
|
||||
client.membersData.find({
|
||||
guildID: interaction.guildId
|
||||
}).lean().then(async m => {
|
||||
await membersLeaderboard.push({
|
||||
id: m.id,
|
||||
level: m.level,
|
||||
xp: m.exp
|
||||
const membersLeaderboard = [],
|
||||
membersData = await client.membersData.find({ guildID: interaction.guildId }).lean();
|
||||
|
||||
await asyncForEach(membersData, async member => {
|
||||
membersLeaderboard.push({
|
||||
id: member.id,
|
||||
level: member.level,
|
||||
xp: member.exp
|
||||
});
|
||||
});
|
||||
membersLeaderboard.sort((a, b) => b.level - a.level);
|
||||
|
@ -146,15 +156,16 @@ class Leaderboard extends BaseCommand {
|
|||
embeds: [embed]
|
||||
});
|
||||
} else if (type === "rep") {
|
||||
const users = await client.usersData.find({
|
||||
rep: { $gt: 0 }
|
||||
}).lean(),
|
||||
usersLeaderboard = users.map(u => {
|
||||
return {
|
||||
id: u.id,
|
||||
rep: u.rep
|
||||
};
|
||||
}).sort((a, b) => b.rep - a.rep);
|
||||
const usersLeaderboard = [],
|
||||
usersData = await client.usersData.find({ rep: { $gt: 0 } }).lean();
|
||||
|
||||
await asyncForEach(usersData, async user => {
|
||||
usersLeaderboard.push({
|
||||
id: user.id,
|
||||
rep: user.rep
|
||||
});
|
||||
});
|
||||
usersLeaderboard.sort((a, b) => b.rep - a.rep);
|
||||
if (usersLeaderboard.length > 20) usersLeaderboard.length = 20;
|
||||
|
||||
let userNames = "";
|
|
@ -1,5 +1,6 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
const BaseCommand = require("../../base/BaseCommand");
|
||||
|
||||
const asyncForEach = async (collection, callback) => {
|
||||
const allPromises = collection.map(async key => {
|
||||
await callback(key);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
const BaseCommand = require("../../base/BaseCommand");
|
||||
|
||||
const asyncForEach = async (collection, callback) => {
|
||||
const allPromises = collection.map(async key => {
|
||||
await callback(key);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "jaba",
|
||||
"version": "4.1.6",
|
||||
"version": "4.1.7",
|
||||
"description": "My Discord Bot",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
|
|
Loading…
Reference in a new issue