diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-14 12:47:57 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-14 12:47:57 -0400 |
commit | 661e4c9935aeb8760dafc7ced4bbec6cc356a033 (patch) | |
tree | bb4c12bdef067d203f100e13e05ccb705b299834 /src/commands/info | |
parent | eaf592b72eb5b1d66aa2bde5151a8947570a506c (diff) | |
download | tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.tar.gz tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.tar.bz2 tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.zip |
remove the war crimes that I previously committed
- Remove custom typings and replace with declaration merging
- Fix the typings for args
- Replace all discord-api-types imports with discord.js imports
- Fix discord.js breaking changes
Diffstat (limited to 'src/commands/info')
-rw-r--r-- | src/commands/info/avatar.ts | 7 | ||||
-rw-r--r-- | src/commands/info/botInfo.ts | 4 | ||||
-rw-r--r-- | src/commands/info/color.ts | 33 | ||||
-rw-r--r-- | src/commands/info/guildInfo.ts | 28 | ||||
-rw-r--r-- | src/commands/info/help.ts | 14 | ||||
-rw-r--r-- | src/commands/info/icon.ts | 4 | ||||
-rw-r--r-- | src/commands/info/links.ts | 4 | ||||
-rw-r--r-- | src/commands/info/ping.ts | 12 | ||||
-rw-r--r-- | src/commands/info/pronouns.ts | 4 | ||||
-rw-r--r-- | src/commands/info/snowflake.ts | 16 | ||||
-rw-r--r-- | src/commands/info/userInfo.ts | 41 |
11 files changed, 74 insertions, 93 deletions
diff --git a/src/commands/info/avatar.ts b/src/commands/info/avatar.ts index 870908d..544c30a 100644 --- a/src/commands/info/avatar.ts +++ b/src/commands/info/avatar.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType, EmbedBuilder, GuildMember, PermissionFlagsBits } from 'discord.js'; export default class AvatarCommand extends BushCommand { @@ -27,11 +27,12 @@ export default class AvatarCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { user: ArgType<'member'> | ArgType<'globalUser'> }) { + public override async exec(message: CommandMessage | SlashMessage, args: { user: OptArgType<'member' | 'globalUser'> }) { const params: { size: 2048; extension: 'png'; dynamic: true } = { size: 2048, extension: 'png', dynamic: true }; const defaultAvatar = `https://cdn.discordapp.com/embed/avatars/${Math.ceil(Math.random() * 6) - 1}.png`; - const member = (args.user ?? message.member) instanceof GuildMember ? args.user ?? message.member : undefined; + const member = + (args.user ?? message.member) instanceof GuildMember ? args.user ?? (message.member as GuildMember | null) : null; const user = args.user instanceof GuildMember ? args.user.user : args.user ?? message.author; const guildAvatar = member?.avatarURL(params); diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index e67ae5a..4a8a36a 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { EmbedBuilder, PermissionFlagsBits, version as discordJSVersion } from 'discord.js'; import * as os from 'os'; @@ -20,7 +20,7 @@ export default class BotInfoCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { enum Platform { aix = 'AIX', android = 'Android', diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts index a74c3f3..f60e28a 100644 --- a/src/commands/info/color.ts +++ b/src/commands/info/color.ts @@ -1,25 +1,9 @@ -import { - AllowedMentions, - BushCommand, - type ArgType, - type BushArgumentTypeCaster, - type BushGuildMember, - type BushMessage, - type BushRole, - type BushSlashMessage -} from '#lib'; +import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; -import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits, Role } from 'discord.js'; +import { ApplicationCommandOptionType, EmbedBuilder, GuildMember, PermissionFlagsBits, Role } from 'discord.js'; import tinycolor from 'tinycolor2'; - assert(tinycolor); -const isValidTinyColor: BushArgumentTypeCaster<string | null> = (_message, phase) => { - // if the phase is a number it converts it to hex incase it could be representing a color in decimal - const newPhase = isNaN(phase as any) ? phase : `#${Number(phase).toString(16)}`; - return tinycolor(newPhase).isValid() ? newPhase : null; -}; - export default class ColorCommand extends BushCommand { public constructor() { super('color', { @@ -32,7 +16,7 @@ export default class ColorCommand extends BushCommand { { id: 'color', description: 'The color string, role, or member to find the color of.', - type: util.arg.union(isValidTinyColor as any, 'role', 'member'), + type: util.arg.union('tinyColor', 'role', 'member'), readableType: 'color|role|member', match: 'restContent', prompt: 'What color code, role, or user would you like to find the color of?', @@ -50,15 +34,12 @@ export default class ColorCommand extends BushCommand { return color.substring(4, color.length - 5); } - public override async exec( - message: BushMessage | BushSlashMessage, - args: { color: string | ArgType<'role'> | ArgType<'member'> } - ) { + public override async exec(message: CommandMessage | SlashMessage, args: { color: ArgType<'tinyColor' | 'role' | 'member'> }) { const _color = message.util.isSlashMessage(message) - ? ((await util.arg.cast(util.arg.union(isValidTinyColor, 'role', 'member'), message, args.color as string)) as + ? ((await util.arg.cast(util.arg.union('tinyColor', 'role', 'member'), message, args.color as string)) as | string - | BushRole - | BushGuildMember) + | Role + | GuildMember) : args.color; const color = diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index 4872497..572cf06 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -1,10 +1,12 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage, type OptArgType } from '#lib'; +import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import assert from 'assert'; -import { GuildDefaultMessageNotifications, GuildExplicitContentFilter } from 'discord-api-types/v10'; import { ApplicationCommandOptionType, + ChannelType, EmbedBuilder, Guild, + GuildDefaultMessageNotifications, + GuildExplicitContentFilter, GuildMFALevel, GuildPremiumTier, GuildVerificationLevel, @@ -41,17 +43,14 @@ export default class GuildInfoCommand extends BushCommand { }); } - public override async exec( - message: BushMessage | BushSlashMessage, - args: { guild: OptArgType<'guild'> | OptArgType<'snowflake'> } - ) { + public override async exec(message: CommandMessage | SlashMessage, args: { guild: OptArgType<'guild' | 'snowflake'> }) { if (!args.guild && !message.inGuild()) { return await message.util.reply( `${util.emojis.error} You must either provide an server to provide info about or run this command in a server.` ); } - let guild: ArgType<'guild'> | ArgType<'snowflake'> | GuildPreview = args.guild ?? message.guild!; + let guild: ArgType<'guild' | '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; @@ -163,10 +162,19 @@ export default class GuildInfoCommand extends BushCommand { const guildStats: string[] = []; - const channelTypes = (['Text', 'Voice', 'News', 'Stage', 'Category', 'Thread'] as const).map( + const channelTypes = ( + [ + ['Text', [ChannelType.GuildText]], + ['Voice', [ChannelType.GuildVoice]], + ['News', [ChannelType.GuildNews]], + ['Stage', [ChannelType.GuildStageVoice]], + ['Category', [ChannelType.GuildCategory]], + ['Thread', [ChannelType.GuildNewsThread, ChannelType.GuildPrivateThread, ChannelType.GuildPublicThread]] + ] as const + ).map( (type) => - `${client.consts.mappings.otherEmojis[`Channel${type}`]} ${guild.channels.cache - .filter((channel) => channel[`is${type}`]()) + `${client.consts.mappings.otherEmojis[`Channel${type[0]}`]} ${guild.channels.cache + .filter((channel) => type[1].some((type) => channel.type === type)) .size.toLocaleString()}` ); diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index ea1e965..af44980 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,10 +1,10 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; -import { ButtonBuilder } from '@discordjs/builders'; +import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import assert from 'assert'; import { ActionRowBuilder, ApplicationCommandOptionType, AutocompleteInteraction, + ButtonBuilder, ButtonStyle, EmbedBuilder, PermissionFlagsBits @@ -53,7 +53,7 @@ export default class HelpCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: HelpArgs) { + public override async exec(message: CommandMessage | SlashMessage, args: HelpArgs) { const row = this.addLinks(message); const command = args.command ? typeof args.command === 'string' @@ -70,7 +70,7 @@ export default class HelpCommand extends BushCommand { } } - private helpAll(message: BushMessage | BushSlashMessage, args: HelpArgs, row: ActionRowBuilder<ButtonBuilder>) { + private helpAll(message: CommandMessage | SlashMessage, args: HelpArgs, row: ActionRowBuilder<ButtonBuilder>) { const prefix = util.prefix(message); const embed = new EmbedBuilder() .setColor(util.colors.default) @@ -99,7 +99,7 @@ export default class HelpCommand extends BushCommand { return message.util.reply({ embeds: [embed], components: row.components.length ? [row] : undefined }); } - private helpIndividual(message: BushMessage | BushSlashMessage, row: ActionRowBuilder<ButtonBuilder>, command: BushCommand) { + private helpIndividual(message: CommandMessage | SlashMessage, row: ActionRowBuilder<ButtonBuilder>, command: BushCommand) { const embed = new EmbedBuilder().setColor(util.colors.default).setTitle(`${command.id} Command`); let description = `${command.description ?? '*This command does not have a description.*'}`; @@ -207,7 +207,7 @@ export default class HelpCommand extends BushCommand { } } - private addLinks(message: BushMessage | BushSlashMessage) { + private addLinks(message: CommandMessage | SlashMessage) { const row = new ActionRowBuilder<ButtonBuilder>(); if (!client.config.isDevelopment && !client.guilds.cache.some((guild) => guild.ownerId === message.author.id)) { @@ -246,4 +246,4 @@ export default class HelpCommand extends BushCommand { } } -type HelpArgs = { command: ArgType<'commandAlias'> | string; showHidden?: boolean }; +type HelpArgs = { command: OptArgType<'commandAlias'> | string; showHidden: ArgType<'flag'> }; diff --git a/src/commands/info/icon.ts b/src/commands/info/icon.ts index db390a5..9c9556b 100644 --- a/src/commands/info/icon.ts +++ b/src/commands/info/icon.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { EmbedBuilder, PermissionFlagsBits } from 'discord.js'; @@ -17,7 +17,7 @@ export default class IconCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { assert(message.inGuild()); const embed = new EmbedBuilder() diff --git a/src/commands/info/links.ts b/src/commands/info/links.ts index 91b62ca..0d5bd15 100644 --- a/src/commands/info/links.ts +++ b/src/commands/info/links.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js'; import packageDotJSON from '../../../package.json' assert { type: 'json' }; @@ -19,7 +19,7 @@ export default class LinksCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { const buttonRow = new ActionRowBuilder<ButtonBuilder>(); if (!client.config.isDevelopment || message.author.isOwner()) { buttonRow.addComponents([new ButtonBuilder({ style: ButtonStyle.Link, label: 'Invite Me', url: util.invite })]); diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index af0fa98..ad7fdcc 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -1,5 +1,5 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { EmbedBuilder, PermissionFlagsBits } from 'discord.js'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { EmbedBuilder, PermissionFlagsBits, type Message } from 'discord.js'; export default class PingCommand extends BushCommand { public constructor() { @@ -15,21 +15,21 @@ export default class PingCommand extends BushCommand { }); } - public override async exec(message: BushMessage) { + public override async exec(message: CommandMessage) { const timestamp1 = message.editedTimestamp ? message.editedTimestamp : message.createdTimestamp; const msg = await message.util.reply('Pong!'); const timestamp2 = msg.editedTimestamp ? msg.editedTimestamp : msg.createdTimestamp; void this.command(message, timestamp2 - timestamp1); } - public override async execSlash(message: BushSlashMessage) { + public override async execSlash(message: SlashMessage) { const timestamp1 = message.createdTimestamp; - const msg = (await message.util.reply({ content: 'Pong!', fetchReply: true })) as BushMessage; + const msg = (await message.util.reply({ content: 'Pong!', fetchReply: true })) as Message; const timestamp2 = msg.editedTimestamp ? msg.editedTimestamp : msg.createdTimestamp; void this.command(message, timestamp2 - timestamp1); } - private command(message: BushMessage | BushSlashMessage, msgLatency: number) { + private command(message: CommandMessage | SlashMessage, msgLatency: number) { const botLatency = util.format.codeBlock(`${Math.round(msgLatency)}ms`); const apiLatency = util.format.codeBlock(`${Math.round(message.client.ws.ping)}ms`); const embed = new EmbedBuilder() diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index b45f9b3..f916687 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; export default class PronounsCommand extends BushCommand { @@ -26,7 +26,7 @@ export default class PronounsCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { user?: ArgType<'globalUser'> }) { + public override async exec(message: CommandMessage | SlashMessage, args: { user: OptArgType<'globalUser'> }) { const user = args.user ?? message.author; const author = user.id === message.author.id; diff --git a/src/commands/info/snowflake.ts b/src/commands/info/snowflake.ts index 07544c9..e74756f 100644 --- a/src/commands/info/snowflake.ts +++ b/src/commands/info/snowflake.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import { stripIndent } from '#tags'; import { ApplicationCommandOptionType, @@ -37,7 +37,7 @@ export default class SnowflakeCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { snowflake: ArgType<'snowflake'> }) { + public override async exec(message: CommandMessage | SlashMessage, args: { snowflake: ArgType<'snowflake'> }) { const snowflake = `${args.snowflake}` as Snowflake; const snowflakeEmbed = new EmbedBuilder().setTitle('Unknown :snowflake:').setColor(util.colors.default); @@ -45,7 +45,7 @@ export default class SnowflakeCommand extends BushCommand { if (client.channels.cache.has(snowflake)) { const channel = client.channels.resolve(snowflake)!; const channelInfo = [`**Type:** ${BushChannelType[channel.type] ?? ChannelType[channel.type]}`]; - if (channel.isDM()) { + if (channel.type === ChannelType.DM) { channelInfo.push( `**Recipient:** ${util.discord.escapeMarkdown(channel.recipient?.tag ?? '¯\\_(ツ)_/¯')} (${ channel.recipient?.id ?? '¯\\_(ツ)_/¯' @@ -55,11 +55,11 @@ export default class SnowflakeCommand extends BushCommand { `:snowflake: DM with ${util.discord.escapeMarkdown(channel.recipient?.tag ?? '¯\\_(ツ)_/¯')} \`[Channel]\`` ); } else if ( - channel.isCategory() || - channel.isNews() || - channel.isText() || - channel.isVoice() || - channel.isStage() || + channel.type === ChannelType.GuildCategory || + channel.type === ChannelType.GuildNews || + channel.type === ChannelType.GuildText || + channel.type === ChannelType.GuildVoice || + channel.type === ChannelType.GuildStageVoice || channel.isThread() ) { channelInfo.push( diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index cb2fc5f..d617756 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -1,22 +1,17 @@ -import { - BushCommand, - Time, - type ArgType, - type BushGuild, - type BushGuildMember, - type BushMessage, - type BushSlashMessage, - type BushUser -} from '#lib'; -import { TeamMemberMembershipState, type APIApplication } from 'discord-api-types/v10'; +import { BushCommand, Time, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import { ActivityType, ApplicationCommandOptionType, ApplicationFlagsBitField, - ApplicationFlagsString, EmbedBuilder, PermissionFlagsBits, - UserFlags + TeamMemberMembershipState, + UserFlags, + type APIApplication, + type ApplicationFlagsString, + type Guild, + type GuildMember, + type User } from 'discord.js'; export default class UserInfoCommand extends BushCommand { @@ -45,7 +40,7 @@ export default class UserInfoCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { user: ArgType<'user'> | ArgType<'snowflake'> }) { + public override async exec(message: CommandMessage | SlashMessage, args: { user: OptArgType<'user' | 'snowflake'> }) { const user = args.user === null ? message.author @@ -61,7 +56,7 @@ export default class UserInfoCommand extends BushCommand { return await message.util.reply({ embeds: [userEmbed] }); } - public static async makeUserInfoEmbed(user: BushUser, member?: BushGuildMember, guild?: BushGuild | null) { + public static async makeUserInfoEmbed(user: User, member?: GuildMember, guild?: Guild | null) { const emojis = []; const superUsers = util.getShared('superUsers'); @@ -121,7 +116,7 @@ export default class UserInfoCommand extends BushCommand { return userEmbed; } - public static async generateGeneralInfoField(embed: EmbedBuilder, user: BushUser, title = '» General Information') { + public static async generateGeneralInfoField(embed: EmbedBuilder, user: User, title = '» General Information') { // General Info const generalInfo = [ `**Mention:** <@${user.id}>`, @@ -138,11 +133,7 @@ export default class UserInfoCommand extends BushCommand { embed.addFields([{ name: title, value: generalInfo.join('\n') }]); } - public static generateServerInfoField( - embed: EmbedBuilder, - member?: BushGuildMember | undefined, - title = '» Server Information' - ) { + public static generateServerInfoField(embed: EmbedBuilder, member?: GuildMember | undefined, title = '» Server Information') { if (!member) return; // Server User Info @@ -167,7 +158,7 @@ export default class UserInfoCommand extends BushCommand { if (serverUserInfo.length) embed.addFields([{ name: title, value: serverUserInfo.join('\n') }]); } - public static generatePresenceField(embed: EmbedBuilder, member?: BushGuildMember | undefined, title = '» Presence') { + public static generatePresenceField(embed: EmbedBuilder, member?: GuildMember | undefined, title = '» Presence') { if (!member || !member.presence) return; if (!member.presence.status && !member.presence.clientStatus && !member.presence.activities) return; @@ -207,7 +198,7 @@ export default class UserInfoCommand extends BushCommand { }); } - public static generateRolesField(embed: EmbedBuilder, member?: BushGuildMember | undefined) { + public static generateRolesField(embed: EmbedBuilder, member?: GuildMember | undefined) { if (!member || member.roles.cache.size <= 1) return; // roles @@ -227,7 +218,7 @@ export default class UserInfoCommand extends BushCommand { public static generatePermissionsField( embed: EmbedBuilder, - member: BushGuildMember | undefined, + member: GuildMember | undefined, title = '» Important Permissions' ) { if (!member) return; @@ -247,7 +238,7 @@ export default class UserInfoCommand extends BushCommand { if (perms.length) embed.addFields([{ name: title, value: perms.join(' ') }]); } - public static async generateBotField(embed: EmbedBuilder, user: BushUser, title = '» Bot Information') { + public static async generateBotField(embed: EmbedBuilder, user: User, title = '» Bot Information') { if (!user.bot) return; const applicationInfo = (await client.rest.get(`/applications/${user.id}/rpc`).catch(() => null)) as APIApplication | null; |