From 456c8a042baa383705d6f937cc711ae7fa6d6828 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Sat, 1 Jan 2022 19:55:10 -0300 Subject: [PATCH 01/12] created the branch but forgot to send the commit --- src/commands/utility/guildinfo.js | 11 ++++++++--- src/locales/en-US/commands.json | 3 ++- src/utils/PermissionUtils.js | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/commands/utility/guildinfo.js b/src/commands/utility/guildinfo.js index 6d582967c..048ea37be 100644 --- a/src/commands/utility/guildinfo.js +++ b/src/commands/utility/guildinfo.js @@ -16,21 +16,26 @@ module.exports = class GuildInfo extends Command { }, client) } - run ({ t, author, channel, language }, guild = channel.guild) { + async run ({ t, author, channel, language }, guild = channel.guild) { + if (guild.members.cache.size !== guild.memberCount) { + guild.members.fetch({ withPresences: true }) + } const embed = new SwitchbladeEmbed(author) moment.locale(language) channel.startTyping() embed.setTitle(guild.name) .setThumbnail(guild.iconURL({ dynamic: true }) ? guild.iconURL({ dynamic: true }) : `https://guild-default-icon.herokuapp.com/${guild.nameAcronym}`) .addField(t('commands:guildinfo.id'), guild.id, true) - .addField(t('commands:guildinfo.owner'), guild.owner, true) - .addField(t('commands:guildinfo.region'), t(`regions:${guild.region}`), true) + .addField(t('commands:guildinfo.owner'), `<@${guild.ownerID}>`, true) .addField(t('commands:guildinfo.channels', { count: MiscUtils.formatNumber(guild.channels.cache.size, language) }), [ t('commands:guildinfo.textChannels', { count: MiscUtils.formatNumber(guild.channels.cache.filter(g => g.type === 'text' || g.type === 'category').size, language) }), t('commands:guildinfo.voiceChannels', { count: MiscUtils.formatNumber(guild.channels.cache.filter(g => g.type === 'voice').size, language) }) ].join('\n'), true) .addField(t('commands:guildinfo.createdAt'), `${moment(guild.createdTimestamp).format('LLL')}\n(${moment(guild.createdTimestamp).fromNow()})`, true) .addField(t('commands:guildinfo.joinedAt'), `${moment(guild.joinedTimestamp).format('LLL')}\n(${moment(guild.joinedTimestamp).fromNow()})`, true) + .addField(t('commands:guildinfo.serverBoost', { count: MiscUtils.formatNumber(guild.premiumSubscriptionCount, language) }), [ + t('commands:guildinfo.level', { count: MiscUtils.formatNumber(guild.premiumTier, language) }) + ].join('\n'), true) .addField(t('commands:guildinfo.members', { count: MiscUtils.formatNumber(guild.members.cache.size, language) }), [ `${this.getEmoji('streaming')} ${t('commands:guildinfo.streaming', { count: MiscUtils.formatNumber(guild.members.cache.filter(m => m.game === 'streaming').size, language) })}`, `${this.getEmoji('online')} ${t('commands:guildinfo.online', { count: MiscUtils.formatNumber(guild.members.cache.filter(m => m.presence.status === 'online').size, language) })}`, diff --git a/src/locales/en-US/commands.json b/src/locales/en-US/commands.json index b2f1e50f2..fd080c685 100644 --- a/src/locales/en-US/commands.json +++ b/src/locales/en-US/commands.json @@ -464,7 +464,8 @@ "commandUsage": "[server id]", "id": "ID", "owner": "Owner", - "region": "Region", + "serverBoost": "Server Boost (**{{count}}**)", + "level": "Level: **{{count}}**", "channels": "Channels **({{count}})**", "textChannels": "Text: **{{count}}**", "voiceChannels": "Voice: **{{count}}**", diff --git a/src/utils/PermissionUtils.js b/src/utils/PermissionUtils.js index 3bbf203c7..f6b5bae50 100644 --- a/src/utils/PermissionUtils.js +++ b/src/utils/PermissionUtils.js @@ -10,8 +10,8 @@ module.exports = class PermissionUtils { } static specialRole (client, user) { - const botGuild = client.guilds.cache.get(process.env.BOT_GUILD) - const member = botGuild && botGuild.members.cache.get(user.id) + const botGuild = client.guilds.fetch(process.env.BOT_GUILD) + const member = botGuild && botGuild.members.fetch(user.id) if (member) { return member.roles.cache.filter(r => r.hoist).sort((a, b) => b.position - a.position).first() } From 420764cd51e78959fef3862d4a5e4989279e6ff1 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Sat, 1 Jan 2022 19:59:16 -0300 Subject: [PATCH 02/12] trying to make the website work fine --- src/http/api/contributors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http/api/contributors.js b/src/http/api/contributors.js index e116ef015..636169ca5 100644 --- a/src/http/api/contributors.js +++ b/src/http/api/contributors.js @@ -12,7 +12,7 @@ module.exports = class Contributors extends Route { const router = Router() router.get('/', async (req, res) => { - const guild = this.client.guilds.cache.get(process.env.BOT_GUILD) + const guild = this.client.guilds.fetch(process.env.BOT_GUILD) const roles = guild.roles.cache const members = await guild.members.fetch() From 9b46197a11bec2f383be6fee9fcb79c3d109d620 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Sat, 1 Jan 2022 20:02:53 -0300 Subject: [PATCH 03/12] metaverse this, metaverse that, why don't you met a girl??? --- src/http/api/contributors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http/api/contributors.js b/src/http/api/contributors.js index 636169ca5..385abd68f 100644 --- a/src/http/api/contributors.js +++ b/src/http/api/contributors.js @@ -8,11 +8,11 @@ module.exports = class Contributors extends Route { }, client) } - register (app) { + async register (app) { const router = Router() router.get('/', async (req, res) => { - const guild = this.client.guilds.fetch(process.env.BOT_GUILD) + const guild = await this.client.guilds.fetch(process.env.BOT_GUILD) const roles = guild.roles.cache const members = await guild.members.fetch() From 39ca4140bda4b6b798c9d36d5c42c8da7d164da8 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Sat, 1 Jan 2022 21:03:41 -0300 Subject: [PATCH 04/12] =?UTF-8?q?chuto=20que=20tudo=20isso=20vai=20funcion?= =?UTF-8?q?ar=20numa=20boa=20sem=20dar=20erro,=20espero=20que=20aconte?= =?UTF-8?q?=C3=A7a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/http/api/guilds.js | 13 +++++++------ src/http/api/statistics.js | 10 +++++++--- src/utils/EndpointUtils.js | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/http/api/guilds.js b/src/http/api/guilds.js index a78c51462..1380400a9 100644 --- a/src/http/api/guilds.js +++ b/src/http/api/guilds.js @@ -8,17 +8,18 @@ module.exports = class Guilds extends Route { }, client) } - register (app) { + async register (app) { const router = Router() // Info router.get('/:guildId/members', async (req, res) => { - const guild = this.client.guilds.cache.get(req.params.guildId) + const guild = await this.client.guilds.fetch(req.params.guildId) + const guildMembers = await guild.members.fetch() if (guild) { - const { id, name, icon, members: { size } } = guild - const userMembers = guild.members.filter(m => !m.user.bot).size - const botMembers = size - userMembers - return res.status(200).json({ id, name, icon, totalMembers: size, userMembers, botMembers }) + const { id, name, icon, memberCount } = guild + const userMembers = guildMembers.filter(m => !m.user.bot).size + const botMembers = memberCount - userMembers + return res.status(200).json({ id, name, icon, totalMembers: memberCount, userMembers, botMembers }) } res.status(400).json({ error: 'Guild not found!' }) }) diff --git a/src/http/api/statistics.js b/src/http/api/statistics.js index 6f7655af7..ce4b50247 100644 --- a/src/http/api/statistics.js +++ b/src/http/api/statistics.js @@ -9,13 +9,17 @@ module.exports = class Statistics extends Route { }, client) } - register (app) { + async register (app) { const router = Router() + const shardGuildCounts = await this.client.shard.fetchClientValues('guilds.cache.size') + const totalGuildCount = shardGuildCounts.reduce((total, current) => total + current) + const shardUserCounts = await this.client.shard.fetchClientValues('users.cache.size') + const totalUserCount = shardUserCounts.reduce((total, current) => total + current) router.get('/', (req, res) => { res.status(200).json({ - serverCount: this.client.guilds.size, - userCount: this.client.users.size, + serverCount: totalGuildCount, + userCount: totalUserCount, uptime: process.uptime() * 1000, commandCount: this.client.commands.length, languageCount: Object.keys(i18next.store.data).length diff --git a/src/utils/EndpointUtils.js b/src/utils/EndpointUtils.js index eb37f093e..ca9b2bfba 100644 --- a/src/utils/EndpointUtils.js +++ b/src/utils/EndpointUtils.js @@ -43,7 +43,7 @@ module.exports = class EndpointUtils { static async _fetchGuilds (client, token) { return this._requestDiscord('/users/@me/guilds', token).then(gs => gs.map(g => { - g.common = client.guilds.cache.has(g.id) + g.common = client.guilds.fetch.has(g.id) return g })) } From 4a733efc1a15ba51c52079cf8bccbe800bb1a664 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Sat, 1 Jan 2022 21:36:10 -0300 Subject: [PATCH 05/12] simple thing so the bot does not crashes --- src/listeners/MainListener.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/listeners/MainListener.js b/src/listeners/MainListener.js index 46f339b09..862b10860 100644 --- a/src/listeners/MainListener.js +++ b/src/listeners/MainListener.js @@ -137,6 +137,7 @@ module.exports = class MainListener extends EventListener { const cmd = fullCmd[0].toLowerCase().trim() const command = this.commands.find(c => c.name.toLowerCase() === cmd || (c.aliases && c.aliases.includes(cmd))) if (command) { + if (!message.channel.permissionsFor(this.user.id).has('SEND_MESSAGES')) return const userDocument = this.database && await this.database.users.findOne(message.author.id, 'blacklisted') if (userDocument && userDocument.blacklisted) return From 2e2d0d35462df61cf95be733436cf6d30e3c36a9 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Sat, 1 Jan 2022 21:37:09 -0300 Subject: [PATCH 06/12] go back --- src/utils/EndpointUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/EndpointUtils.js b/src/utils/EndpointUtils.js index ca9b2bfba..eb37f093e 100644 --- a/src/utils/EndpointUtils.js +++ b/src/utils/EndpointUtils.js @@ -43,7 +43,7 @@ module.exports = class EndpointUtils { static async _fetchGuilds (client, token) { return this._requestDiscord('/users/@me/guilds', token).then(gs => gs.map(g => { - g.common = client.guilds.fetch.has(g.id) + g.common = client.guilds.cache.has(g.id) return g })) } From e65ada44da100f88578feb87b725ba33701c6761 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Mon, 3 Jan 2022 14:26:35 -0300 Subject: [PATCH 07/12] Update src/commands/utility/guildinfo.js Co-authored-by: Fernando Silva --- src/commands/utility/guildinfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/utility/guildinfo.js b/src/commands/utility/guildinfo.js index 048ea37be..011a901b0 100644 --- a/src/commands/utility/guildinfo.js +++ b/src/commands/utility/guildinfo.js @@ -18,7 +18,7 @@ module.exports = class GuildInfo extends Command { async run ({ t, author, channel, language }, guild = channel.guild) { if (guild.members.cache.size !== guild.memberCount) { - guild.members.fetch({ withPresences: true }) + await guild.members.fetch({ withPresences: true }) } const embed = new SwitchbladeEmbed(author) moment.locale(language) From d20500bf6cbbf76c2b8f588047fb18f00b9eb89d Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Mon, 3 Jan 2022 14:26:47 -0300 Subject: [PATCH 08/12] Update src/utils/PermissionUtils.js Co-authored-by: Fernando Silva --- src/utils/PermissionUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/PermissionUtils.js b/src/utils/PermissionUtils.js index f6b5bae50..d2c0e72bb 100644 --- a/src/utils/PermissionUtils.js +++ b/src/utils/PermissionUtils.js @@ -9,7 +9,7 @@ module.exports = class PermissionUtils { return isDeveloper } - static specialRole (client, user) { + static async specialRole (client, user) { const botGuild = client.guilds.fetch(process.env.BOT_GUILD) const member = botGuild && botGuild.members.fetch(user.id) if (member) { From 5587a6e45d8ec8142bf0f39bc8a4075419bfcd6c Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Mon, 3 Jan 2022 14:26:54 -0300 Subject: [PATCH 09/12] Update src/utils/PermissionUtils.js Co-authored-by: Fernando Silva --- src/utils/PermissionUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/PermissionUtils.js b/src/utils/PermissionUtils.js index d2c0e72bb..91422bfa4 100644 --- a/src/utils/PermissionUtils.js +++ b/src/utils/PermissionUtils.js @@ -10,8 +10,8 @@ module.exports = class PermissionUtils { } static async specialRole (client, user) { - const botGuild = client.guilds.fetch(process.env.BOT_GUILD) - const member = botGuild && botGuild.members.fetch(user.id) + const botGuild = await client.guilds.fetch(process.env.BOT_GUILD) + const member = botGuild && await botGuild.members.fetch(user.id) if (member) { return member.roles.cache.filter(r => r.hoist).sort((a, b) => b.position - a.position).first() } From 60c9f2291d989dec34b4e157ed3ab176bbded266 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Mon, 3 Jan 2022 16:19:50 -0300 Subject: [PATCH 10/12] Update src/http/api/statistics.js Co-authored-by: Almeida --- src/http/api/statistics.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http/api/statistics.js b/src/http/api/statistics.js index ce4b50247..c2cd785df 100644 --- a/src/http/api/statistics.js +++ b/src/http/api/statistics.js @@ -13,8 +13,8 @@ module.exports = class Statistics extends Route { const router = Router() const shardGuildCounts = await this.client.shard.fetchClientValues('guilds.cache.size') const totalGuildCount = shardGuildCounts.reduce((total, current) => total + current) - const shardUserCounts = await this.client.shard.fetchClientValues('users.cache.size') - const totalUserCount = shardUserCounts.reduce((total, current) => total + current) + const shardUserCounts = await this.client.shard.broadcastEval('this.guilds.cache.reduce((acc, g) => acc + g.memberCount, 0)') + const totalUserCount = shardUserCounts.reduce((total, current) => total + current, 0) router.get('/', (req, res) => { res.status(200).json({ From bd182dd4e0c006be43bd113158dd56c480e7da17 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Mon, 3 Jan 2022 16:19:55 -0300 Subject: [PATCH 11/12] Update src/http/api/statistics.js Co-authored-by: Almeida --- src/http/api/statistics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http/api/statistics.js b/src/http/api/statistics.js index c2cd785df..0b6e45c0b 100644 --- a/src/http/api/statistics.js +++ b/src/http/api/statistics.js @@ -12,7 +12,7 @@ module.exports = class Statistics extends Route { async register (app) { const router = Router() const shardGuildCounts = await this.client.shard.fetchClientValues('guilds.cache.size') - const totalGuildCount = shardGuildCounts.reduce((total, current) => total + current) + const totalGuildCount = shardGuildCounts.reduce((total, current) => total + current, 0) const shardUserCounts = await this.client.shard.broadcastEval('this.guilds.cache.reduce((acc, g) => acc + g.memberCount, 0)') const totalUserCount = shardUserCounts.reduce((total, current) => total + current, 0) From 78e269bad562d9f1a6aedb97613e0cdf8a164d31 Mon Sep 17 00:00:00 2001 From: Doges <31023616+Doges@users.noreply.github.com> Date: Tue, 4 Jan 2022 12:28:53 -0300 Subject: [PATCH 12/12] ADD TODOS and fix one more thing --- src/commands/social/leaderboard/money.js | 1 + src/commands/social/leaderboard/reputation.js | 1 + src/utils/EndpointUtils.js | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/social/leaderboard/money.js b/src/commands/social/leaderboard/money.js index a867c6170..c47a15579 100644 --- a/src/commands/social/leaderboard/money.js +++ b/src/commands/social/leaderboard/money.js @@ -11,6 +11,7 @@ module.exports = class MoneyLeaderboard extends Command { } async run ({ t, author, channel }) { + // TODO: Remake everything because it's not working properly channel.startTyping() const top = await this.client.controllers.social.leaderboard('money') diff --git a/src/commands/social/leaderboard/reputation.js b/src/commands/social/leaderboard/reputation.js index 34b7e6463..23e1ef5e0 100644 --- a/src/commands/social/leaderboard/reputation.js +++ b/src/commands/social/leaderboard/reputation.js @@ -11,6 +11,7 @@ module.exports = class ReputationLeaderboard extends Command { } async run ({ t, author, channel }) { + // TODO: Remake everything because it's not working properly channel.startTyping() const top = await this.client.controllers.social.leaderboard('rep') diff --git a/src/utils/EndpointUtils.js b/src/utils/EndpointUtils.js index eb37f093e..a335ea730 100644 --- a/src/utils/EndpointUtils.js +++ b/src/utils/EndpointUtils.js @@ -43,7 +43,7 @@ module.exports = class EndpointUtils { static async _fetchGuilds (client, token) { return this._requestDiscord('/users/@me/guilds', token).then(gs => gs.map(g => { - g.common = client.guilds.cache.has(g.id) + g.common = client.guilds.fetch(g.id) return g })) } @@ -81,7 +81,7 @@ module.exports = class EndpointUtils { const guild = client.guilds.cache.get(id) if (!guild) return res.status(400).json({ ok: false }) if (!req.isAdmin) { - const member = await guild.fetchMember(req.user.id) + const member = await guild.members.fetch(req.user.id) if (!member || (permissions && !member.hasPermission(permissions))) return res.status(403).json({ error: 'Missing permissions!' }) } req.guildId = id