changes to serverinfo and fixes in utils
This commit is contained in:
parent
3c6c9ebecf
commit
5fad488a63
2 changed files with 16 additions and 15 deletions
|
@ -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 humanizeDuration from "humanize-duration";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
|
import { ChannelTypeStrings } from "../../../types";
|
||||||
import {
|
import {
|
||||||
EmbedWith,
|
EmbedWith,
|
||||||
formatNumber,
|
formatNumber,
|
||||||
|
@ -82,12 +83,11 @@ export async function getServerInfoEmbed(
|
||||||
});
|
});
|
||||||
|
|
||||||
// IMAGE LINKS
|
// IMAGE LINKS
|
||||||
const iconUrl = `[Link](${(restGuild || guildPreview)!.iconURL()})`;
|
const iconUrl = `[Link](${(restGuild || guildPreview)!.iconURL({ dynamic: true, format: "png", size: 2048 })})`;
|
||||||
const bannerUrl = restGuild?.bannerURL() ? `[Link](${restGuild.bannerURL()})` : "None";
|
const bannerUrl = restGuild?.banner ? `[Link](${restGuild.bannerURL({ format: "png", size: 2048 })})` : "None";
|
||||||
const splashUrl =
|
const splashUrl = (restGuild || guildPreview)!.splash
|
||||||
(restGuild || guildPreview)!.splashURL() != null
|
? `[Link](${(restGuild || guildPreview)!.splashURL({ format: "png", size: 2048 })})`
|
||||||
? `[Link](${(restGuild || guildPreview)!.splashURL()?.replace("size=128", "size=2048")})`
|
: "None";
|
||||||
: "None";
|
|
||||||
|
|
||||||
embed.fields.push(
|
embed.fields.push(
|
||||||
{
|
{
|
||||||
|
@ -155,9 +155,9 @@ export async function getServerInfoEmbed(
|
||||||
// CHANNEL COUNTS
|
// CHANNEL COUNTS
|
||||||
if (thisServer) {
|
if (thisServer) {
|
||||||
const totalChannels = thisServer.channels.cache.size;
|
const totalChannels = thisServer.channels.cache.size;
|
||||||
const categories = thisServer.channels.cache.filter(channel => channel instanceof CategoryChannel);
|
const categories = thisServer.channels.cache.filter(channel => channel.type === ChannelTypeStrings.CATEGORY);
|
||||||
const textChannels = thisServer.channels.cache.filter(channel => channel instanceof TextChannel);
|
const textChannels = thisServer.channels.cache.filter(channel => channel.type === ChannelTypeStrings.TEXT);
|
||||||
const voiceChannels = thisServer.channels.cache.filter(channel => channel instanceof VoiceChannel);
|
const voiceChannels = thisServer.channels.cache.filter(channel => channel.type === ChannelTypeStrings.VOICE);
|
||||||
|
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + "Channels",
|
name: preEmbedPadding + "Channels",
|
||||||
|
|
|
@ -1282,7 +1282,7 @@ export async function resolveRoleId(bot: Client, guildId: string, value: string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Role name
|
// 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());
|
const role = roleList.filter(x => x.name.toLocaleLowerCase() === value.toLocaleLowerCase());
|
||||||
if (role[0]) {
|
if (role[0]) {
|
||||||
return role[0].id;
|
return role[0].id;
|
||||||
|
@ -1310,7 +1310,6 @@ export async function resolveInvite<T extends boolean>(
|
||||||
return inviteCache.get(key) as ResolveInviteReturnType<T>;
|
return inviteCache.get(key) as ResolveInviteReturnType<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore: the getInvite() withCounts typings are blergh
|
|
||||||
const promise = client.fetchInvite(code).catch(() => null);
|
const promise = client.fetchInvite(code).catch(() => null);
|
||||||
inviteCache.set(key, promise);
|
inviteCache.set(key, promise);
|
||||||
|
|
||||||
|
@ -1319,12 +1318,14 @@ export async function resolveInvite<T extends boolean>(
|
||||||
|
|
||||||
const internalStickerCache: LimitedCollection<Snowflake, Sticker> = new LimitedCollection(500);
|
const internalStickerCache: LimitedCollection<Snowflake, Sticker> = new LimitedCollection(500);
|
||||||
|
|
||||||
export async function resolveStickerId(bot: Client, id: Snowflake): Promise<Sticker> {
|
export async function resolveStickerId(bot: Client, id: Snowflake): Promise<Sticker | null> {
|
||||||
const cachedSticker = internalStickerCache.get(id);
|
const cachedSticker = internalStickerCache.get(id);
|
||||||
if (cachedSticker) return cachedSticker;
|
if (cachedSticker) return cachedSticker;
|
||||||
|
|
||||||
const fetchedSticker = await bot.fetchSticker(id).catch(undefined);
|
const fetchedSticker = await bot.fetchSticker(id).catch(() => null);
|
||||||
internalStickerCache.set(id, fetchedSticker);
|
if (fetchedSticker) {
|
||||||
|
internalStickerCache.set(id, fetchedSticker);
|
||||||
|
}
|
||||||
|
|
||||||
return fetchedSticker;
|
return fetchedSticker;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue