diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-20 22:50:45 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-20 22:50:45 -0500 |
commit | 8fb88c737e49321ff2b612a9d0e0e059c64c272a (patch) | |
tree | 6d22573479b7e7e047eceb85dbb7520b616a5a45 /src | |
parent | d4a401ed2315a7b5e7dfa390836f2ebae1299976 (diff) | |
download | tanzanite-8fb88c737e49321ff2b612a9d0e0e059c64c272a.tar.gz tanzanite-8fb88c737e49321ff2b612a9d0e0e059c64c272a.tar.bz2 tanzanite-8fb88c737e49321ff2b612a9d0e0e059c64c272a.zip |
do some fixes or something
Diffstat (limited to 'src')
31 files changed, 214 insertions, 110 deletions
diff --git a/src/arguments/contentWithDuration.ts b/src/arguments/contentWithDuration.ts index a9a7c23..41cb9bb 100644 --- a/src/arguments/contentWithDuration.ts +++ b/src/arguments/contentWithDuration.ts @@ -1,8 +1,5 @@ -import { type BushArgumentTypeCaster } from '#lib'; +import { ParsedDuration, type BushArgumentTypeCaster } from '#lib'; -export const contentWithDuration: BushArgumentTypeCaster = async ( - _, - phrase -): Promise<{ duration: number | null; contentWithoutTime: string | null }> => { +export const contentWithDuration: BushArgumentTypeCaster = async (_, phrase): Promise<ParsedDuration> => { return client.util.parseDuration(phrase); }; diff --git a/src/arguments/discordEmoji.ts b/src/arguments/discordEmoji.ts index 8648f7f..a3c531c 100644 --- a/src/arguments/discordEmoji.ts +++ b/src/arguments/discordEmoji.ts @@ -1,9 +1,14 @@ import { type BushArgumentTypeCaster } from '#lib'; import { type Snowflake } from 'discord-api-types'; -export const discordEmoji: BushArgumentTypeCaster = (_, phrase): { name: string; id: Snowflake } | null => { +export const discordEmoji: BushArgumentTypeCaster = (_, phrase): DiscordEmojiInfo | null => { if (!phrase) return null; const validEmoji: RegExpExecArray | null = client.consts.regex.discordEmoji.exec(phrase); if (!validEmoji || !validEmoji.groups) return null; return { name: validEmoji.groups.name, id: validEmoji.groups.id }; }; + +export interface DiscordEmojiInfo { + name: string; + id: Snowflake; +} diff --git a/src/arguments/permission.ts b/src/arguments/permission.ts index 8c09072..b5ff4bf 100644 --- a/src/arguments/permission.ts +++ b/src/arguments/permission.ts @@ -1,12 +1,12 @@ import { type BushArgumentTypeCaster } from '#lib'; -import { Permissions } from 'discord.js'; +import { Permissions, PermissionString } from 'discord.js'; -export const permission: BushArgumentTypeCaster = (_, phrase) => { +export const permission: BushArgumentTypeCaster = (_, phrase): PermissionString | null => { if (!phrase) return null; phrase = phrase.toUpperCase().replace(/ /g, '_'); if (!(phrase in Permissions.FLAGS)) { return null; } else { - return phrase; + return phrase as PermissionString; } }; diff --git a/src/arguments/roleWithDuration.ts b/src/arguments/roleWithDuration.ts index 9bf4bb2..999ac1c 100644 --- a/src/arguments/roleWithDuration.ts +++ b/src/arguments/roleWithDuration.ts @@ -1,9 +1,7 @@ import { type BushArgumentTypeCaster } from '#lib'; +import { Role } from 'discord.js'; -export const roleWithDuration: BushArgumentTypeCaster = async ( - message, - phrase -): Promise<{ duration: number | null; role: string | null } | null> => { +export const roleWithDuration: BushArgumentTypeCaster = async (message, phrase): Promise<RoleWithDuration | null> => { // eslint-disable-next-line prefer-const let { duration, contentWithoutTime } = client.util.parseDuration(phrase); if (contentWithoutTime === null || contentWithoutTime === undefined) return null; @@ -12,3 +10,8 @@ export const roleWithDuration: BushArgumentTypeCaster = async ( if (!role) return null; return { duration, role }; }; + +export interface RoleWithDuration { + duration: number | null; + role: Role | null; +} @@ -5,8 +5,6 @@ import config from './config/options.js'; import { Sentry } from './lib/common/Sentry.js'; import { BushClient } from './lib/index.js'; -const __dirname = dirname(fileURLToPath(import.meta.url)); -global.__rootdir__ = __dirname || process.cwd(); -new Sentry(); +new Sentry(dirname(fileURLToPath(import.meta.url)) || process.cwd()); BushClient.init(); void new BushClient(config).start(); diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index b44ae21..17bea40 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -14,7 +14,7 @@ export default class ChannelPermissionsCommand extends BushCommand { { id: 'target', description: 'The user/role to change the permissions of.', - customType: util.arg.union('member', 'role'), + type: util.arg.union('member', 'role'), readableType: 'member|role', prompt: 'What user/role would you like to change?', retry: '{error} Choose a valid user/role to change.', @@ -58,7 +58,7 @@ export default class ChannelPermissionsCommand extends BushCommand { message: BushMessage | BushSlashMessage, args: { target: Role | GuildMember; - permission: PermissionString | string; + permission: PermissionString; state: 'true' | 'false' | 'neutral'; } ) { @@ -67,7 +67,7 @@ export default class ChannelPermissionsCommand extends BushCommand { return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); - const permission: PermissionString = message.util.isSlashMessage(message) + const permission = message.util.isSlashMessage(message) ? await util.arg.cast('permission', message, args.permission) : args.permission; if (!permission) return await message.util.reply(`${util.emojis.error} Invalid permission.`); diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index 8bb778c..da4ad18 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -1,5 +1,6 @@ import { AllowedMentions, BushCommand, Global, type BushMessage, type BushSlashMessage } from '#lib'; -import { User, type Channel } from 'discord.js'; +import { GuildTextBasedChannels } from 'discord-akairo'; +import { User } from 'discord.js'; export default class BlacklistCommand extends BushCommand { public constructor() { @@ -25,7 +26,7 @@ export default class BlacklistCommand extends BushCommand { { id: 'target', description: 'The channel/user to blacklist.', - customType: util.arg.union('channel', 'user'), + type: util.arg.union('channel', 'user'), readableType: 'channel|user', prompt: 'What channel or user that you would like to blacklist/unblacklist?', retry: '{error} Pick a valid user or channel.', @@ -51,14 +52,14 @@ export default class BlacklistCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { action: 'blacklist' | 'unblacklist'; target: Channel | User | string; global: boolean } + args: { action: 'blacklist' | 'unblacklist'; target: GuildTextBasedChannels | User | string; global: boolean } ) { let action: 'blacklist' | 'unblacklist' | 'toggle' = args.action ?? (message?.util?.parsed?.alias as 'blacklist' | 'unblacklist') ?? 'toggle'; const global = args.global && message.author.isOwner(); const target = typeof args.target === 'string' - ? (await util.arg.cast('channel', message, args.target)) ?? (await util.arg.cast('user', message, args.target)) + ? (await util.arg.cast('textChannel', message, args.target)) ?? (await util.arg.cast('user', message, args.target)) : args.target; if (!target) return await message.util.reply(`${util.emojis.error} Choose a valid channel or user.`); const targetID = target.id; @@ -81,13 +82,15 @@ export default class BlacklistCommand extends BushCommand { if (!success) return await message.util.reply({ content: `${util.emojis.error} There was an error globally ${action}ing ${util.format.input( - target?.tag ?? target.name + target instanceof User ? target.tag : target.name )}.`, allowedMentions: AllowedMentions.none() }); else return await message.util.reply({ - content: `${util.emojis.success} Successfully ${action}ed ${util.format.input(target?.tag ?? target.name)} globally.`, + content: `${util.emojis.success} Successfully ${action}ed ${util.format.input( + target instanceof User ? target.tag : target.name + )} globally.`, allowedMentions: AllowedMentions.none() }); // guild disable @@ -108,12 +111,16 @@ export default class BlacklistCommand extends BushCommand { .catch(() => false); if (!success) return await message.util.reply({ - content: `${util.emojis.error} There was an error ${action}ing ${util.format.input(target?.tag ?? target.name)}.`, + content: `${util.emojis.error} There was an error ${action}ing ${util.format.input( + target instanceof User ? target.tag : target.name + )}.`, allowedMentions: AllowedMentions.none() }); else return await message.util.reply({ - content: `${util.emojis.success} Successfully ${action}ed ${util.format.input(target?.tag ?? target.name)}.`, + content: `${util.emojis.success} Successfully ${action}ed ${util.format.input( + target instanceof User ? target.tag : target.name + )}.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index 333ae19..a30652a 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -21,7 +21,7 @@ export default class DisableCommand extends BushCommand { { id: 'command', description: 'The command to disable/enable.', - customType: util.arg.union('commandAlias', 'command'), + type: util.arg.union('commandAlias', 'command'), readableType: 'command|commandAlias', prompt: 'What command would you like to enable/disable?', retry: '{error} Pick a valid command.', diff --git a/src/commands/info/avatar.ts b/src/commands/info/avatar.ts index 87ea0cc..36504f8 100644 --- a/src/commands/info/avatar.ts +++ b/src/commands/info/avatar.ts @@ -13,7 +13,7 @@ export default class AvatarCommand extends BushCommand { { id: 'user', description: 'The user you would like to find the avatar of.', - customType: util.arg.union('member', 'globalUser'), + type: util.arg.union('member', 'globalUser'), readableType: 'member|user', prompt: 'Who would you like to see the avatar of?', retry: '{error} Choose a valid user.', diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts index cb612b5..4277d56 100644 --- a/src/commands/info/color.ts +++ b/src/commands/info/color.ts @@ -1,9 +1,16 @@ -import { AllowedMentions, BushCommand, type BushGuildMember, type BushMessage, type BushRole, type BushSlashMessage } from '#lib'; -import { Argument } from 'discord-akairo'; -import { MessageEmbed, Role, type Message } from 'discord.js'; +import { + AllowedMentions, + BushArgumentTypeCaster, + BushCommand, + type BushGuildMember, + type BushMessage, + type BushRole, + type BushSlashMessage +} from '#lib'; +import { MessageEmbed, Role } from 'discord.js'; import tinycolor from 'tinycolor2'; -const isValidTinyColor = (_message: Message, phase: string) => { +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; @@ -21,7 +28,7 @@ export default class ColorCommand extends BushCommand { { id: 'color', description: 'The color string, role, or member to find the color of.', - customType: Argument.union(isValidTinyColor, 'role', 'member'), + type: util.arg.union(isValidTinyColor as any, 'role', 'member'), readableType: 'color|role|member', match: 'restContent', prompt: 'What color code, role, or user would you like to find the color of?', @@ -41,7 +48,7 @@ export default class ColorCommand extends BushCommand { public override async exec(message: BushMessage | BushSlashMessage, args: { color: string | BushRole | BushGuildMember }) { const _color = message.util.isSlashMessage(message) - ? ((await util.arg.cast(Argument.union(isValidTinyColor, 'role', 'member'), message, args.color as string)) as + ? ((await util.arg.cast(util.arg.union(isValidTinyColor as any, 'role', 'member'), message, args.color as string)) as | string | BushRole | BushGuildMember) diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index a38a446..ab09741 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -21,7 +21,7 @@ export default class GuildInfoCommand extends BushCommand { { id: 'guild', description: 'The guild to find information about.', - customType: util.arg.union('guild', 'snowflake'), + type: util.arg.union('guild', 'snowflake'), readableType: 'guild|snowflake', prompt: 'What server would you like to find information about?', retry: '{error} Choose a valid server to find information about.', diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 89d3c23..2d7fcfb 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -14,7 +14,7 @@ export default class UserInfoCommand extends BushCommand { { id: 'user', description: 'The user you would like to find information about.', - customType: util.arg.union('user', 'snowflake'), + type: util.arg.union('user', 'snowflake'), readableType: 'user|snowflake', prompt: 'What user would you like to find information about?', retry: '{error} Choose a valid user to find information about.', diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 3d68a97..506a7c3 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -13,7 +13,7 @@ export default class BanCommand extends BushCommand { { id: 'user', description: 'The user that will be banned.', - customType: util.arg.union('user', 'snowflake'), + type: util.arg.union('user', 'snowflake'), prompt: 'What user would you like to ban?', retry: '{error} Choose a valid user to ban.', slashType: 'USER' @@ -35,7 +35,7 @@ export default class BanCommand extends BushCommand { match: 'option', prompt: "How many days of the user's messages would you like to delete?", retry: '{error} Choose between 0 and 7 days to delete messages from the user for.', - customType: util.arg.range('integer', 0, 7, true), + type: util.arg.range('integer', 0, 7, true), optional: true, slashType: 'INTEGER', choices: [...Array(8).keys()].map((v) => ({ name: v.toString(), value: v })) @@ -91,7 +91,7 @@ export default class BanCommand extends BushCommand { return message.util.reply(`${util.emojis.error} The delete days must be an integer between 0 and 7.`); } - let time: number; + let time: number | null; if (args.reason) { time = typeof args.reason === 'string' ? await util.arg.cast('duration', message, args.reason) : args.reason.duration; } diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 474eaa9..0f2d33c 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -13,7 +13,7 @@ export default class ModlogCommand extends BushCommand { { id: 'search', description: 'The case id or user to search for modlogs by.', - customType: util.arg.union('user', 'string'), + type: util.arg.union('user', 'string'), prompt: 'What case id or user would you like to see?', retry: '{error} Choose a valid case id or user.', slashType: 'STRING' diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index a18c04e..c7091b3 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -49,7 +49,7 @@ export default class MuteCommand extends BushCommand { message: BushMessage | BushSlashMessage, args: { user: BushUser; reason?: { duration: number | null; contentWithoutTime: string } | string; force: boolean } ) { - const reason: { duration: number | null; contentWithoutTime: string } = args.reason + const reason: { duration: number | null; contentWithoutTime: string | null } = args.reason ? typeof args.reason === 'string' ? await util.arg.cast('contentWithDuration', message, args.reason) : args.reason diff --git a/src/commands/moderation/purge.ts b/src/commands/moderation/purge.ts index 21b9a3a..f039046 100644 --- a/src/commands/moderation/purge.ts +++ b/src/commands/moderation/purge.ts @@ -13,7 +13,7 @@ export default class PurgeCommand extends BushCommand { { id: 'amount', description: 'The amount of messages to purge.', - customType: util.arg.range('integer', 1, 100, true), + type: util.arg.range('integer', 1, 100, true), readableType: 'integer', prompt: 'How many messages would you like to purge?', retry: '{error} Please pick a number between 1 and 100.', diff --git a/src/commands/moderation/removeReactionEmoji.ts b/src/commands/moderation/removeReactionEmoji.ts index d543f60..4ada9d5 100644 --- a/src/commands/moderation/removeReactionEmoji.ts +++ b/src/commands/moderation/removeReactionEmoji.ts @@ -21,7 +21,7 @@ export default class RemoveReactionEmojiCommand extends BushCommand { { id: 'emoji', description: 'The emoji to remove all the reactions of from a message.', - customType: util.arg.union('emoji', 'snowflake'), + type: util.arg.union('emoji', 'snowflake'), readableType: 'emoji|snowflake', match: 'restContent', prompt: 'What emoji would you like to remove?', diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts index 949038c..f4ab822 100644 --- a/src/commands/moderation/slowmode.ts +++ b/src/commands/moderation/slowmode.ts @@ -21,7 +21,7 @@ export default class SlowModeCommand extends BushCommand { { id: 'length', description: 'The amount of time to set the slowmode of a channel to.', - customType: Argument.union('duration', 'durationSeconds', 'off', 'none', 'disable'), + type: Argument.union('duration', 'durationSeconds', 'off', 'none', 'disable'), readableType: "duration|durationSeconds|'off'|'none'|'disable'", prompt: 'What would you like to set the slowmode to?', retry: '{error} Please set the slowmode to a valid length.', @@ -52,7 +52,7 @@ export default class SlowModeCommand extends BushCommand { length, channel }: { - length: number | 'off' | 'none' | 'disable'; + length: number | 'off' | 'none' | 'disable' | null; channel: TextChannel | ThreadChannel | BushTextChannel | BushNewsChannel | BushThreadChannel | NewsChannel; } ) { diff --git a/src/commands/moulberry-bush/rule.ts b/src/commands/moulberry-bush/rule.ts index a88b323..2404c4d 100644 --- a/src/commands/moulberry-bush/rule.ts +++ b/src/commands/moulberry-bush/rule.ts @@ -62,7 +62,7 @@ export default class RuleCommand extends BushCommand { { id: 'rule', description: 'The rule to view.', - customType: util.arg.range('integer', 1, rules.length, true), + type: util.arg.range('integer', 1, rules.length, true), readableType: 'integer', prompt: 'What rule would you like to have cited?', retry: '{error} Choose a valid rule.', diff --git a/src/commands/utilities/activity.ts b/src/commands/utilities/activity.ts index 6829757..2ab56cc 100644 --- a/src/commands/utilities/activity.ts +++ b/src/commands/utilities/activity.ts @@ -112,7 +112,7 @@ export default class YouTubeCommand extends BushCommand { id: 'activity', description: 'The activity to create an invite for.', match: 'rest', - customType: activityTypeCaster, + type: activityTypeCaster, prompt: 'What activity would you like to play?', retry: `{error} You must choose one of the following options: ${Object.values(activityMap) .flatMap((a) => a.aliases) diff --git a/src/commands/utilities/steal.ts b/src/commands/utilities/steal.ts index 190277a..6a15d71 100644 --- a/src/commands/utilities/steal.ts +++ b/src/commands/utilities/steal.ts @@ -1,5 +1,5 @@ import { BushCommand, BushSlashMessage, type BushMessage } from '#lib'; -import { ArgumentOptions, Flag } from 'discord-akairo'; +import { ArgumentOptions, ArgumentType, ArgumentTypeCaster, Flag } from 'discord-akairo'; import { type Snowflake } from 'discord.js'; import _ from 'lodash'; @@ -15,7 +15,7 @@ export default class StealCommand extends BushCommand { { id: 'emoji', description: 'The emoji to steal.', - customType: util.arg.union('discordEmoji', 'snowflake', 'url'), + type: util.arg.union('discordEmoji', 'snowflake', 'url'), readableType: 'discordEmoji|snowflake|url', prompt: 'What emoji would you like to steal?', retry: '{error} Pick a valid emoji, emoji id, or image url.', @@ -47,7 +47,7 @@ export default class StealCommand extends BushCommand { ? message.attachments.first()!.url : yield { id: 'emoji', - type: util.arg.union('discordEmoji', 'snowflake', 'url'), + type: util.arg.union('discordEmoji', 'snowflake', 'url') as ArgumentType | ArgumentTypeCaster, prompt: { start: 'What emoji would you like to steal?', retry: '{error} Pick a valid emoji, emoji id, or image url.' diff --git a/src/commands/utilities/viewRaw.ts b/src/commands/utilities/viewRaw.ts index c934e2e..0809a39 100644 --- a/src/commands/utilities/viewRaw.ts +++ b/src/commands/utilities/viewRaw.ts @@ -13,7 +13,7 @@ export default class ViewRawCommand extends BushCommand { { id: 'message', description: 'The message to view the raw content of.', - customType: util.arg.union('guildMessage', 'messageLink'), + type: util.arg.union('guildMessage', 'messageLink'), readableType: 'guildMessage|messageLink', prompt: 'What message would you like to view?', retry: '{error} Choose a valid message.', diff --git a/src/lib/common/Sentry.ts b/src/lib/common/Sentry.ts index 1de09ac..119e205 100644 --- a/src/lib/common/Sentry.ts +++ b/src/lib/common/Sentry.ts @@ -1,12 +1,18 @@ +import { RewriteFrames } from '@sentry/integrations'; import * as SentryNode from '@sentry/node'; import config from './../../config/options.js'; export class Sentry { - public constructor() { + public constructor(rootdir: string) { SentryNode.init({ dsn: config.credentials.sentryDsn, environment: config.environment, - tracesSampleRate: 1.0 + tracesSampleRate: 1.0, + integrations: [ + new RewriteFrames({ + root: rootdir + }) + ] }); } } diff --git a/src/lib/common/util/Arg.ts b/src/lib/common/util/Arg.ts index 1982f4a..9ce8b54 100644 --- a/src/lib/common/util/Arg.ts +++ b/src/lib/common/util/Arg.ts @@ -1,4 +1,4 @@ -import { type BushArgumentType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BaseBushArgumentType, BushArgumentTypeCaster, BushSlashMessage, type BushArgumentType } from '#lib'; import { Argument, type ArgumentTypeCaster, type Flag, type ParsedValuePredicate } from 'discord-akairo'; import { type Message } from 'discord.js'; @@ -9,12 +9,16 @@ export class Arg { * @param message - Message that called the command. * @param phrase - Phrase to process. */ - public static cast( - type: BushArgumentType | ArgumentTypeCaster, - message: BushMessage | BushSlashMessage, - phrase: string - ): Promise<any> { - return Argument.cast(type, client.commandHandler.resolver, message as Message, phrase); + public static async cast<T extends ATC>(type: T, message: Message | BushSlashMessage, phrase: string): Promise<ATCR<T>>; + public static async cast<T extends KBAT>(type: T, message: Message | BushSlashMessage, phrase: string): Promise<BAT[T]>; + public static async cast<T extends AT | ATC>(type: T, message: Message | BushSlashMessage, phrase: string): Promise<any>; + public static async cast(type: ATC | AT, message: Message | BushSlashMessage, phrase: string): Promise<any> { + return Argument.cast( + type as ArgumentTypeCaster | keyof BushArgumentType, + client.commandHandler.resolver, + message as Message, + phrase + ); } /** @@ -22,8 +26,11 @@ export class Arg { * If any of the types fails, the entire composition fails. * @param types - Types to use. */ - public static compose(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.compose(...types); + public static compose<T extends ATC>(...types: T[]): ATCATCR<T>; + public static compose<T extends KBAT>(...types: T[]): ATCBAT<T>; + public static compose<T extends AT | ATC>(...types: T[]): ATC; + public static compose(...types: (AT | ATC)[]): ATC { + return Argument.compose(...(types as any)); } /** @@ -31,8 +38,11 @@ export class Arg { * If any of the types fails, the composition still continues with the failure passed on. * @param types - Types to use. */ - public static composeWithFailure(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.composeWithFailure(...types); + public static composeWithFailure<T extends ATC>(...types: T[]): ATCATCR<T>; + public static composeWithFailure<T extends KBAT>(...types: T[]): ATCBAT<T>; + public static composeWithFailure<T extends AT | ATC>(...types: T[]): ATC; + public static composeWithFailure(...types: (AT | ATC)[]): ATC { + return Argument.composeWithFailure(...(types as any)); } /** @@ -48,8 +58,11 @@ export class Arg { * Only inputs where each type resolves with a non-void value are valid. * @param types - Types to use. */ - public static product(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.product(...types); + public static product<T extends ATC>(...types: T[]): ATCATCR<T>; + public static product<T extends KBAT>(...types: T[]): ATCBAT<T>; + public static product<T extends AT | ATC>(...types: T[]): ATC; + public static product(...types: (AT | ATC)[]): ATC { + return Argument.product(...(types as any)); } /** @@ -59,8 +72,11 @@ export class Arg { * @param max - Maximum value. * @param inclusive - Whether or not to be inclusive on the upper bound. */ - public static range(type: BushArgumentType, min: number, max: number, inclusive?: boolean): ArgumentTypeCaster { - return Argument.range(type, min, max, inclusive); + public static range<T extends ATC>(type: T, min: number, max: number, inclusive?: boolean): ATCATCR<T>; + public static range<T extends KBAT>(type: T, min: number, max: number, inclusive?: boolean): ATCBAT<T>; + public static range<T extends AT | ATC>(type: T, min: number, max: number, inclusive?: boolean): ATC; + public static range(type: AT | ATC, min: number, max: number, inclusive?: boolean): ATC { + return Argument.range(type as any, min, max, inclusive); } /** @@ -69,8 +85,11 @@ export class Arg { * @param type - The type to use. * @param tag - Tag to add. Defaults to the `type` argument, so useful if it is a string. */ - public static tagged(type: BushArgumentType, tag?: any): ArgumentTypeCaster { - return Argument.tagged(type, tag); + public static tagged<T extends ATC>(type: T, tag?: any): ATCATCR<T>; + public static tagged<T extends KBAT>(type: T, tag?: any): ATCBAT<T>; + public static tagged<T extends AT | ATC>(type: T, tag?: any): ATC; + public static tagged(type: AT | ATC, tag?: any): ATC { + return Argument.tagged(type as any, tag); } /** @@ -79,8 +98,11 @@ export class Arg { * Each type will also be tagged using `tagged` with themselves. * @param types - Types to use. */ - public static taggedUnion(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.taggedUnion(...types); + public static taggedUnion<T extends ATC>(...types: T[]): ATCATCR<T>; + public static taggedUnion<T extends KBAT>(...types: T[]): ATCBAT<T>; + public static taggedUnion<T extends AT | ATC>(...types: T[]): ATC; + public static taggedUnion(...types: (AT | ATC)[]): ATC { + return Argument.taggedUnion(...(types as any)); } /** @@ -89,8 +111,11 @@ export class Arg { * @param type - The type to use. * @param tag - Tag to add. Defaults to the `type` argument, so useful if it is a string. */ - public static taggedWithInput(type: BushArgumentType, tag?: any): ArgumentTypeCaster { - return Argument.taggedWithInput(type, tag); + public static taggedWithInput<T extends ATC>(type: T, tag?: any): ATCATCR<T>; + public static taggedWithInput<T extends KBAT>(type: T, tag?: any): ATCBAT<T>; + public static taggedWithInput<T extends AT | ATC>(type: T, tag?: any): ATC; + public static taggedWithInput(type: AT | ATC, tag?: any): ATC { + return Argument.taggedWithInput(type as any, tag); } /** @@ -98,8 +123,11 @@ export class Arg { * The first type that resolves to a non-void value is used. * @param types - Types to use. */ - public static union(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.union(...types); + public static union<T extends ATC>(...types: T[]): ATCATCR<T>; + public static union<T extends KBAT>(...types: T[]): ATCBAT<T>; + public static union<T extends AT | ATC>(...types: T[]): ATC; + public static union(...types: (AT | ATC)[]): ATC { + return Argument.union(...(types as any)); } /** @@ -108,8 +136,11 @@ export class Arg { * @param type - The type to use. * @param predicate - The predicate function. */ - public static validate(type: BushArgumentType, predicate: ParsedValuePredicate): ArgumentTypeCaster { - return Argument.validate(type, predicate); + public static validate<T extends ATC>(type: T, predicate: ParsedValuePredicate): ATCATCR<T>; + public static validate<T extends KBAT>(type: T, predicate: ParsedValuePredicate): ATCBAT<T>; + public static validate<T extends AT | ATC>(type: T, predicate: ParsedValuePredicate): ATC; + public static validate(type: AT | ATC, predicate: ParsedValuePredicate): ATC { + return Argument.validate(type as any, predicate); } /** @@ -117,7 +148,41 @@ export class Arg { * Result is in an object `{ input, value }` and wrapped in `Flag.fail` when failed. * @param type - The type to use. */ - public static withInput(type: BushArgumentType): ArgumentTypeCaster { - return Argument.withInput(type); + public static withInput<T extends ATC>(type: T): ATC<ATCR<T>>; + public static withInput<T extends KBAT>(type: T): ATCBAT<T>; + public static withInput<T extends AT | ATC>(type: T): ATC; + public static withInput(type: AT | ATC): ATC { + return Argument.withInput(type as any); } } + +type ArgumentTypeCasterReturn<R> = R extends BushArgumentTypeCaster<infer S> ? S : R; +/** ```ts + * <R = unknown> = ArgumentTypeCaster<R> + * ``` */ +type ATC<R = unknown> = BushArgumentTypeCaster<R>; +/** ```ts + * keyof BaseArgumentType + * ``` */ +type KBAT = keyof BaseBushArgumentType; +/** ```ts + * <R> = ArgumentTypeCasterReturn<R> + * ``` */ +type ATCR<R> = ArgumentTypeCasterReturn<R>; +/** ```ts + * keyof BaseBushArgumentType | string + * ``` */ +type AT = BushArgumentTypeCaster | keyof BaseBushArgumentType | string; +/** ```ts + * BaseArgumentType + * ``` */ +type BAT = BaseBushArgumentType; + +/** ```ts + * <T extends ArgumentTypeCaster> = ArgumentTypeCaster<ArgumentTypeCasterReturn<T>> + * ``` */ +type ATCATCR<T extends BushArgumentTypeCaster> = BushArgumentTypeCaster<ArgumentTypeCasterReturn<T>>; +/** ```ts + * <T extends keyof BaseArgumentType> = ArgumentTypeCaster<BaseArgumentType[T]> + * ``` */ +type ATCBAT<T extends keyof BaseBushArgumentType> = BushArgumentTypeCaster<BaseBushArgumentType[T]>; diff --git a/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts b/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts index f27fb89..7a9a3db 100644 --- a/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts +++ b/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts @@ -1,3 +1,3 @@ import { type BushMessage } from '#lib'; -export type BushArgumentTypeCaster = (message: BushMessage, phrase: string) => any; +export type BushArgumentTypeCaster<R = unknown> = (message: BushMessage, phrase: string) => R; diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index e5ce7be..a9e172a 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -187,8 +187,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re prefix: async ({ guild }: Message) => { if (this.config.isDevelopment) return 'dev '; if (!guild) return this.config.prefix; - const row = await GuildModel.findByPk(guild.id); - return (row?.prefix ?? this.config.prefix) as string; + const prefix = await (guild as BushGuild).getSetting('prefix'); + return (prefix ?? this.config.prefix) as string; }, allowMention: true, handleEdits: true, @@ -348,7 +348,10 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re * Starts the bot */ public async start() { - void this.logger.success('version', process.version, false); + if (!process.version.startsWith('v17.')) { + void (await this.console.error('version', `Please use node <<v17.x.x>>, not <<${process.version}>>.`, false)); + process.exit(2); + } this.intercept('ready', async (arg, done) => { await this.guilds.fetch(); const promises = this.guilds.cache.map((guild) => { diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index cded096..ab1f3ed 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -112,7 +112,7 @@ export class BushClientUtil extends ClientUtil { void this.handleError('haste', new Error(`content over 400,000 characters (${content.length.toLocaleString()})`)); return { error: 'content too long' }; } else if (content.length > 400_000) { - content = content.substr(0, 400_000); + content = content.substring(0, 400_000); isSubstr = true; } for (const url of this.#hasteURLs) { diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index d8f0d38..5111c19 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -1,4 +1,12 @@ -import { type BushClient, type BushCommandHandler, type BushMessage, type BushSlashMessage } from '#lib'; +import { + BushArgumentTypeCaster, + BushUser, + ParsedDuration, + type BushClient, + type BushCommandHandler, + type BushMessage, + type BushSlashMessage +} from '#lib'; import { AkairoApplicationCommandAutocompleteOption, AkairoApplicationCommandChannelOptionData, @@ -13,25 +21,26 @@ import { SlashOption, SlashResolveTypes, type ArgumentOptions, - type ArgumentTypeCaster, type CommandOptions } from 'discord-akairo'; -import { BaseArgumentType } from 'discord-akairo/dist/src/struct/commands/arguments/Argument'; -import { ApplicationCommandOptionChoice, type PermissionResolvable, type Snowflake } from 'discord.js'; - -export type BaseBushArgumentType = - | BaseArgumentType - | 'duration' - | 'contentWithDuration' - | 'permission' - | 'snowflake' - | 'discordEmoji' - | 'roleWithDuration' - | 'abbreviatedNumber' - | 'globalUser' - | 'messageLink'; - -export type BushArgumentType = BaseBushArgumentType | RegExp; +import { ArgumentType, ArgumentTypeCaster, BaseArgumentType } from 'discord-akairo/dist/src/struct/commands/arguments/Argument'; +import { ApplicationCommandOptionChoice, PermissionString, type PermissionResolvable, type Snowflake } from 'discord.js'; +import { DiscordEmojiInfo } from '../../../arguments/discordEmoji'; +import { RoleWithDuration } from '../../../arguments/roleWithDuration'; + +export interface BaseBushArgumentType extends BaseArgumentType { + duration: number | null; + contentWithDuration: ParsedDuration; + permission: PermissionString | null; + snowflake: Snowflake | null; + discordEmoji: DiscordEmojiInfo | null; + roleWithDuration: RoleWithDuration | null; + abbreviatedNumber: number | null; + globalUser: BushUser | null; + messageLink: BushMessage | null; +} + +export type BushArgumentType = keyof BaseBushArgumentType | RegExp; interface BaseBushArgumentOptions extends Omit<ArgumentOptions, 'type' | 'prompt'> { id: string; @@ -149,7 +158,7 @@ export interface BushArgumentOptions extends BaseBushArgumentOptions { * - `contentWithDuration` tries to parse duration in milliseconds and returns the remaining content with the duration * removed */ - type?: BushArgumentType | BaseBushArgumentType[]; + type?: BushArgumentType | (keyof BaseBushArgumentType)[] | BushArgumentTypeCaster; } export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { /** @@ -160,7 +169,7 @@ export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { * A regular expression can also be used. * The evaluated argument will be an object containing the `match` and `matches` if global. */ - customType?: ArgumentTypeCaster | (string | string[])[] | RegExp | string | null; + customType?: (string | string[])[] | RegExp | string | null; } export type BushMissingPermissionSupplier = (message: BushMessage | BushSlashMessage) => Promise<any> | any; @@ -344,7 +353,7 @@ export class BushCommand extends Command { if ('retry' in arg) newArg.prompt.retry = arg.retry; if ('optional' in arg) newArg.prompt.optional = arg.optional; } - if ('type' in arg) newArg.type = arg.type; + if ('type' in arg) newArg.type = arg.type as ArgumentType | ArgumentTypeCaster; if ('unordered' in arg) newArg.unordered = arg.unordered; newTextArgs.push(newArg); } diff --git a/src/lib/extensions/discord.js/BushStoreChannel.ts b/src/lib/extensions/discord.js/BushStoreChannel.ts index 8540936..918c27b 100644 --- a/src/lib/extensions/discord.js/BushStoreChannel.ts +++ b/src/lib/extensions/discord.js/BushStoreChannel.ts @@ -2,6 +2,7 @@ import type { BushCategoryChannel, BushClient, BushGuild, BushGuildMember } from import { StoreChannel, type Collection, type Snowflake } from 'discord.js'; import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes'; +// eslint-disable-next-line deprecation/deprecation export class BushStoreChannel extends StoreChannel { public declare guild: BushGuild; public declare readonly members: Collection<Snowflake, BushGuildMember>; diff --git a/src/lib/extensions/global.d.ts b/src/lib/extensions/global.d.ts index 8427873..1df86bb 100644 --- a/src/lib/extensions/global.d.ts +++ b/src/lib/extensions/global.d.ts @@ -3,7 +3,6 @@ import type { BushClient, BushClientUtil } from '#lib'; declare global { var client: BushClient; var util: BushClientUtil; - var __rootdir__: string; // eslint-disable-next-line @typescript-eslint/no-unused-vars interface ReadonlyArray<T> { diff --git a/src/listeners/message/blacklistedFile.ts b/src/listeners/message/blacklistedFile.ts index 26e1719..ac1fd02 100644 --- a/src/listeners/message/blacklistedFile.ts +++ b/src/listeners/message/blacklistedFile.ts @@ -105,7 +105,9 @@ export default class BlacklistedFileListener extends BushListener { for (const attachment of foundEmojis) { try { const req = await got.get( - `https://cdn.discordapp.com/emojis/${attachment.groups?.id}.${attachment.groups?.animated === 'a' ? 'gif' : 'png'}` + `https://cdn.discordapp.com/emojis/${attachment.groups?.id}.${ + attachment.groups?.animated === 'a' ? 'gif' : 'png' + }` ); const rawHash = crypto.createHash('md5'); rawHash.update(req.rawBody.toString('binary')); @@ -143,7 +145,9 @@ export default class BlacklistedFileListener extends BushListener { ); void client.console.warn( 'blacklistedFile', - `Failed to delete <<${foundFiles.map((f) => f.description).join(' and ')}>> sent by <<${message.author.tag}>> in <<${ + `Failed to delete <<${foundFiles.map((f) => f.description).join(' and ')}>> sent by <<${ + message.author.tag + }>> in <<${ message.channel.type === 'DM' ? `${message.channel.recipient.tag}'s DMs` : message.channel.name }>>.` ); |