aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-03 21:57:15 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-03 21:57:15 -0500
commitc544cee715d61570a693e300337da08a21213a0e (patch)
treeec34a19e4ace357665d7f6580a3018a8024ddb45 /src/commands
parent821ed93ccf55e4f32f6f25f502bce1e5b161d356 (diff)
downloadtanzanite-c544cee715d61570a693e300337da08a21213a0e.tar.gz
tanzanite-c544cee715d61570a693e300337da08a21213a0e.tar.bz2
tanzanite-c544cee715d61570a693e300337da08a21213a0e.zip
refactor guild info command
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/info/guildInfo.ts197
1 files changed, 110 insertions, 87 deletions
diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts
index 55fb0b2..a4b7fb9 100644
--- a/src/commands/info/guildInfo.ts
+++ b/src/commands/info/guildInfo.ts
@@ -51,37 +51,74 @@ export default class GuildInfoCommand extends BushCommand {
);
}
- const otherEmojis = client.consts.mappings.otherEmojis;
- let isPreview = false;
- let _guild: ArgType<'guild'> | ArgType<'snowflake'> | GuildPreview = args.guild ?? message.guild!;
- if (typeof _guild === 'string') {
- const preview = await client.fetchGuildPreview(`${args.guild}` as Snowflake).catch(() => {});
- if (preview) {
- _guild = preview;
- isPreview = true;
- } else {
- return await message.util.reply(`${util.emojis.error} That guild is not discoverable or does not exist.`);
- }
+ let guild: ArgType<'guild'> | ArgType<'snowflake'> | GuildPreview = args.guild ?? message.guild!;
+ if (typeof guild === 'string') {
+ const preview = await client.fetchGuildPreview(`${args.guild}` as Snowflake).catch(() => undefined);
+ if (preview) guild = preview;
+ else return await message.util.reply(`${util.emojis.error} That guild is not discoverable or does not exist.`);
}
- const guild: Guild | GuildPreview = _guild;
assert(guild);
- const emojis: string[] = [];
- const guildAbout: string[] = [];
- const guildStats: string[] = [];
- const guildSecurity: string[] = [];
- const verifiedGuilds = Object.values(client.consts.mappings.guilds);
- if (verifiedGuilds.includes(guild.id as typeof verifiedGuilds[number])) emojis.push(otherEmojis.BushVerified);
- if (!isPreview && guild instanceof Guild) {
- if (guild.premiumTier !== GuildPremiumTier.None) emojis.push(otherEmojis[`BoostTier${guild.premiumTier}`]);
+ if (guild instanceof Guild) {
await guild.fetch();
- const channels = guild.channels.cache;
+ }
- const channelTypes = (['Text', 'Voice', 'News', 'Stage', 'Store', 'Category', 'Thread'] as const).map(
- (type) => `${otherEmojis[`Channel${type}`]} ${channels.filter((channel) => channel[`is${type}`]()).size.toLocaleString()}`
- );
+ const guildInfoEmbed = new Embed().setTitle(guild.name).setColor(util.colors.default);
+ if (guild.icon) guildInfoEmbed.setThumbnail(guild.iconURL({ size: 2048, extension: 'png' }));
+
+ await this.generateAboutField(guildInfoEmbed, guild);
+
+ this.generateStatsField(guildInfoEmbed, guild);
+
+ this.generateSecurityField(guildInfoEmbed, guild);
+
+ this.generateDescription(guildInfoEmbed, guild);
+
+ return await message.util.reply({ embeds: [guildInfoEmbed] });
+ }
+
+ private generateDescription(embed: Embed, guild: Guild | GuildPreview) {
+ const description: string[] = [];
+ const otherEmojis = client.consts.mappings.otherEmojis;
+
+ const verifiedGuilds = Object.values(client.consts.mappings.guilds);
+ if (verifiedGuilds.includes(guild.id as typeof verifiedGuilds[number])) description.push(otherEmojis.BushVerified);
+ if (guild instanceof Guild) {
+ if (guild.premiumTier !== GuildPremiumTier.None) description.push(otherEmojis[`BoostTier${guild.premiumTier}`]);
+ }
+
+ const features = client.consts.mappings.features;
+ const guildFeatures = guild.features.sort((a, b): number => {
+ const aWeight = features[a]?.weight;
+ const bWeight = features[b]?.weight;
+
+ if (aWeight !== undefined && bWeight !== undefined) return aWeight - bWeight;
+ else if (aWeight === undefined) return 1;
+ else if (bWeight === undefined) return -1;
+ return 0;
+ });
+
+ if (guildFeatures.length) {
+ guildFeatures.forEach((feature) => {
+ if (features[feature]?.emoji) description.push(`${features[feature].emoji}`);
+ else if (features[feature]?.name) description.push(`\`${features[feature].name}\``);
+ else description.push(`\`${feature.charAt(0) + util.akairo.snakeToCamelCase(feature).substring(1)}\``);
+ });
+ }
+
+ if (guild.description) {
+ description.push(`\n\n${guild.description}`);
+ }
+
+ embed.setDescription(`\u200B${/*zero width space*/ description.join(' ')}`);
+ }
+
+ private async generateAboutField(embed: Embed, guild: Guild | GuildPreview) {
+ const guildAbout = [];
+
+ if (guild instanceof Guild) {
const guildRegions = [
...new Set(
guild.channels.cache.filter((c) => c.isVoiceBased()).map((c) => (c as BaseGuildVoiceChannel).rtcRegion ?? 'automatic')
@@ -106,34 +143,6 @@ export default class GuildInfoCommand extends BushCommand {
if (guild.icon) guildAbout.push(`**Icon:** [link](${guild.iconURL({ size: 4096, extension: 'png' })})`);
if (guild.banner) guildAbout.push(`**Banner:** [link](${guild.bannerURL({ size: 4096, extension: 'png' })})`);
if (guild.splash) guildAbout.push(`**Splash:** [link](${guild.splashURL({ size: 4096, extension: 'png' })})`);
-
- const EmojiTierMap = {
- [GuildPremiumTier.Tier3]: 500,
- [GuildPremiumTier.Tier2]: 300,
- [GuildPremiumTier.Tier1]: 100,
- [GuildPremiumTier.None]: 50
- } as const;
- const StickerTierMap = {
- [GuildPremiumTier.Tier3]: 60,
- [GuildPremiumTier.Tier2]: 30,
- [GuildPremiumTier.Tier1]: 15,
- [GuildPremiumTier.None]: 0
- } as const;
-
- guildStats.push(
- `**Channels:** ${guild.channels.cache.size.toLocaleString()} / 500 (${channelTypes.join(', ')})`,
- // subtract 1 for @everyone role
- `**Roles:** ${((guild.roles.cache.size ?? 0) - 1).toLocaleString()} / 250`,
- `**Emojis:** ${guild.emojis.cache.size?.toLocaleString() ?? 0} / ${EmojiTierMap[guild.premiumTier]}`,
- `**Stickers:** ${guild.stickers.cache.size?.toLocaleString() ?? 0} / ${StickerTierMap[guild.premiumTier]}`
- );
-
- guildSecurity.push(
- `**Verification Level:** ${BushGuildVerificationLevel[guild.verificationLevel]}`,
- `**Explicit Content Filter:** ${BushGuildExplicitContentFilter[guild.explicitContentFilter]}`,
- `**Default Message Notifications:** ${BushGuildDefaultMessageNotifications[guild.defaultMessageNotifications]}`,
- `**2FA Required:** ${guild.mfaLevel === GuildMFALevel.Elevated ? 'True' : 'False'}`
- );
} else {
guildAbout.push(
`**Members:** ${guild.approximateMemberCount?.toLocaleString() ?? 0} (${util.emojis.onlineCircle} ${
@@ -146,44 +155,58 @@ export default class GuildInfoCommand extends BushCommand {
);
}
- const features = client.consts.mappings.features;
- const guildFeatures = guild.features.sort((a, b): number => {
- const aWeight = features[a]?.weight;
- const bWeight = features[b]?.weight;
+ embed.addField({ name: '» About', value: guildAbout.join('\n') });
+ }
- if (aWeight !== undefined && bWeight !== undefined) return aWeight - bWeight;
- else if (aWeight == undefined) return 1;
- else if (bWeight == undefined) return -1;
- return 0;
- });
- if (guildFeatures.length) {
- guildFeatures.forEach((feature) => {
- if (features[feature]?.emoji) emojis.push(`${features[feature].emoji}`);
- else if (features[feature]?.name) emojis.push(`\`${features[feature].name}\``);
- else emojis.push(`\`${feature}\``);
- });
- }
+ private generateStatsField(embed: Embed, guild: Guild | GuildPreview) {
+ if (!(guild instanceof Guild)) return;
- if (guild.description) {
- emojis.push(`\n\n${guild.description}`);
- }
+ const guildStats: string[] = [];
- const guildInfoEmbed = new Embed()
- .setTitle(guild.name)
- .setColor(util.colors.default)
- .addField({ name: '» About', value: guildAbout.join('\n') });
- if (guildStats.length) guildInfoEmbed.addField({ name: '» Stats', value: guildStats.join('\n') });
- const guildIcon = guild.iconURL({ size: 2048, extension: 'png' });
- if (guildIcon) {
- guildInfoEmbed.setThumbnail(guildIcon);
- }
- if (!isPreview) {
- guildInfoEmbed.addField({ name: '» Security', value: guildSecurity.join('\n') });
- }
- if (emojis) {
- guildInfoEmbed.setDescription(`\u200B${/*zero width space*/ emojis.join(' ')}`);
- }
- return await message.util.reply({ embeds: [guildInfoEmbed] });
+ const channelTypes = (['Text', 'Voice', 'News', 'Stage', 'Store', 'Category', 'Thread'] as const).map(
+ (type) =>
+ `${client.consts.mappings.otherEmojis[`Channel${type}`]} ${guild.channels.cache
+ .filter((channel) => channel[`is${type}`]())
+ .size.toLocaleString()}`
+ );
+
+ const EmojiTierMap = {
+ [GuildPremiumTier.Tier3]: 500,
+ [GuildPremiumTier.Tier2]: 300,
+ [GuildPremiumTier.Tier1]: 100,
+ [GuildPremiumTier.None]: 50
+ } as const;
+ const StickerTierMap = {
+ [GuildPremiumTier.Tier3]: 60,
+ [GuildPremiumTier.Tier2]: 30,
+ [GuildPremiumTier.Tier1]: 15,
+ [GuildPremiumTier.None]: 0
+ } as const;
+
+ guildStats.push(
+ `**Channels:** ${guild.channels.cache.size.toLocaleString()} / 500 (${channelTypes.join(', ')})`,
+ // subtract 1 for @everyone role
+ `**Roles:** ${((guild.roles.cache.size ?? 0) - 1).toLocaleString()} / 250`,
+ `**Emojis:** ${guild.emojis.cache.size?.toLocaleString() ?? 0} / ${EmojiTierMap[guild.premiumTier]}`,
+ `**Stickers:** ${guild.stickers.cache.size?.toLocaleString() ?? 0} / ${StickerTierMap[guild.premiumTier]}`
+ );
+
+ embed.addField({ name: '» Stats', value: guildStats.join('\n') });
+ }
+
+ private generateSecurityField(embed: Embed, guild: Guild | GuildPreview) {
+ if (!(guild instanceof Guild)) return;
+
+ const guildSecurity: string[] = [];
+
+ guildSecurity.push(
+ `**Verification Level:** ${BushGuildVerificationLevel[guild.verificationLevel]}`,
+ `**Explicit Content Filter:** ${BushGuildExplicitContentFilter[guild.explicitContentFilter]}`,
+ `**Default Message Notifications:** ${BushGuildDefaultMessageNotifications[guild.defaultMessageNotifications]}`,
+ `**2FA Required:** ${guild.mfaLevel === GuildMFALevel.Elevated ? 'True' : 'False'}`
+ );
+
+ embed.addField({ name: '» Security', value: guildSecurity.join('\n') });
}
}