diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/config/config.ts | 2 | ||||
-rw-r--r-- | src/commands/info/guildInfo.ts | 4 | ||||
-rw-r--r-- | src/commands/info/userInfo.ts | 91 | ||||
-rw-r--r-- | src/commands/moderation/modlog.ts | 12 | ||||
-rw-r--r-- | src/commands/utilities/suicide.ts | 2 | ||||
-rw-r--r-- | src/lib/common/AutoMod.ts | 4 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 24 | ||||
-rw-r--r-- | src/lib/utils/BushConstants.ts | 16 |
8 files changed, 112 insertions, 43 deletions
diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index 8f2472e..580f8d2 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -357,7 +357,7 @@ export default class ConfigCommand extends BushCommand { new ButtonComponent().setStyle(ButtonStyle.Primary).setCustomId('command_settingsBack').setLabel('Back') ); settingsEmbed.setDescription( - `${Formatters.italic(guildSettingsObj[setting].description)}\n\n**Type**: ${guildSettingsObj[setting].type}` + `${Formatters.italic(guildSettingsObj[setting].description)}\n\n**Type:** ${guildSettingsObj[setting].type}` ); settingsEmbed.setFooter({ diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index 0aabb70..55fb0b2 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -129,10 +129,10 @@ export default class GuildInfoCommand extends BushCommand { ); guildSecurity.push( - `**Verification Level**: ${BushGuildVerificationLevel[guild.verificationLevel]}`, + `**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'}` + `**2FA Required:** ${guild.mfaLevel === GuildMFALevel.Elevated ? 'True' : 'False'}` ); } else { guildAbout.push( diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 50cb1a8..74f8185 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -7,7 +7,15 @@ import { type BushSlashMessage, type BushUser } from '#lib'; -import { ActivityType, ApplicationCommandOptionType, Embed, PermissionFlagsBits, UserFlags } from 'discord.js'; +import { APIApplication, TeamMemberMembershipState } from 'discord-api-types'; +import { + ActivityType, + ApplicationCommandOptionType, + ApplicationFlagsBitField, + Embed, + PermissionFlagsBits, + UserFlags +} from 'discord.js'; export default class UserInfoCommand extends BushCommand { public constructor() { @@ -43,7 +51,7 @@ export default class UserInfoCommand extends BushCommand { ? args.user : await client.users.fetch(`${args.user}`).catch(() => undefined); if (user === undefined) return message.util.reply(`${util.emojis.error} Invalid user.`); - const member = message.guild ? message.guild.members.cache.get(user.id) : undefined; + const member = message.guild ? await message.guild.members.fetch(user.id).catch(() => undefined) : undefined; await user.fetch(true); // gets banner info and accent color const userEmbed = await UserInfoCommand.makeUserInfoEmbed(user, member, message.guild); @@ -100,12 +108,17 @@ export default class UserInfoCommand extends BushCommand { this.generatePermissionsField(userEmbed, member); - if (emojis) userEmbed.setDescription(`\u200B${emojis.filter((e) => e).join(' ')}`); // zero width space + await this.generateBotField(userEmbed, user); + + if (emojis) + userEmbed.setDescription( + `\u200B${emojis.filter((e) => e).join(' ')}${userEmbed.description?.length ? `\n\n${userEmbed.description}` : ''}` + ); // zero width space return userEmbed; } private static async generateGeneralInfoField(embed: Embed, user: BushUser) { - const createdAt = util.timestamp(user.createdAt), + const createdAt = util.timestamp(user.createdAt, 'd'), createdAtDelta = util.dateDelta(user.createdAt); // General Info @@ -115,7 +128,7 @@ export default class UserInfoCommand extends BushCommand { const pronouns = await Promise.race([util.getPronounsOf(user), util.sleep(2)]); // cut off request after 2 seconds - if (pronouns && typeof pronouns === 'string') generalInfo.push(`**Pronouns:** ${pronouns}`); + if (pronouns && typeof pronouns === 'string' && pronouns !== 'Unspecified') generalInfo.push(`**Pronouns:** ${pronouns}`); embed.addField({ name: '» General Info', value: generalInfo.join('\n') }); } @@ -123,9 +136,9 @@ export default class UserInfoCommand extends BushCommand { private static generateServerInfoField(embed: Embed, member?: BushGuildMember | undefined) { if (!member) return; - const joinedAt = util.timestamp(member?.joinedAt), + const joinedAt = util.timestamp(member?.joinedAt, 'd'), joinedAtDelta = member.joinedAt ? util.dateDelta(member.joinedAt, 2) : undefined, - premiumSince = util.timestamp(member?.premiumSince), + premiumSince = util.timestamp(member?.premiumSince, 'd'), premiumSinceDelta = member.premiumSince ? util.dateDelta(member.premiumSince, 2) : undefined; // Server User Info @@ -188,16 +201,14 @@ export default class UserInfoCommand extends BushCommand { } private static generateRolesField(embed: Embed, member?: BushGuildMember | undefined) { - if (!member || !(member.roles.cache.size < 1)) return; + if (!member || member.roles.cache.size < 1) return; // roles - if (member?.roles.cache.size && member?.roles.cache.size - 1) { - const roles = member?.roles.cache - .filter((role) => role.name !== '@everyone') - .sort((role1, role2) => role2.position - role1.position) - .map((role) => `${role}`); - embed.addField({ name: `» Role${roles.length - 1 ? 's' : ''} [${roles.length}]`, value: roles.join(', ') }); - } + const roles = member.roles.cache + .filter((role) => role.name !== '@everyone') + .sort((role1, role2) => role2.position - role1.position) + .map((role) => `${role}`); + embed.addField({ name: `» Role${roles.length - 1 ? 's' : ''} [${roles.length}]`, value: roles.join(', ') }); } private static generatePermissionsField(embed: Embed, member: BushGuildMember | undefined) { @@ -217,4 +228,54 @@ export default class UserInfoCommand extends BushCommand { if (perms.length) embed.addField({ name: '» Important Perms', value: perms.join(' ') }); } + + private static async generateBotField(embed: Embed, user: BushUser) { + if (!user.bot) return; + + const applicationInfo = (await client.rest.get(`/applications/${user.id}/rpc`).catch(() => null)) as APIApplication | null; + if (!applicationInfo) return; + + const flags = new ApplicationFlagsBitField(applicationInfo.flags); + + const botInfo = [ + `**Publicity:** ${applicationInfo.bot_public ? 'Public' : 'Private'}`, + `**Requires Code Grant:** ${applicationInfo.bot_require_code_grant ? util.emojis.check : util.emojis.cross}`, + `**Server Members Intent:** ${ + flags.has('GatewayGuildMembers') + ? util.emojis.check + : flags.has('GatewayGuildMembersLimited') + ? util.emojis.warn + : util.emojis.cross + }`, + `**Presence Intent:** ${ + flags.has('GatewayPresence') + ? util.emojis.check + : flags.has('GatewayPresenceLimited') + ? util.emojis.warn + : util.emojis.cross + }`, + `**Message Content Intent:** ${ + flags.has('GatewayMessageContent') + ? util.emojis.check + : flags.has('GatewayMessageContentLimited') + ? util.emojis.warn + : util.emojis.cross + }` + ]; + + if (applicationInfo.owner || applicationInfo.team) { + const teamMembers = applicationInfo.owner + ? [applicationInfo.owner] + : applicationInfo + .team!.members.filter((tm) => tm.membership_state === TeamMemberMembershipState.Accepted) + .map((tm) => tm.user); + botInfo.push( + `**Developer${teamMembers.length > 1 ? 's' : ''}:** ${teamMembers + .map((m) => `${m.username}#${m.discriminator}`) + .join(', ')}` + ); + } + + if (botInfo.length) embed.addField({ name: '» Bot Info', value: botInfo.join('\n') }); + } } diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 6b8ae2d..443ffa3 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -81,12 +81,12 @@ export default class ModlogCommand extends BushCommand { public static generateModlogInfo(log: ModLog, showUser: boolean): string { const trim = (str: string): string => (str.endsWith('\n') ? str.substring(0, str.length - 1).trim() : str.trim()); - const modLog = [`**Case ID**: ${util.discord.escapeMarkdown(log.id)}`, `**Type**: ${log.type.toLowerCase()}`]; - if (showUser) modLog.push(`**User**: <@!${log.user}>`); - modLog.push(`**Moderator**: <@!${log.moderator}>`); - if (log.duration) modLog.push(`**Duration**: ${util.humanizeDuration(log.duration)}`); - modLog.push(`**Reason**: ${trim(log.reason ?? 'No Reason Specified.')}`); - modLog.push(`**Date**: ${util.timestamp(log.createdAt)}`); + const modLog = [`**Case ID:** ${util.discord.escapeMarkdown(log.id)}`, `**Type:** ${log.type.toLowerCase()}`]; + if (showUser) modLog.push(`**User:** <@!${log.user}>`); + modLog.push(`**Moderator:** <@!${log.moderator}>`); + if (log.duration) modLog.push(`**Duration:** ${util.humanizeDuration(log.duration)}`); + modLog.push(`**Reason:** ${trim(log.reason ?? 'No Reason Specified.')}`); + modLog.push(`**Date:** ${util.timestamp(log.createdAt)}`); if (log.evidence) modLog.push(`**Evidence:** ${trim(log.evidence)}`); return modLog.join(`\n`); } diff --git a/src/commands/utilities/suicide.ts b/src/commands/utilities/suicide.ts index 293008c..693896d 100644 --- a/src/commands/utilities/suicide.ts +++ b/src/commands/utilities/suicide.ts @@ -33,7 +33,7 @@ export default class SuicideCommand extends BushCommand { '**Text: HOME** to 741741', 'https://suicidepreventionlifeline.org/chat/', '', - '**Outside the U.S**: Find a supportive resource on [this Wikipedia list of worldwide crisis hotlines](https://en.wikipedia.org/wiki/List_of_suicide_crisis_lines)' + '**Outside the U.S:** Find a supportive resource on [this Wikipedia list of worldwide crisis hotlines](https://en.wikipedia.org/wiki/List_of_suicide_crisis_lines)' ].join('\n') }) .addField({ diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts index 24feae0..2633e1a 100644 --- a/src/lib/common/AutoMod.ts +++ b/src/lib/common/AutoMod.ts @@ -145,7 +145,7 @@ export class AutoMod { new Embed() .setTitle(`[Severity ${Severity.TEMP_MUTE}] Mention Scam Deleted`) .setDescription( - `**User:** ${this.message.author} (${this.message.author.tag})\n**Sent From**: <#${this.message.channel.id}> [Jump to context](${this.message.url})` + `**User:** ${this.message.author} (${this.message.author.tag})\n**Sent From:** <#${this.message.channel.id}> [Jump to context](${this.message.url})` ) .addField({ name: 'Message Content', value: `${await util.codeblock(this.message.content, 1024)}` }) .setColor(color) @@ -263,7 +263,7 @@ export class AutoMod { new Embed() .setTitle(`[Severity ${highestOffence.severity}] Automod Action Performed`) .setDescription( - `**User:** ${this.message.author} (${this.message.author.tag})\n**Sent From**: <#${ + `**User:** ${this.message.author} (${this.message.author.tag})\n**Sent From:** <#${ this.message.channel.id }> [Jump to context](${this.message.url})\n**Blacklisted Words:** ${offences.map((o) => `\`${o.match}\``).join(', ')}` ) diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 09dd84d..7026539 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -195,6 +195,9 @@ export class BushClientUtil extends ClientUtil { return client.consts.emojis; } + /** + * Just the ids of Commonly Used Emojis + */ get emojisRaw() { return client.consts.emojisRaw; } @@ -251,7 +254,7 @@ export class BushClientUtil extends ClientUtil { * @returns The inspected object. */ public inspect(object: any, options?: BushInspectOptions): string { - const optionsWithDefaults = this.getDefaultInspectOptions(options); + const optionsWithDefaults = this.#getDefaultInspectOptions(options); return inspect(object, optionsWithDefaults); } @@ -260,7 +263,7 @@ export class BushClientUtil extends ClientUtil { * @param options The options to create defaults with. * @returns The default options combined with the specified options. */ - private getDefaultInspectOptions(options?: BushInspectOptions): BushInspectOptions { + #getDefaultInspectOptions(options?: BushInspectOptions): BushInspectOptions { const { showHidden = false, depth = 2, @@ -582,13 +585,13 @@ export class BushClientUtil extends ClientUtil { * * @see * **Styles:** - * - **t**: Short Time - * - **T**: Long Time - * - **d**: Short Date - * - **D**: Long Date - * - **f**: Short Date/Time - * - **F**: Long Date/Time - * - **R**: Relative Time + * - **t**: Short Time ex. `16:20` + * - **T**: Long Time ex. `16:20:30 ` + * - **d**: Short Date ex. `20/04/2021` + * - **D**: Long Date ex. `20 April 2021` + * - **f**: Short Date/Time ex. `20 April 2021 16:20` + * - **F**: Long Date/Time ex. `Tuesday, 20 April 2021 16:20` + * - **R**: Relative Time ex. `2 months ago` */ public timestamp<D extends Date | undefined | null>( date: D, @@ -696,8 +699,7 @@ export class BushClientUtil extends ClientUtil { * @returns A string with each method on a new line. */ public getMethods(obj: Record<string, any>): string { - // modified from https://stackoverflow.com/questions/31054910/get-functions-methods-of-a-class - // answer by Bruno Grieder + // modified from https://stackoverflow.com/questions/31054910/get-functions-methods-of-a-class/31055217#31055217 let props: string[] = []; let obj_: Record<string, any> = new Object(obj); diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts index 4012054..5b2b2e6 100644 --- a/src/lib/utils/BushConstants.ts +++ b/src/lib/utils/BushConstants.ts @@ -148,13 +148,17 @@ export class BushConstants { public static regex = BushClientUtil.deepFreeze({ snowflake: /^\d{15,21}$/im, + discordEmoji: /<a?:(?<name>[a-zA-Z0-9_]+):(?<id>\d{15,21})>/im, //stolen from geek messageLink: - /(?:ptb\.|canary\.|staging\.|lc\.)?(?:discord(?:app)?|inv)\.(?:com|wtf)?\/channels\/(?<guild_id>\d{15,21}|@me)\/(?<channel_id>\d{15,21})\/(?<message_id>\d{15,21})/im + /(?:ptb\.|canary\.|staging\.|lc\.)?(?:discord(?:app)?)\.(?:com)?\/channels\/(?<guild_id>\d{15,21}|@me)\/(?<channel_id>\d{15,21})\/(?<message_id>\d{15,21})/im } as const); + /** + * Maps the response from pronoundb.org to a readable format + */ public static pronounMapping = Object.freeze({ unspecified: 'Unspecified', hh: 'He/Him', @@ -179,7 +183,9 @@ export class BushConstants { avoid: 'Avoid pronouns, use my name' } as const); - /** A bunch of mappings */ + /** + * A bunch of mappings + */ public static mappings = BushClientUtil.deepFreeze({ guilds: { bush: '516977525906341928', @@ -320,12 +326,12 @@ export class BushConstants { HypeSquadOnlineHouse2: '<:hypeSquadBrilliance:848742840649646101>', HypeSquadOnlineHouse3: '<:hypeSquadBalance:848742877537370133>', PremiumEarlySupporter: '<:earlySupporter:848741030102171648>', - TeamPseudoUser: 'TEAM_PSEUDO_USER', + TeamPseudoUser: 'TeamPseudoUser', BugHunterLevel2: '<:bugHunterGold:848743283080822794>', - VerifiedBot: 'VERIFIED_BOT', + VerifiedBot: '<:verifiedbot_rebrand1:938928232667947028><:verifiedbot_rebrand2:938928355707879475>', VerifiedDeveloper: '<:earlyVerifiedBotDeveloper:848741079875846174>', CertifiedModerator: '<:discordCertifiedModerator:877224285901582366>', - BotHTTPInteractions: 'BOT_HTTP_INTERACTIONS' + BotHTTPInteractions: 'BotHTTPInteractions' }, status: { |