mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 05:04:58 +05:00
Перенос функции asyncForEach в client.functions
This commit is contained in:
parent
c232c7b205
commit
e94237dfb3
4 changed files with 19 additions and 29 deletions
|
@ -1,14 +1,6 @@
|
||||||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||||
const BaseCommand = require("../../base/BaseCommand");
|
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 {
|
class Leaderboard extends BaseCommand {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -60,7 +52,7 @@ class Leaderboard extends BaseCommand {
|
||||||
const membersLeaderboard = [],
|
const membersLeaderboard = [],
|
||||||
membersData = await client.membersData.find({ guildID: interaction.guildId }).lean();
|
membersData = await client.membersData.find({ guildID: interaction.guildId }).lean();
|
||||||
|
|
||||||
await asyncForEach(membersData, async member => {
|
await client.functions.asyncForEach(membersData, async member => {
|
||||||
membersLeaderboard.push({
|
membersLeaderboard.push({
|
||||||
id: member.id,
|
id: member.id,
|
||||||
money: member.money + member.bankSold,
|
money: member.money + member.bankSold,
|
||||||
|
@ -103,7 +95,7 @@ class Leaderboard extends BaseCommand {
|
||||||
const membersLeaderboard = [],
|
const membersLeaderboard = [],
|
||||||
membersData = await client.membersData.find({ guildID: interaction.guildId }).lean();
|
membersData = await client.membersData.find({ guildID: interaction.guildId }).lean();
|
||||||
|
|
||||||
await asyncForEach(membersData, async member => {
|
await client.functions.asyncForEach(membersData, async member => {
|
||||||
membersLeaderboard.push({
|
membersLeaderboard.push({
|
||||||
id: member.id,
|
id: member.id,
|
||||||
level: member.level,
|
level: member.level,
|
||||||
|
@ -157,7 +149,7 @@ class Leaderboard extends BaseCommand {
|
||||||
const usersLeaderboard = [],
|
const usersLeaderboard = [],
|
||||||
usersData = await client.usersData.find({ rep: { $gt: 0 } }).lean();
|
usersData = await client.usersData.find({ rep: { $gt: 0 } }).lean();
|
||||||
|
|
||||||
await asyncForEach(usersData, async user => {
|
await client.functions.asyncForEach(usersData, async user => {
|
||||||
usersLeaderboard.push({
|
usersLeaderboard.push({
|
||||||
id: user.id,
|
id: user.id,
|
||||||
rep: user.rep,
|
rep: user.rep,
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||||
const BaseCommand = require("../../base/BaseCommand");
|
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 Money extends BaseCommand {
|
class Money extends BaseCommand {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -53,7 +45,7 @@ class Money extends BaseCommand {
|
||||||
|
|
||||||
const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id));
|
const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id));
|
||||||
let globalMoney = 0;
|
let globalMoney = 0;
|
||||||
await asyncForEach(guilds, async guild => {
|
await client.functions.asyncForEach(guilds, async guild => {
|
||||||
const data = await client.findOrCreateMember({
|
const data = await client.findOrCreateMember({
|
||||||
id: member.id,
|
id: member.id,
|
||||||
guildId: guild.id,
|
guildId: guild.id,
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||||
const BaseCommand = require("../../base/BaseCommand");
|
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 Profile extends BaseCommand {
|
class Profile extends BaseCommand {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -58,7 +50,7 @@ class Profile extends BaseCommand {
|
||||||
|
|
||||||
const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id));
|
const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id));
|
||||||
let globalMoney = 0;
|
let globalMoney = 0;
|
||||||
await asyncForEach(guilds, async guild => {
|
await client.functions.asyncForEach(guilds, async guild => {
|
||||||
const data = await client.findOrCreateMember({
|
const data = await client.findOrCreateMember({
|
||||||
id: member.id,
|
id: member.id,
|
||||||
guildId: guild.id,
|
guildId: guild.id,
|
||||||
|
|
|
@ -14,6 +14,20 @@ module.exports = {
|
||||||
if (channel) return (await channel.createInvite()).url || "No channels found or missing permissions";
|
if (channel) return (await channel.createInvite()).url || "No channels found or missing permissions";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls a callback for each element in collection async
|
||||||
|
* @param {Array} collection
|
||||||
|
* @param {Function} callback
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
async asyncForEach (collection, callback) {
|
||||||
|
const allPromises = collection.map(async key => {
|
||||||
|
await callback(key);
|
||||||
|
});
|
||||||
|
|
||||||
|
return await Promise.all(allPromises);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort array by key
|
* Sort array by key
|
||||||
* @param {Array} array Array to sort
|
* @param {Array} array Array to sort
|
||||||
|
|
Loading…
Reference in a new issue