diff options
Diffstat (limited to 'src/commands/info')
-rw-r--r-- | src/commands/info/botInfo.ts | 2 | ||||
-rw-r--r-- | src/commands/info/guildInfo.ts | 40 | ||||
-rw-r--r-- | src/commands/info/icon.ts | 2 | ||||
-rw-r--r-- | src/commands/info/pronouns.ts | 4 | ||||
-rw-r--r-- | src/commands/info/snowflake.ts | 58 | ||||
-rw-r--r-- | src/commands/info/userInfo.ts | 8 |
6 files changed, 56 insertions, 58 deletions
diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index f100317..04a1b14 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -1,7 +1,7 @@ import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { MessageEmbed, version as discordJSVersion } from 'discord.js'; import * as os from 'os'; -import prettyBytes from 'pretty-bytes'; +const {default: prettyBytes} = await import('pretty-bytes') export default class BotInfoCommand extends BushCommand { public constructor() { diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index facbb45..ef1c232 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -1,5 +1,5 @@ import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { Guild, MessageEmbed, type BaseGuildVoiceChannel, type GuildPreview, type Snowflake, type Vanity } from 'discord.js'; +import { Constants, Guild, MessageEmbed, type BaseGuildVoiceChannel, type GuildPreview, type Snowflake, type Vanity } from 'discord.js'; export default class GuildInfoCommand extends BushCommand { public constructor() { @@ -65,15 +65,18 @@ export default class GuildInfoCommand extends BushCommand { if (guild.premiumTier !== 'NONE') emojis.push(otherEmojis[`BOOST_${guild.premiumTier}`]); await guild.fetch(); const channels = guild.channels.cache; - const channelTypes = [ - `${otherEmojis.TEXT} ${channels.filter((channel) => channel.type === 'GUILD_TEXT').size.toLocaleString()}`, - `${otherEmojis.NEWS} ${channels.filter((channel) => channel.type === 'GUILD_NEWS').size.toLocaleString()}`, - `${otherEmojis.VOICE} ${channels.filter((channel) => channel.type === 'GUILD_VOICE').size.toLocaleString()}`, - `${otherEmojis.STAGE} ${channels.filter((channel) => channel.type === 'GUILD_STAGE_VOICE').size.toLocaleString()}`, - `${otherEmojis.STORE} ${channels.filter((channel) => channel.type === 'GUILD_STORE').size.toLocaleString()}`, - `${otherEmojis.CATEGORY} ${channels.filter((channel) => channel.type === 'GUILD_CATEGORY').size.toLocaleString()}`, - `${otherEmojis.THREAD} ${channels.filter((channel) => channel.type.includes('_THREAD')).size.toLocaleString()}` - ]; + + type ChannelType = 'GUILD_TEXT'|'GUILD_NEWS'|'GUILD_VOICE'|'GUILD_STAGE_VOICE'|'GUILD_STORE'|'GUILD_CATEGORY'|'THREAD' + const channelTypes = ([ + 'GUILD_TEXT', + 'GUILD_VOICE', + 'GUILD_STAGE_VOICE', + 'GUILD_STORE', + 'GUILD_CATEGORY', + 'THREAD', + ] as ChannelType[]).map( + (type)=>`${otherEmojis[type]} ${channels.filter((channel) => channel.type.includes(type)).size.toLocaleString()}` + ) const guildRegions = [ ...new Set( @@ -82,7 +85,7 @@ export default class GuildInfoCommand extends BushCommand { ] as RTCRegion[]; guildAbout.push( - `**Owner:** ${guild.members.cache.get(guild.ownerId)?.user.tag}`, + `**Owner:** ${util.discord.escapeMarkdown(guild.members.cache.get(guild.ownerId)?.user.tag ?? '¯\\_(ツ)_/¯')}`, `**Created** ${util.timestamp(guild.createdAt)} (${util.dateDelta(guild.createdAt)})`, `**Members:** ${guild.memberCount.toLocaleString() ?? 0} (${util.emojis.onlineCircle} ${ guild.approximatePresenceCount?.toLocaleString() ?? 0 @@ -91,9 +94,7 @@ export default class GuildInfoCommand extends BushCommand { ); if (guild.premiumSubscriptionCount) guildAbout.push( - `**Boosts:** Level ${guild.premiumTier == 'NONE' ? 0 : guild.premiumTier[5]} with ${ - guild.premiumSubscriptionCount ?? 0 - } boosts` + `**Boosts:** Level ${Constants.PremiumTiers[guild.premiumTier]} with ${guild.premiumSubscriptionCount ?? 0} boosts` ); if (guild.me?.permissions.has('MANAGE_GUILD') && guild.vanityURLCode) { const vanityInfo: Vanity = await guild.fetchVanityData(); @@ -104,16 +105,15 @@ export default class GuildInfoCommand extends BushCommand { if (guild.banner) guildAbout.push(`**Banner:** [link](${guild.bannerURL({ size: 4096, format: 'png' })})`); if (guild.splash) guildAbout.push(`**Splash:** [link](${guild.splashURL({ size: 4096, format: 'png' })})`); + enum EmojiTierMap { TIER_3 = 500, TIER_2 = 300, TIER_1 = 100, NONE = 50 } + enum StickerTierMap { TIER_3 = 60, TIER_2 = 30, TIER_1 = 15, NONE = 0 } + 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} / ${ - guild.premiumTier === 'TIER_3' ? 500 : guild.premiumTier === 'TIER_2' ? 300 : guild.premiumTier === 'TIER_1' ? 100 : 50 - }`, - `**Stickers:** ${guild.stickers.cache.size?.toLocaleString() ?? 0} / ${ - guild.premiumTier === 'TIER_3' ? 60 : guild.premiumTier === 'TIER_2' ? 30 : guild.premiumTier === 'TIER_1' ? 15 : 0 - }` + `**Emojis:** ${guild.emojis.cache.size?.toLocaleString() ?? 0} / ${EmojiTierMap[guild.premiumTier]}`, + `**Stickers:** ${guild.stickers.cache.size?.toLocaleString() ?? 0} / ${StickerTierMap[guild.premiumTier]}` ); guildSecurity.push( diff --git a/src/commands/info/icon.ts b/src/commands/info/icon.ts index fa4968c..2a04a65 100644 --- a/src/commands/info/icon.ts +++ b/src/commands/info/icon.ts @@ -29,7 +29,7 @@ export default class IconCommand extends BushCommand { format: 'png' })! ) - .setTitle(message.guild!.name); + .setTitle(util.discord.escapeMarkdown(message.guild!.name)); await message.util.reply({ embeds: [embed] }); } } diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index fbbc5af..a7df5aa 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -44,7 +44,7 @@ export default class PronounsCommand extends BushCommand { const pronouns = await util.getPronounsOf(user); if (!pronouns) { return await message.util.reply( - `${author ? 'You do' : `${user.tag} does`} not appear to have any pronouns set. Please${ + `${author ? 'You do' : `${util.discord.escapeMarkdown(user.tag)} does`} not appear to have any pronouns set. Please${ author ? '' : ' tell them to' } go to https://pronoundb.org/ and set ${author ? 'your' : 'their'} pronouns.` ); @@ -52,7 +52,7 @@ export default class PronounsCommand extends BushCommand { return await message.util.reply({ embeds: [ new MessageEmbed({ - title: `${author ? 'Your' : `${user.tag}'s`} pronouns:`, + title: `${author ? 'Your' : `${util.discord.escapeMarkdown(user.tag)}'s`} pronouns:`, description: pronouns, footer: { text: 'Data provided by https://pronoundb.org/' diff --git a/src/commands/info/snowflake.ts b/src/commands/info/snowflake.ts index a6de675..3b1a073 100644 --- a/src/commands/info/snowflake.ts +++ b/src/commands/info/snowflake.ts @@ -1,20 +1,18 @@ import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { - MessageEmbed, - SnowflakeUtil, - VoiceChannel, - type CategoryChannel, - type Channel, - type DeconstructedSnowflake, - type DMChannel, - type Emoji, - type Guild, - type NewsChannel, - type Role, - type Snowflake, - type StageChannel, - type TextChannel, - type User + MessageEmbed, + SnowflakeUtil, + VoiceChannel, + type CategoryChannel, + type Channel, + type DeconstructedSnowflake, + type DMChannel, type Guild, + type NewsChannel, + type Role, + type Snowflake, + type StageChannel, + type TextChannel, + type User } from 'discord.js'; export default class SnowflakeCommand extends BushCommand { @@ -61,8 +59,8 @@ export default class SnowflakeCommand extends BushCommand { const channelInfo = [`**Type:** ${channel.type}`]; if (['dm', 'group'].includes(channel.type)) { const _channel = channel as DMChannel; - channelInfo.push(`**Recipient:** ${_channel.recipient.tag} (${_channel.recipient.id})`); - snowflakeEmbed.setTitle(`:snowflake: DM with ${(channel as DMChannel).recipient.tag} \`[Channel]\``); + channelInfo.push(`**Recipient:** ${util.discord.escapeMarkdown(_channel.recipient.tag)} (${_channel.recipient.id})`); + snowflakeEmbed.setTitle(`:snowflake: DM with ${util.discord.escapeMarkdown((channel as DMChannel).recipient.tag)} \`[Channel]\``); } else if ( [ 'GUILD_CATEGORY', @@ -78,10 +76,10 @@ export default class SnowflakeCommand extends BushCommand { ) { const _channel = channel as TextChannel | VoiceChannel | NewsChannel | StageChannel | CategoryChannel | StageChannel; channelInfo.push( - `**Channel Name:** <#${_channel.id}> (${_channel.name})`, - `**Channel's Server:** ${_channel.guild.name} (${_channel.guild.id})` + `**Channel Name:** <#${_channel.id}> (${util.discord.escapeMarkdown(_channel.name)})`, + `**Channel's Server:** ${util.discord.escapeMarkdown(_channel.guild.name)} (${_channel.guild.id})` ); - snowflakeEmbed.setTitle(`:snowflake: ${_channel.name} \`[Channel]\``); + snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(_channel.name)} \`[Channel]\``); } snowflakeEmbed.addField('» Channel Info', channelInfo.join('\n')); } @@ -90,39 +88,39 @@ export default class SnowflakeCommand extends BushCommand { if (client.guilds.cache.has(snowflake)) { const guild: Guild = client.guilds.cache.get(snowflake)!; const guildInfo = [ - `**Name:** ${guild.name}`, - `**Owner:** ${client.users.cache.get(guild.ownerId)?.tag ?? '¯\\_(ツ)_/¯'} (${guild.ownerId})`, + `**Name:** ${util.discord.escapeMarkdown(guild.name)}`, + `**Owner:** ${util.discord.escapeMarkdown(client.users.cache.get(guild.ownerId)?.tag ?? '¯\\_(ツ)_/¯')} (${guild.ownerId})`, `**Members:** ${guild.memberCount?.toLocaleString()}` ]; if (guild.icon) snowflakeEmbed.setThumbnail(guild.iconURL({ size: 2048, dynamic: true })!); snowflakeEmbed.addField('» Server Info', guildInfo.join('\n')); - snowflakeEmbed.setTitle(`:snowflake: ${guild.name} \`[Server]\``); + snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(guild.name)} \`[Server]\``); } // User const fetchedUser = await client.users.fetch(`${snowflake}`).catch(() => undefined); if (client.users.cache.has(snowflake) || fetchedUser) { const user: User = (client.users.cache.get(snowflake) ?? fetchedUser)!; - const userInfo = [`**Name:** <@${user.id}> (${user.tag})`]; + const userInfo = [`**Name:** <@${user.id}> (${util.discord.escapeMarkdown(user.tag)})`]; if (user.avatar) snowflakeEmbed.setThumbnail(user.avatarURL({ size: 2048, dynamic: true })!); snowflakeEmbed.addField('» User Info', userInfo.join('\n')); - snowflakeEmbed.setTitle(`:snowflake: ${user.tag} \`[User]\``); + snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(user.tag)} \`[User]\``); } // Emoji if (client.emojis.cache.has(snowflake)) { - const emoji: Emoji = client.emojis.cache.get(snowflake)!; - const emojiInfo = [`**Name:** ${emoji.name}`, `**Animated:** ${emoji.animated}`]; + const emoji = client.emojis.cache.get(snowflake)!; + const emojiInfo = [`**Name:** ${util.discord.escapeMarkdown(emoji.name ?? '¯\\_(ツ)_/¯')}`, `**Animated:** ${emoji.animated}`]; if (emoji.url) snowflakeEmbed.setThumbnail(emoji.url); snowflakeEmbed.addField('» Emoji Info', emojiInfo.join('\n')); - snowflakeEmbed.setTitle(`:snowflake: ${emoji.name} \`[Emoji]\``); + snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(emoji.name ?? '¯\\_(ツ)_/¯')} \`[Emoji]\``); } // Role if (message.guild && message.guild.roles.cache.has(snowflake)) { const role: Role = message.guild.roles.cache.get(snowflake)!; const roleInfo = [ - `**Name:** <@&${role.id}> (${role.name})`, + `**Name:** <@&${role.id}> (${util.discord.escapeMarkdown(role.name)})`, `**Members:** ${role.members.size}`, `**Hoisted:** ${role.hoist}`, `**Managed:** ${role.managed}`, @@ -131,7 +129,7 @@ export default class SnowflakeCommand extends BushCommand { ]; if (role.color) snowflakeEmbed.setColor(role.color); snowflakeEmbed.addField('» Role Info', roleInfo.join('\n')); - snowflakeEmbed.setTitle(`:snowflake: ${role.name} \`[Role]\``); + snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(role.name)} \`[Role]\``); } // SnowflakeInfo diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 2b87d0b..49c23c9 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -52,9 +52,9 @@ export default class UserInfoCommand extends BushCommand { await user.fetch(true); // gets banner info and accent color const userEmbed: MessageEmbed = new MessageEmbed() - .setTitle(user.tag) + .setTitle(util.discord.escapeMarkdown(user.tag)) .setThumbnail( - user.avatarURL({ size: 2048, format: 'png', dynamic: true }) ?? 'https://cdn.discordapp.com/embed/avatars/0.png' + user.displayAvatarURL({ size: 2048, format: 'png', dynamic: true }) ) .setTimestamp(); @@ -112,7 +112,7 @@ export default class UserInfoCommand extends BushCommand { serverUserInfo.push(`**General Deletions:** 1⅓`); if (['384620942577369088', '496409778822709251'].includes(user.id) && message.guild?.id == client.consts.mappings.guilds.bush) serverUserInfo.push(`**General Deletions:** ⅓`); - if (member?.nickname) serverUserInfo.push(`**Nickname:** ${member?.nickname}`); + if (member?.nickname) serverUserInfo.push(`**Nickname:** ${util.discord.escapeMarkdown(member?.nickname)}`); if (serverUserInfo.length) userEmbed.addField('» Server Info', serverUserInfo.join('\n')).setColor(member?.displayColor ?? util.colors.default); @@ -137,7 +137,7 @@ export default class UserInfoCommand extends BushCommand { presenceInfo.push(`**${devices.length - 1 ? 'Devices' : 'Device'}:** ${util.oxford(devices, 'and', '')}`); if (activitiesNames.length) presenceInfo.push(`**Activit${activitiesNames.length - 1 ? 'ies' : 'y'}:** ${util.oxford(activitiesNames, 'and', '')}`); - if (customStatus && customStatus.length) presenceInfo.push(`**Custom Status:** ${customStatus}`); + if (customStatus && customStatus.length) presenceInfo.push(`**Custom Status:** ${util.discord.escapeMarkdown(customStatus)}`); userEmbed.addField('» Presence', presenceInfo.join('\n')); enum statusEmojis { |