Наконец то фикс

Возвращены кредиты со всех серверов в profile и money
This commit is contained in:
JonnyBro 2022-01-06 19:46:10 +05:00
parent c596f314e1
commit e6be809cec
6 changed files with 44 additions and 60 deletions

View file

@ -24,7 +24,6 @@ class Birthdate extends Command {
const [day, month, year] = tArgs; const [day, month, year] = tArgs;
if (!day || !month || !year) return message.error("economy/birthdate:INVALID_DATE"); if (!day || !month || !year) return message.error("economy/birthdate:INVALID_DATE");
// Gets the string of the date
const match = date.match(/\d+/g); const match = date.match(/\d+/g);
if (!match) return message.error("economy/birthdate:INVALID_DATE"); if (!match) return message.error("economy/birthdate:INVALID_DATE");

View file

@ -20,12 +20,8 @@ class Marry extends Command {
} }
async run(message, args, data) { async run(message, args, data) {
// if the message author is already wedded if (data.userData.lover) return message.error("economy/marry:ALREADY_MARRIED", { prefix: data.guild.prefix });
if (data.userData.lover) return message.error("economy/marry:ALREADY_MARRIED", {
prefix: data.guild.prefix
});
// Gets the first mentionned member
const member = await this.client.resolveMember(args[0], message.guild); const member = await this.client.resolveMember(args[0], message.guild);
if (!member) return message.error("economy/marry:INVALID_MEMBER"); if (!member) return message.error("economy/marry:INVALID_MEMBER");
@ -33,13 +29,8 @@ class Marry extends Command {
id: member.id id: member.id
}); });
// if the member is already wedded if (userData.lover) return message.error("economy/marry:ALREADY_MARRIED_USER", { username: member.user.tag });
if (userData.lover) return message.error("economy/marry:ALREADY_MARRIED_USER", {
username: member.user.tag
});
if (member.user.bot) return message.error("economy/marry:BOT_USER"); if (member.user.bot) return message.error("economy/marry:BOT_USER");
if (member.id === message.author.id) return message.error("economy/marry:YOURSELF"); if (member.id === message.author.id) return message.error("economy/marry:YOURSELF");
for (const requester in pendings) { for (const requester in pendings) {

View file

@ -1,20 +1,22 @@
const Command = require("../../base/Command.js"), const Command = require("../../base/Command.js"),
Discord = require("discord.js"); Discord = require("discord.js");
// const asyncForEach = async (array, callback) => { const asyncForEach = async (collection, callback) => {
// for (let index = 0; index < array.size; index++) { const allPromises = collection.map(async key => {
// await callback(index, array); await callback(key);
// }; });
// };
class Credits extends Command { return await Promise.all(allPromises);
};
class Money extends Command {
constructor(client) { constructor(client) {
super(client, { super(client, {
name: "money", name: "money",
dirname: __dirname, dirname: __dirname,
enabled: true, enabled: true,
guildOnly: true, guildOnly: true,
aliases: ["credits", "balance", "mon"], aliases: ["balance", "mon"],
memberPermissions: [], memberPermissions: [],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"], botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
nsfw: false, nsfw: false,
@ -36,16 +38,15 @@ class Credits extends Command {
}); });
const commonsGuilds = this.client.guilds.cache.filter((g) => g.members.cache.get(user.id)); const commonsGuilds = this.client.guilds.cache.filter((g) => g.members.cache.get(user.id));
const globalMoney = memberData.money + memberData.bankSold; let globalMoney = 0;
// let globalMoney = 0; await asyncForEach(commonsGuilds, async (guild) => {
// await asyncForEach(commonsGuilds, async (guild) => { const data = await this.client.findOrCreateMember({
// const memberData = await this.client.findOrCreateMember({ id: user.id,
// id: user.id, guildID: guild.id
// guildID: guild.id });
// }); globalMoney += data.money;
// globalMoney += memberData.money; globalMoney += data.bankSold;
// globalMoney += memberData.bankSold; });
// });
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setAuthor({ .setAuthor({
@ -71,4 +72,4 @@ class Credits extends Command {
} }
}; };
module.exports = Credits; module.exports = Money;

View file

@ -1,11 +1,13 @@
const Command = require("../../base/Command.js"), const Command = require("../../base/Command.js"),
Discord = require("discord.js"); Discord = require("discord.js");
// const asyncForEach = async (array, callback) => { const asyncForEach = async (collection, callback) => {
// for (let index = 0; index < array.size; index++) { const allPromises = collection.map(async key => {
// await callback(index, array); await callback(key);
// }; });
// };
return await Promise.all(allPromises);
};
class Profile extends Command { class Profile extends Command {
constructor(client) { constructor(client) {
@ -24,33 +26,30 @@ class Profile extends Command {
} }
async run(message, args, data) { async run(message, args, data) {
const client = this.client;
const arg = args[0] || message.author const arg = args[0] || message.author
let member = await client.resolveMember(arg, message.guild); let member = await this.client.resolveMember(arg, message.guild);
if (!member) member = message.member; if (!member) member = message.member;
if (member.user.bot) return message.error("economy/profile:BOT_USER"); if (member.user.bot) return message.error("economy/profile:BOT_USER");
const memberData = (member.id === message.author.id ? data.memberData : await client.findOrCreateMember({ const memberData = (member.id === message.author.id ? data.memberData : await this.client.findOrCreateMember({
id: member.id, id: member.id,
guildID: message.guild.id guildID: message.guild.id
})); }));
const userData = (member.id === message.author.id ? data.userData : await client.findOrCreateUser({ const userData = (member.id === message.author.id ? data.userData : await this.client.findOrCreateUser({
id: member.id id: member.id
})); }));
if (userData.lover && !this.client.users.cache.get(userData.lover)) await this.client.users.fetch(userData.lover, true); if (userData.lover && !this.client.users.cache.get(userData.lover)) await this.client.users.fetch(userData.lover, true);
const commonsGuilds = client.guilds.cache.filter((g) => g.members.cache.get(member.id)); const commonsGuilds = this.client.guilds.cache.filter((g) => g.members.cache.get(member.id));
const globalMoney = memberData.money + memberData.bankSold; let globalMoney = 0;
// let globalMoney = 0; await asyncForEach(commonsGuilds, async (guild) => {
// await asyncForEach(commonsGuilds, async (guild) => { const data = await this.client.findOrCreateMember({
// const memberData = await client.findOrCreateMember({ id: member.id,
// id: member.id, guildID: guild.id
// guildID: guild.id });
// }); globalMoney += data.money;
// globalMoney += memberData.money; globalMoney += data.bankSold;
// globalMoney += memberData.bankSold; });
// });
const profileEmbed = new Discord.MessageEmbed() const profileEmbed = new Discord.MessageEmbed()
.setAuthor({ .setAuthor({

View file

@ -24,20 +24,15 @@ class Np extends Command {
if (!voice) return message.error("music/play:NO_VOICE_CHANNEL"); if (!voice) return message.error("music/play:NO_VOICE_CHANNEL");
if (!queue) return message.error("music/play:NOT_PLAYING"); if (!queue) return message.error("music/play:NOT_PLAYING");
// Gets the current song
const track = queue.songs[0]; const track = queue.songs[0];
const status = queue => const status = queue =>
`Фильтры: \`${queue.filters.join(", ") `Фильтры: \`${queue.filters.join(", ") || "Выкл"}\` | Повтор: \`${
|| "Выкл"}\` | Повтор: \`${
queue.repeatMode queue.repeatMode
? queue.repeatMode === 2 ? queue.repeatMode === 2 ? "Очереди" : "Трека"
? "Очереди"
: "Трека"
: "Выкл" : "Выкл"
}\` | Автовоспроизведение: \`${queue.autoplay ? "Вкл" : "Выкл"}\``; }\` | Автовоспроизведение: \`${queue.autoplay ? "Вкл" : "Выкл"}\``;
// Generate discord embed to display song informations
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setAuthor({ .setAuthor({
name: message.translate("music/queue:TITLE") name: message.translate("music/queue:TITLE")
@ -53,7 +48,6 @@ class Np extends Command {
}) })
.setTimestamp(); .setTimestamp();
// Send the embed in the current channel
message.channel.send({ message.channel.send({
embeds: [embed] embeds: [embed]
}); });

View file

@ -9,7 +9,7 @@
"NO_BIO": "Биография отсутствует", "NO_BIO": "Биография отсутствует",
"CASH": "💵 Кредиты", "CASH": "💵 Кредиты",
"BANK": "💳 Банк", "BANK": "💳 Банк",
"GLOBAL": "🌍 Всего кредитов на текущем сервере", "GLOBAL": "🌍 Всего кредитов на всех серверах",
"REPUTATION": "🎩 Репутация", "REPUTATION": "🎩 Репутация",
"LEVEL": "📊 Уровень", "LEVEL": "📊 Уровень",
"EXP": "🔮 Опыт", "EXP": "🔮 Опыт",