From 5fad488a635b0045d5d8cf2c1bcfb7175f02cb37 Mon Sep 17 00:00:00 2001 From: almeidx Date: Thu, 29 Jul 2021 17:18:49 +0100 Subject: [PATCH] changes to serverinfo and fixes in utils --- .../Utility/functions/getServerInfoEmbed.ts | 20 +++++++++---------- backend/src/utils.ts | 11 +++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts index 89e601fe..a0922399 100644 --- a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts @@ -1,7 +1,8 @@ -import { CategoryChannel, MessageEmbedOptions, Snowflake, TextChannel, VoiceChannel } from "discord.js"; +import { MessageEmbedOptions, Snowflake } from "discord.js"; import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; import moment from "moment-timezone"; +import { ChannelTypeStrings } from "../../../types"; import { EmbedWith, formatNumber, @@ -82,12 +83,11 @@ export async function getServerInfoEmbed( }); // IMAGE LINKS - const iconUrl = `[Link](${(restGuild || guildPreview)!.iconURL()})`; - const bannerUrl = restGuild?.bannerURL() ? `[Link](${restGuild.bannerURL()})` : "None"; - const splashUrl = - (restGuild || guildPreview)!.splashURL() != null - ? `[Link](${(restGuild || guildPreview)!.splashURL()?.replace("size=128", "size=2048")})` - : "None"; + const iconUrl = `[Link](${(restGuild || guildPreview)!.iconURL({ dynamic: true, format: "png", size: 2048 })})`; + const bannerUrl = restGuild?.banner ? `[Link](${restGuild.bannerURL({ format: "png", size: 2048 })})` : "None"; + const splashUrl = (restGuild || guildPreview)!.splash + ? `[Link](${(restGuild || guildPreview)!.splashURL({ format: "png", size: 2048 })})` + : "None"; embed.fields.push( { @@ -155,9 +155,9 @@ export async function getServerInfoEmbed( // CHANNEL COUNTS if (thisServer) { const totalChannels = thisServer.channels.cache.size; - const categories = thisServer.channels.cache.filter(channel => channel instanceof CategoryChannel); - const textChannels = thisServer.channels.cache.filter(channel => channel instanceof TextChannel); - const voiceChannels = thisServer.channels.cache.filter(channel => channel instanceof VoiceChannel); + const categories = thisServer.channels.cache.filter(channel => channel.type === ChannelTypeStrings.CATEGORY); + const textChannels = thisServer.channels.cache.filter(channel => channel.type === ChannelTypeStrings.TEXT); + const voiceChannels = thisServer.channels.cache.filter(channel => channel.type === ChannelTypeStrings.VOICE); embed.fields.push({ name: preEmbedPadding + "Channels", diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 350fd830..a2ea3005 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -1282,7 +1282,7 @@ export async function resolveRoleId(bot: Client, guildId: string, value: string) } // Role name - const roleList = await (await bot.guilds.fetch(guildId as Snowflake)).roles.cache; + const roleList = (await bot.guilds.fetch(guildId as Snowflake)).roles.cache; const role = roleList.filter(x => x.name.toLocaleLowerCase() === value.toLocaleLowerCase()); if (role[0]) { return role[0].id; @@ -1310,7 +1310,6 @@ export async function resolveInvite( return inviteCache.get(key) as ResolveInviteReturnType; } - // @ts-ignore: the getInvite() withCounts typings are blergh const promise = client.fetchInvite(code).catch(() => null); inviteCache.set(key, promise); @@ -1319,12 +1318,14 @@ export async function resolveInvite( const internalStickerCache: LimitedCollection = new LimitedCollection(500); -export async function resolveStickerId(bot: Client, id: Snowflake): Promise { +export async function resolveStickerId(bot: Client, id: Snowflake): Promise { const cachedSticker = internalStickerCache.get(id); if (cachedSticker) return cachedSticker; - const fetchedSticker = await bot.fetchSticker(id).catch(undefined); - internalStickerCache.set(id, fetchedSticker); + const fetchedSticker = await bot.fetchSticker(id).catch(() => null); + if (fetchedSticker) { + internalStickerCache.set(id, fetchedSticker); + } return fetchedSticker; }