diff options
Diffstat (limited to 'src')
58 files changed, 343 insertions, 171 deletions
diff --git a/src/arguments/abbreviatedNumber.ts b/src/arguments/abbreviatedNumber.ts index 3a447d7..3027cb2 100644 --- a/src/arguments/abbreviatedNumber.ts +++ b/src/arguments/abbreviatedNumber.ts @@ -1,7 +1,7 @@ import { type BushArgumentTypeCaster } from '#lib'; import numeral from 'numeral'; -export const abbreviatedNumber: BushArgumentTypeCaster = (_, phrase): number | null => { +export const abbreviatedNumber: BushArgumentTypeCaster<number | null> = (_, phrase) => { if (!phrase) return null; const num = numeral(phrase?.toLowerCase()).value(); diff --git a/src/arguments/contentWithDuration.ts b/src/arguments/contentWithDuration.ts index 41cb9bb..3d87061 100644 --- a/src/arguments/contentWithDuration.ts +++ b/src/arguments/contentWithDuration.ts @@ -1,5 +1,5 @@ import { ParsedDuration, type BushArgumentTypeCaster } from '#lib'; -export const contentWithDuration: BushArgumentTypeCaster = async (_, phrase): Promise<ParsedDuration> => { +export const contentWithDuration: BushArgumentTypeCaster<Promise<ParsedDuration>> = async (_, phrase) => { return client.util.parseDuration(phrase); }; diff --git a/src/arguments/discordEmoji.ts b/src/arguments/discordEmoji.ts index a3c531c..d9428e1 100644 --- a/src/arguments/discordEmoji.ts +++ b/src/arguments/discordEmoji.ts @@ -1,7 +1,7 @@ import { type BushArgumentTypeCaster } from '#lib'; import { type Snowflake } from 'discord-api-types'; -export const discordEmoji: BushArgumentTypeCaster = (_, phrase): DiscordEmojiInfo | null => { +export const discordEmoji: BushArgumentTypeCaster<DiscordEmojiInfo | null> = (_, phrase) => { if (!phrase) return null; const validEmoji: RegExpExecArray | null = client.consts.regex.discordEmoji.exec(phrase); if (!validEmoji || !validEmoji.groups) return null; diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts index 9cb1d03..58593ef 100644 --- a/src/arguments/duration.ts +++ b/src/arguments/duration.ts @@ -1,5 +1,5 @@ import { type BushArgumentTypeCaster } from '#lib'; -export const duration: BushArgumentTypeCaster = (_, phrase): number | null => { +export const duration: BushArgumentTypeCaster<number | null> = (_, phrase) => { return client.util.parseDuration(phrase).duration; }; diff --git a/src/arguments/durationSeconds.ts b/src/arguments/durationSeconds.ts index 8cbfa21..74d136f 100644 --- a/src/arguments/durationSeconds.ts +++ b/src/arguments/durationSeconds.ts @@ -1,6 +1,6 @@ import { type BushArgumentTypeCaster } from '#lib'; -export const durationSeconds: BushArgumentTypeCaster = (_, phrase): number | null => { +export const durationSeconds: BushArgumentTypeCaster<number | null> = (_, phrase) => { phrase += 's'; return client.util.parseDuration(phrase).duration; }; diff --git a/src/arguments/globalUser.ts b/src/arguments/globalUser.ts index 081eabf..89e8324 100644 --- a/src/arguments/globalUser.ts +++ b/src/arguments/globalUser.ts @@ -1,7 +1,7 @@ import { BushUser, type BushArgumentTypeCaster } from '#lib'; // resolve non-cached users -export const globalUser: BushArgumentTypeCaster = async (_, phrase): Promise<BushUser | null> => { +export const globalUser: BushArgumentTypeCaster<Promise<BushUser | null>> = async (_, phrase) => { return client.users.cache.has(phrase) ? client.users.cache.get(`${phrase}`) ?? null : await client.users.fetch(`${phrase}`).catch(() => null); diff --git a/src/arguments/index.ts b/src/arguments/index.ts new file mode 100644 index 0000000..eebf0a2 --- /dev/null +++ b/src/arguments/index.ts @@ -0,0 +1,10 @@ +export * from './abbreviatedNumber.js'; +export * from './contentWithDuration.js'; +export * from './discordEmoji.js'; +export * from './duration.js'; +export * from './durationSeconds.js'; +export * from './globalUser.js'; +export * from './messageLink.js'; +export * from './permission.js'; +export * from './roleWithDuration.js'; +export * from './snowflake.js'; diff --git a/src/arguments/messageLink.ts b/src/arguments/messageLink.ts index d270abd..80aacde 100644 --- a/src/arguments/messageLink.ts +++ b/src/arguments/messageLink.ts @@ -1,6 +1,7 @@ +import { Message } from 'discord.js'; import { type BushArgumentTypeCaster } from '../lib'; -export const messageLink: BushArgumentTypeCaster = async (_, phrase) => { +export const messageLink: BushArgumentTypeCaster<Promise<Message | null>> = async (_, phrase) => { const match = client.consts.regex.messageLink.exec(phrase); if (!match || !match.groups) return null; diff --git a/src/arguments/permission.ts b/src/arguments/permission.ts index b5ff4bf..7a43216 100644 --- a/src/arguments/permission.ts +++ b/src/arguments/permission.ts @@ -1,7 +1,7 @@ import { type BushArgumentTypeCaster } from '#lib'; import { Permissions, PermissionString } from 'discord.js'; -export const permission: BushArgumentTypeCaster = (_, phrase): PermissionString | null => { +export const permission: BushArgumentTypeCaster<PermissionString | null> = (_, phrase) => { if (!phrase) return null; phrase = phrase.toUpperCase().replace(/ /g, '_'); if (!(phrase in Permissions.FLAGS)) { diff --git a/src/arguments/roleWithDuration.ts b/src/arguments/roleWithDuration.ts index 999ac1c..b0357dd 100644 --- a/src/arguments/roleWithDuration.ts +++ b/src/arguments/roleWithDuration.ts @@ -1,7 +1,7 @@ import { type BushArgumentTypeCaster } from '#lib'; import { Role } from 'discord.js'; -export const roleWithDuration: BushArgumentTypeCaster = async (message, phrase): Promise<RoleWithDuration | null> => { +export const roleWithDuration: BushArgumentTypeCaster<Promise<RoleWithDuration | null>> = async (message, phrase) => { // eslint-disable-next-line prefer-const let { duration, contentWithoutTime } = client.util.parseDuration(phrase); if (contentWithoutTime === null || contentWithoutTime === undefined) return null; diff --git a/src/arguments/snowflake.ts b/src/arguments/snowflake.ts index 455ed63..15896ae 100644 --- a/src/arguments/snowflake.ts +++ b/src/arguments/snowflake.ts @@ -1,7 +1,7 @@ import { type BushArgumentTypeCaster } from '#lib'; import { type Snowflake } from 'discord.js'; -export const snowflake: BushArgumentTypeCaster = (_, phrase): Snowflake | null => { +export const snowflake: BushArgumentTypeCaster<Snowflake | null> = (_, phrase) => { if (!phrase) return null; if (client.consts.regex.snowflake.test(phrase)) return phrase; return null; diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index 17bea40..b94094c 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -1,5 +1,5 @@ -import { BushCommand, ButtonPaginator, type BushMessage, type BushSlashMessage } from '#lib'; -import { MessageEmbed, type GuildMember, type PermissionString, type Role } from 'discord.js'; +import { ArgType, BushCommand, ButtonPaginator, type BushMessage, type BushSlashMessage } from '#lib'; +import { MessageEmbed } from 'discord.js'; export default class ChannelPermissionsCommand extends BushCommand { public constructor() { @@ -57,8 +57,8 @@ export default class ChannelPermissionsCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, args: { - target: Role | GuildMember; - permission: PermissionString; + target: ArgType<'member'> | ArgType<'role'>; + permission: ArgType<'permission'>; state: 'true' | 'false' | 'neutral'; } ) { diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts index 585e6cc..a946e33 100644 --- a/src/commands/admin/roleAll.ts +++ b/src/commands/admin/roleAll.ts @@ -1,5 +1,5 @@ -import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { type GuildMember, type Role } from 'discord.js'; +import { AllowedMentions, ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { type GuildMember } from 'discord.js'; export default class RoleAllCommand extends BushCommand { public constructor() { @@ -37,7 +37,7 @@ export default class RoleAllCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { role: Role; bots: boolean }) { + public override async exec(message: BushMessage | BushSlashMessage, args: { role: ArgType<'role'>; bots: boolean }) { if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); if (!message.member!.permissions.has('ADMINISTRATOR') && !message.member!.user.isOwner()) return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index a6e6a3d..d119774 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -1,5 +1,5 @@ -import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { GuildTextBasedChannel, User } from 'discord.js'; +import { AllowedMentions, ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { User } from 'discord.js'; export default class BlacklistCommand extends BushCommand { public constructor() { @@ -51,7 +51,7 @@ export default class BlacklistCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { action?: 'blacklist' | 'unblacklist'; target: GuildTextBasedChannel | User | string; global: boolean } + args: { action?: 'blacklist' | 'unblacklist'; target: ArgType<'channel'> | ArgType<'user'> | string; global: boolean } ) { let action: 'blacklist' | 'unblacklist' | 'toggle' = args.action ?? (message?.util?.parsed?.alias as 'blacklist' | 'unblacklist' | undefined) ?? 'toggle'; diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index b88147d..9377dd0 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -1,4 +1,12 @@ -import { BushCommand, guildSettingsObj, settingsArr, type BushMessage, type BushSlashMessage, type GuildSettings } from '#lib'; +import { + ArgType, + BushCommand, + guildSettingsObj, + settingsArr, + type BushMessage, + type BushSlashMessage, + type GuildSettings +} from '#lib'; import { type ArgumentOptions, type Flag } from 'discord-akairo'; import { Channel, @@ -172,7 +180,7 @@ export default class SettingsCommand extends BushCommand { subcommandGroup?: GuildSettings; action?: Action; subcommand?: Action; - value: string | Channel | Role; + value: ArgType<'channel'> | ArgType<'role'> | string; } ) { if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`); diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index 44c28d3..f6bce3a 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; export default class DisableCommand extends BushCommand { private static blacklistedCommands = ['eval', 'disable']; @@ -49,7 +49,7 @@ export default class DisableCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { action?: 'enable' | 'disable'; command: BushCommand | string; global: boolean } + args: { action?: 'enable' | 'disable'; command: ArgType<'commandAlias'> | string; global: boolean } ) { let action = (args.action ?? message?.util?.parsed?.alias ?? 'toggle') as 'disable' | 'enable' | 'toggle'; const global = args.global && message.author.isOwner(); diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts index 52cb8f5..c61a6d5 100644 --- a/src/commands/config/log.ts +++ b/src/commands/config/log.ts @@ -1,6 +1,5 @@ -import { BushCommand, guildLogsArr, type BushMessage, type BushSlashMessage, type GuildLogType } from '#lib'; +import { ArgType, BushCommand, guildLogsArr, type BushMessage, type BushSlashMessage, type GuildLogType } from '#lib'; import { type ArgumentOptions, type Flag } from 'discord-akairo'; -import { type TextChannel } from 'discord.js'; export default class LogCommand extends BushCommand { public constructor() { @@ -62,7 +61,10 @@ export default class LogCommand extends BushCommand { return { log_type, channel }; } - public override async exec(message: BushMessage | BushSlashMessage, args: { log_type: GuildLogType; channel: TextChannel }) { + public override async exec( + message: BushMessage | BushSlashMessage, + args: { log_type: GuildLogType; channel: ArgType<'textChannel'> } + ) { if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`); const currentLogs = await message.guild.getSetting('logChannels'); const oldChannel = currentLogs[args.log_type] ?? undefined; diff --git a/src/commands/dev/__template.ts b/src/commands/dev/__template.ts index 5bb29c8..4341198 100644 --- a/src/commands/dev/__template.ts +++ b/src/commands/dev/__template.ts @@ -36,6 +36,7 @@ export default class TemplateCommand extends BushCommand { userPermissions: [] }); } + public override async exec( message: BushMessage | BushSlashMessage, args: { required_argument: string; optional_argument: string } diff --git a/src/commands/dev/dm.ts b/src/commands/dev/dm.ts index 5031dfd..4133b96 100644 --- a/src/commands/dev/dm.ts +++ b/src/commands/dev/dm.ts @@ -1,4 +1,4 @@ -import { BushCommand, BushUser, type BushMessage, type BushSlashMessage } from '#lib'; +import { ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; export default class DMCommand extends BushCommand { public constructor() { @@ -11,7 +11,7 @@ export default class DMCommand extends BushCommand { args: [ { id: 'user', - type: 'string', + type: 'user', description: 'The user to send the dm to.', prompt: 'Who would you like to dm?', retry: '{error} Pick a valid user to send a dm to.', @@ -20,6 +20,7 @@ export default class DMCommand extends BushCommand { { id: 'content', type: 'string', + match: 'rest', description: 'This is the second argument.', prompt: 'What would you like to set your second argument to be?', retry: '{error} Pick a valid argument.', @@ -34,7 +35,7 @@ export default class DMCommand extends BushCommand { userPermissions: [] }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { user: BushUser; content: string }) { + public override async exec(message: BushMessage | BushSlashMessage, args: { user: ArgType<'user'>; content: string }) { try { const u = await client.users.fetch(args.user.id); await u.send(args.content); diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 2393a9b..f97f00d 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { exec } from 'child_process'; import { MessageEmbed as _MessageEmbed } from 'discord.js'; import ts from 'typescript'; @@ -119,7 +119,7 @@ export default class EvalCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, args: { - sel_depth: number; + sel_depth: ArgType<'integer'>; code: string; sudo: boolean; silent: boolean; diff --git a/src/commands/dev/javascript.ts b/src/commands/dev/javascript.ts index d832c09..2a6a87b 100644 --- a/src/commands/dev/javascript.ts +++ b/src/commands/dev/javascript.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { MessageEmbed } from 'discord.js'; import { VM } from 'vm2'; @@ -51,7 +51,7 @@ export default class JavascriptCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, args: { - sel_depth: number; + sel_depth: ArgType<'integer'>; code: string; } ) { diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts index f38419f..35e98aa 100644 --- a/src/commands/dev/superUser.ts +++ b/src/commands/dev/superUser.ts @@ -1,6 +1,5 @@ -import { BushCommand, Global, type BushMessage, type BushSlashMessage } from '#lib'; +import { ArgType, BushCommand, Global, type BushMessage, type BushSlashMessage } from '#lib'; import { type ArgumentOptions, type Flag } from 'discord-akairo'; -import { type User } from 'discord.js'; export default class SuperUserCommand extends BushCommand { public constructor() { @@ -56,7 +55,7 @@ export default class SuperUserCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - { action, user }: { action: 'add' | 'remove'; user: User } + { action, user }: { action: 'add' | 'remove'; user: ArgType<'user'> } ) { if (!message.author.isOwner()) return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); diff --git a/src/commands/fun/minesweeper.ts b/src/commands/fun/minesweeper.ts index 16352ce..0b6c89c 100644 --- a/src/commands/fun/minesweeper.ts +++ b/src/commands/fun/minesweeper.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { Minesweeper } from '@notenoughupdates/discord.js-minesweeper'; export default class MinesweeperCommand extends BushCommand { @@ -67,7 +67,13 @@ export default class MinesweeperCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { rows: number; columns: number; mines: number; spaces: boolean; reveal_first_cell: boolean } + args: { + rows: ArgType<'integer'>; + columns: ArgType<'integer'>; + mines: ArgType<'integer'>; + spaces: boolean; + reveal_first_cell: boolean; + } ) { const minesweeper = new Minesweeper({ rows: args.rows ?? 9, diff --git a/src/commands/info/avatar.ts b/src/commands/info/avatar.ts index 36504f8..3436b87 100644 --- a/src/commands/info/avatar.ts +++ b/src/commands/info/avatar.ts @@ -1,5 +1,5 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { GuildMember, MessageEmbed, type User } from 'discord.js'; +import { ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { GuildMember, MessageEmbed } from 'discord.js'; export default class AvatarCommand extends BushCommand { constructor() { @@ -27,7 +27,7 @@ export default class AvatarCommand extends BushCommand { }); } - override async exec(message: BushMessage | BushSlashMessage, args: { user: GuildMember | User }) { + override async exec(message: BushMessage | BushSlashMessage, args: { user: ArgType<'member'> | ArgType<'globalUser'> }) { const params: { size: 2048; format: 'png'; dynamic: true } = { size: 2048, format: 'png', dynamic: true }; const defaultAvatar = `https://cdn.discordapp.com/embed/avatars/${Math.ceil(Math.random() * 6) - 1}.png`; diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts index 4277d56..2f9751b 100644 --- a/src/commands/info/color.ts +++ b/src/commands/info/color.ts @@ -1,5 +1,6 @@ import { AllowedMentions, + ArgType, BushArgumentTypeCaster, BushCommand, type BushGuildMember, @@ -46,7 +47,10 @@ export default class ColorCommand extends BushCommand { return color.substring(4, color.length - 5); } - public override async exec(message: BushMessage | BushSlashMessage, args: { color: string | BushRole | BushGuildMember }) { + public override async exec( + message: BushMessage | BushSlashMessage, + args: { color: string | ArgType<'role'> | ArgType<'member'> } + ) { const _color = message.util.isSlashMessage(message) ? ((await util.arg.cast(util.arg.union(isValidTinyColor as any, 'role', 'member'), message, args.color as string)) as | string diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index ab09741..67150f6 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { Constants, Gu |
