diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-08-28 21:51:17 -0400 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-08-28 21:51:17 -0400 |
| commit | 14eb0e617b084080c4cffc5b781b311c65c5f928 (patch) | |
| tree | 9aaf1734c1e739814a913afeda40c56b0f84df61 /lib | |
| parent | 03b26d5f00422f3aaddce3db2186765863b1eca0 (diff) | |
| download | tanzanite-14eb0e617b084080c4cffc5b781b311c65c5f928.tar.gz tanzanite-14eb0e617b084080c4cffc5b781b311c65c5f928.tar.bz2 tanzanite-14eb0e617b084080c4cffc5b781b311c65c5f928.zip | |
rebrand v3
Diffstat (limited to 'lib')
50 files changed, 556 insertions, 530 deletions
diff --git a/lib/arguments/abbreviatedNumber.ts b/lib/arguments/abbreviatedNumber.ts index a7d8ce5..5fe39b5 100644 --- a/lib/arguments/abbreviatedNumber.ts +++ b/lib/arguments/abbreviatedNumber.ts @@ -1,9 +1,9 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import type { BotArgumentTypeCaster } from '#lib'; import assert from 'assert/strict'; import numeral from 'numeral'; assert(typeof numeral === 'function'); -export const abbreviatedNumber: BushArgumentTypeCaster<number | null> = (_, phrase) => { +export const abbreviatedNumber: BotArgumentTypeCaster<number | null> = (_, phrase) => { if (!phrase) return null; const num = numeral(phrase?.toLowerCase()).value(); diff --git a/lib/arguments/contentWithDuration.ts b/lib/arguments/contentWithDuration.ts index 0efba39..ec015dc 100644 --- a/lib/arguments/contentWithDuration.ts +++ b/lib/arguments/contentWithDuration.ts @@ -1,5 +1,5 @@ -import { parseDuration, type BushArgumentTypeCaster, type ParsedDuration } from '#lib'; +import { parseDuration, type BotArgumentTypeCaster, type ParsedDuration } from '#lib'; -export const contentWithDuration: BushArgumentTypeCaster<Promise<ParsedDuration>> = async (_, phrase) => { +export const contentWithDuration: BotArgumentTypeCaster<Promise<ParsedDuration>> = async (_, phrase) => { return parseDuration(phrase); }; diff --git a/lib/arguments/discordEmoji.ts b/lib/arguments/discordEmoji.ts index 92d6502..0a0d168 100644 --- a/lib/arguments/discordEmoji.ts +++ b/lib/arguments/discordEmoji.ts @@ -1,7 +1,7 @@ -import { regex, type BushArgumentTypeCaster } from '#lib'; +import { regex, type BotArgumentTypeCaster } from '#lib'; import type { Snowflake } from 'discord.js'; -export const discordEmoji: BushArgumentTypeCaster<DiscordEmojiInfo | null> = (_, phrase) => { +export const discordEmoji: BotArgumentTypeCaster<DiscordEmojiInfo | null> = (_, phrase) => { if (!phrase) return null; const validEmoji: RegExpExecArray | null = regex.discordEmoji.exec(phrase); if (!validEmoji || !validEmoji.groups) return null; diff --git a/lib/arguments/duration.ts b/lib/arguments/duration.ts index 09dd3d5..4952dc4 100644 --- a/lib/arguments/duration.ts +++ b/lib/arguments/duration.ts @@ -1,5 +1,5 @@ -import { parseDuration, type BushArgumentTypeCaster } from '#lib'; +import { parseDuration, type BotArgumentTypeCaster } from '#lib'; -export const duration: BushArgumentTypeCaster<number | null> = (_, phrase) => { +export const duration: BotArgumentTypeCaster<number | null> = (_, phrase) => { return parseDuration(phrase).duration; }; diff --git a/lib/arguments/durationSeconds.ts b/lib/arguments/durationSeconds.ts index d8d6749..8deee5b 100644 --- a/lib/arguments/durationSeconds.ts +++ b/lib/arguments/durationSeconds.ts @@ -1,6 +1,6 @@ -import { parseDuration, type BushArgumentTypeCaster } from '#lib'; +import { parseDuration, type BotArgumentTypeCaster } from '#lib'; -export const durationSeconds: BushArgumentTypeCaster<number | null> = (_, phrase) => { +export const durationSeconds: BotArgumentTypeCaster<number | null> = (_, phrase) => { phrase += 's'; return parseDuration(phrase).duration; }; diff --git a/lib/arguments/globalUser.ts b/lib/arguments/globalUser.ts index 4324aa9..4198e3c 100644 --- a/lib/arguments/globalUser.ts +++ b/lib/arguments/globalUser.ts @@ -1,7 +1,7 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import type { BotArgumentTypeCaster } from '#lib'; import type { User } from 'discord.js'; // resolve non-cached users -export const globalUser: BushArgumentTypeCaster<Promise<User | null>> = async (message, phrase) => { +export const globalUser: BotArgumentTypeCaster<Promise<User | null>> = async (message, phrase) => { return message.client.users.resolve(phrase) ?? (await message.client.users.fetch(`${phrase}`).catch(() => null)); }; diff --git a/lib/arguments/messageLink.ts b/lib/arguments/messageLink.ts index c95e42d..ffb48a0 100644 --- a/lib/arguments/messageLink.ts +++ b/lib/arguments/messageLink.ts @@ -1,7 +1,7 @@ -import { BushArgumentTypeCaster, regex } from '#lib'; +import { BotArgumentTypeCaster, regex } from '#lib'; import type { Message } from 'discord.js'; -export const messageLink: BushArgumentTypeCaster<Promise<Message | null>> = async (message, phrase) => { +export const messageLink: BotArgumentTypeCaster<Promise<Message | null>> = async (message, phrase) => { const match = new RegExp(regex.messageLink).exec(phrase); if (!match || !match.groups) return null; diff --git a/lib/arguments/permission.ts b/lib/arguments/permission.ts index 98bfe74..4d09e9c 100644 --- a/lib/arguments/permission.ts +++ b/lib/arguments/permission.ts @@ -1,7 +1,7 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import type { BotArgumentTypeCaster } from '#lib'; import { PermissionFlagsBits, type PermissionsString } from 'discord.js'; -export const permission: BushArgumentTypeCaster<PermissionsString | null> = (_, phrase) => { +export const permission: BotArgumentTypeCaster<PermissionsString | null> = (_, phrase) => { if (!phrase) return null; phrase = phrase.toUpperCase().replace(/ /g, '_'); if (!(phrase in PermissionFlagsBits)) { diff --git a/lib/arguments/roleWithDuration.ts b/lib/arguments/roleWithDuration.ts index b97f205..9391c75 100644 --- a/lib/arguments/roleWithDuration.ts +++ b/lib/arguments/roleWithDuration.ts @@ -1,7 +1,7 @@ -import { Arg, BushArgumentTypeCaster, parseDuration } from '#lib'; +import { Arg, BotArgumentTypeCaster, parseDuration } from '#lib'; import type { Role } from 'discord.js'; -export const roleWithDuration: BushArgumentTypeCaster<Promise<RoleWithDuration | null>> = async (message, phrase) => { +export const roleWithDuration: BotArgumentTypeCaster<Promise<RoleWithDuration | null>> = async (message, phrase) => { // eslint-disable-next-line prefer-const let { duration, content } = parseDuration(phrase); if (content === null || content === undefined) return null; diff --git a/lib/arguments/snowflake.ts b/lib/arguments/snowflake.ts index b98a20f..ab0c7fc 100644 --- a/lib/arguments/snowflake.ts +++ b/lib/arguments/snowflake.ts @@ -1,7 +1,7 @@ -import { BushArgumentTypeCaster, regex } from '#lib'; +import { BotArgumentTypeCaster, regex } from '#lib'; import type { Snowflake } from 'discord.js'; -export const snowflake: BushArgumentTypeCaster<Snowflake | null> = (_, phrase) => { +export const snowflake: BotArgumentTypeCaster<Snowflake | null> = (_, phrase) => { if (!phrase) return null; if (regex.snowflake.test(phrase)) return phrase; return null; diff --git a/lib/arguments/tinyColor.ts b/lib/arguments/tinyColor.ts index 148c078..2eb6ab2 100644 --- a/lib/arguments/tinyColor.ts +++ b/lib/arguments/tinyColor.ts @@ -1,9 +1,9 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import type { BotArgumentTypeCaster } from '#lib'; import assert from 'assert/strict'; import tinycolorModule from 'tinycolor2'; assert(tinycolorModule); -export const tinyColor: BushArgumentTypeCaster<string | null> = (_message, phrase) => { +export const tinyColor: BotArgumentTypeCaster<string | null> = (_message, phrase) => { // if the phase is a number it converts it to hex incase it could be representing a color in decimal const newPhase = isNaN(phrase as any) ? phrase : `#${Number(phrase).toString(16)}`; return tinycolorModule(newPhase).isValid() ? newPhase : null; diff --git a/lib/automod/AutomodShared.ts b/lib/automod/AutomodShared.ts index 9cdb020..29b0536 100644 --- a/lib/automod/AutomodShared.ts +++ b/lib/automod/AutomodShared.ts @@ -1,6 +1,6 @@ import * as Moderation from '#lib/common/Moderation.js'; import { unmuteResponse } from '#lib/extensions/discord.js/ExtendedGuildMember.js'; -import { colors, emojis } from '#lib/utils/BushConstants.js'; +import { colors, emojis } from '#lib/utils/Constants.js'; import * as Format from '#lib/utils/Format.js'; import { formatUnmuteResponse } from '#lib/utils/FormatResponse.js'; import { @@ -165,7 +165,7 @@ export async function handleAutomodInteraction(interaction: ButtonInteraction) { const check = victim ? await Moderation.permissionCheck(moderator, victim, 'ban', true) : true; if (check !== true) return interaction.reply({ content: check, ephemeral: true }); - const result = await interaction.guild?.bushBan({ + const result = await interaction.guild?.customBan({ user: userId, reason, moderator: interaction.user.id, @@ -209,7 +209,7 @@ export async function handleAutomodInteraction(interaction: ButtonInteraction) { const check2 = await Moderation.checkMutePermissions(interaction.guild); if (check2 !== true) return interaction.reply({ content: formatUnmuteResponse('/', victim!, check2), ephemeral: true }); - const result = await victim.bushUnmute({ + const result = await victim.customUnmute({ reason, moderator: interaction.member as GuildMember, evidence: (interaction.message as Message).url ?? undefined diff --git a/lib/automod/MessageAutomod.ts b/lib/automod/MessageAutomod.ts index 0abd34c..0b6ebba 100644 --- a/lib/automod/MessageAutomod.ts +++ b/lib/automod/MessageAutomod.ts @@ -2,8 +2,8 @@ import { stripIndent } from '#tags'; import assert from 'assert/strict'; import chalk from 'chalk'; import { EmbedBuilder, GuildTextBasedChannel, PermissionFlagsBits, type Message } from 'discord.js'; -import { colors } from '../utils/BushConstants.js'; -import { format, formatError } from '../utils/BushUtils.js'; +import { colors } from '../utils/Constants.js'; +import { format, formatError } from '../utils/Utils.js'; import { Automod, BadWordDetails, Severity } from './AutomodShared.js'; /** @@ -202,7 +202,7 @@ export class MessageAutomod extends Automod { } case Severity.WARN: { void this.message.delete().catch((e) => deleteError.bind(this, e)); - void this.member.bushWarn({ + void this.member.customWarn({ moderator: this.guild!.members.me!, reason: `[Automod] ${highestOffense.reason}` }); @@ -211,7 +211,7 @@ export class MessageAutomod extends Automod { } case Severity.TEMP_MUTE: { void this.message.delete().catch((e) => deleteError.bind(this, e)); - void this.member.bushMute({ + void this.member.customMute({ moderator: this.guild!.members.me!, reason: `[Automod] ${highestOffense.reason}`, duration: 900_000 // 15 minutes @@ -221,7 +221,7 @@ export class MessageAutomod extends Automod { } case Severity.PERM_MUTE: { void this.message.delete().catch((e) => deleteError.bind(this, e)); - void this.member.bushMute({ + void this.member.customMute({ moderator: this.guild!.members.me!, reason: `[Automod] ${highestOffense.reason}`, duration: 0 // permanent diff --git a/lib/common/BushCache.ts b/lib/common/BotCache.ts index 22a13ef..e91d9e5 100644 --- a/lib/common/BushCache.ts +++ b/lib/common/BotCache.ts @@ -1,7 +1,7 @@ import { BadWords, GlobalModel, SharedModel, type Guild } from '#lib'; import { Collection, type Snowflake } from 'discord.js'; -export class BushCache { +export class BotCache { public global = new GlobalCache(); public shared = new SharedCache(); public guilds = new GuildCache(); diff --git a/lib/common/HighlightManager.ts b/lib/common/HighlightManager.ts index cc31413..ca71a83 100644 --- a/lib/common/HighlightManager.ts +++ b/lib/common/HighlightManager.ts @@ -10,7 +10,7 @@ import { type Snowflake, type TextBasedChannel } from 'discord.js'; -import { colors, Time } from '../utils/BushConstants.js'; +import { colors, Time } from '../utils/Constants.js'; import { sanitizeInputForDiscord } from '../utils/Format.js'; const NOTIFY_COOLDOWN = 5 * Time.Minute; diff --git a/lib/extensions/discord-akairo/BotArgumentTypeCaster.ts b/lib/extensions/discord-akairo/BotArgumentTypeCaster.ts new file mode 100644 index 0000000..5f4f32f --- /dev/null +++ b/lib/extensions/discord-akairo/BotArgumentTypeCaster.ts @@ -0,0 +1,3 @@ +import { type CommandMessage } from '#lib'; + +export type BotArgumentTypeCaster<R = unknown> = (message: CommandMessage, phrase: string) => R; diff --git a/lib/extensions/discord-akairo/BushCommand.ts b/lib/extensions/discord-akairo/BotCommand.ts index 7201248..abd945e 100644 --- a/lib/extensions/discord-akairo/BushCommand.ts +++ b/lib/extensions/discord-akairo/BotCommand.ts @@ -1,12 +1,12 @@ import { type DiscordEmojiInfo, type RoleWithDuration } from '#args'; import { - type BushArgumentTypeCaster, - type BushClient, - type BushCommandHandler, - type BushInhibitor, - type BushListener, - type BushTask, - type ParsedDuration + type BotArgumentTypeCaster, + type BotCommandHandler, + type BotInhibitor, + type BotListener, + type BotTask, + type ParsedDuration, + type TanzaniteClient } from '#lib'; import { ArgumentMatch, @@ -45,15 +45,15 @@ import _ from 'lodash'; import { SlashMessage } from './SlashMessage.js'; export interface OverriddenBaseArgumentType extends BaseArgumentType { - commandAlias: BushCommand | null; - command: BushCommand | null; - inhibitor: BushInhibitor | null; - listener: BushListener | null; - task: BushTask | null; + commandAlias: BotCommand | null; + command: BotCommand | null; + inhibitor: BotInhibitor | null; + listener: BotListener | null; + task: BotTask | null; contextMenuCommand: ContextMenuCommand | null; } -export interface BaseBushArgumentType extends OverriddenBaseArgumentType { +export interface BaseBotArgumentType extends OverriddenBaseArgumentType { duration: number | null; contentWithDuration: ParsedDuration; permission: PermissionsString | null; @@ -67,9 +67,9 @@ export interface BaseBushArgumentType extends OverriddenBaseArgumentType { tinyColor: string | null; } -export type BushArgumentType = keyof BaseBushArgumentType | RegExp; +export type BotArgumentType = keyof BaseBotArgumentType | RegExp; -interface BaseBushArgumentOptions extends Omit<ArgumentOptions, 'type' | 'prompt'>, ExtraArgumentOptions { +interface BaseBotArgumentOptions extends Omit<ArgumentOptions, 'type' | 'prompt'>, ExtraArgumentOptions { id: string; description: string; @@ -150,7 +150,7 @@ interface ExtraArgumentOptions { superUserOnly?: boolean; } -export interface BushArgumentOptions extends BaseBushArgumentOptions { +export interface BotArgumentOptions extends BaseBotArgumentOptions { /** * The type that the argument should be cast to. * - `string` does not cast to any type. @@ -199,10 +199,10 @@ export interface BushArgumentOptions extends BaseBushArgumentOptions { * - `contentWithDuration` tries to parse duration in milliseconds and returns the remaining content with the duration * removed */ - type?: BushArgumentType | (keyof BaseBushArgumentType)[] | BushArgumentTypeCaster; + type?: BotArgumentType | (keyof BaseBotArgumentType)[] | BotArgumentTypeCaster; } -export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { +export interface CustomBotArgumentOptions extends BaseBotArgumentOptions { /** * An array of strings can be used to restrict input to only those strings, case insensitive. * The array can also contain an inner array of strings, for aliases. @@ -214,7 +214,7 @@ export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { customType?: (string | string[])[] | RegExp | string | null; } -export type BushMissingPermissionSupplier = (message: CommandMessage | SlashMessage) => Promise<any> | any; +export type CustomMissingPermissionSupplier = (message: CommandMessage | SlashMessage) => Promise<any> | any; interface ExtendedCommandOptions { /** @@ -253,7 +253,7 @@ interface ExtendedCommandOptions { bypassChannelBlacklist?: boolean; /** - * Use instead of {@link BaseBushCommandOptions.args} when using argument generators or custom slashOptions + * Use instead of {@link BaseBotCommandOptions.args} when using argument generators or custom slashOptions */ helpArgs?: ArgsInfo[]; @@ -263,7 +263,7 @@ interface ExtendedCommandOptions { note?: string; } -export interface BaseBushCommandOptions +export interface BaseBotCommandOptions extends Omit<CommandOptions, 'userPermissions' | 'clientPermissions' | 'args'>, ExtendedCommandOptions { /** @@ -274,19 +274,19 @@ export interface BaseBushCommandOptions /** * The arguments for the command. */ - args?: BushArgumentOptions[] & CustomBushArgumentOptions[]; + args?: BotArgumentOptions[] & CustomBotArgumentOptions[]; category: string; /** * Permissions required by the client to run this command. */ - clientPermissions: bigint | bigint[] | BushMissingPermissionSupplier; + clientPermissions: bigint | bigint[] | CustomMissingPermissionSupplier; /** * Permissions required by the user to run this command. */ - userPermissions: bigint | bigint[] | BushMissingPermissionSupplier; + userPermissions: bigint | bigint[] | CustomMissingPermissionSupplier; /** * Whether the argument is only accessible to the owners. @@ -299,7 +299,7 @@ export interface BaseBushCommandOptions superUserOnly?: boolean; } -export type BushCommandOptions = Omit<BaseBushCommandOptions, 'helpArgs'> | Omit<BaseBushCommandOptions, 'args'>; +export type CustomCommandOptions = Omit<BaseBotCommandOptions, 'helpArgs'> | Omit<BaseBotCommandOptions, 'args'>; export interface ArgsInfo { /** @@ -360,9 +360,9 @@ export interface ArgsInfo { superUserOnly?: boolean; } -export abstract class BushCommand extends Command { - public declare client: BushClient; - public declare handler: BushCommandHandler; +export abstract class BotCommand extends Command { + public declare client: TanzaniteClient; + public declare handler: BotCommandHandler; public declare description: string; /** @@ -378,7 +378,7 @@ export abstract class BushCommand extends Command { /** * The options sent to the constructor */ - public options: BushCommandOptions; + public options: CustomCommandOptions; /** * The options sent to the super call @@ -420,8 +420,8 @@ export abstract class BushCommand extends Command { */ public note?: string; - public constructor(id: string, options: BushCommandOptions) { - const options_ = options as BaseBushCommandOptions; + public constructor(id: string, options: CustomCommandOptions) { + const options_ = options as BaseBotCommandOptions; if (options_.args && typeof options_.args !== 'function') { options_.args.forEach((_, index: number) => { @@ -512,8 +512,8 @@ export abstract class BushCommand extends Command { const argsInfo: ArgsInfo[] = []; const combined = (options_.args ?? options_.helpArgs)!.map((arg) => { const norm = options_.args - ? options_.args.find((_arg) => _arg.id === ('id' in arg ? arg.id : arg.name)) ?? ({} as BushArgumentOptions) - : ({} as BushArgumentOptions); + ? options_.args.find((_arg) => _arg.id === ('id' in arg ? arg.id : arg.name)) ?? ({} as BotArgumentOptions) + : ({} as BotArgumentOptions); const help = options_.helpArgs ? options_.helpArgs.find((_arg) => _arg.name === ('id' in arg ? arg.id : arg.name)) ?? ({} as ArgsInfo) : ({} as ArgsInfo); @@ -574,7 +574,7 @@ type SlashOptionKeys = | keyof AkairoApplicationCommandNumericOptionData | keyof AkairoApplicationCommandSubCommandData; -interface PseudoArguments extends BaseBushArgumentType { +interface PseudoArguments extends BaseBotArgumentType { boolean: boolean; flag: boolean; regex: { match: RegExpMatchArray; matches: RegExpExecArray[] }; diff --git a/lib/extensions/discord-akairo/BotCommandHandler.ts b/lib/extensions/discord-akairo/BotCommandHandler.ts new file mode 100644 index 0000000..8a4fe60 --- /dev/null +++ b/lib/extensions/discord-akairo/BotCommandHandler.ts @@ -0,0 +1,37 @@ +import { type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { CommandHandler, type Category, type CommandHandlerEvents, type CommandHandlerOptions } from 'discord-akairo'; +import { type Collection, type Message, type PermissionsString } from 'discord.js'; + +export type CustomCommandHandlerOptions = CommandHandlerOptions; + +export interface BotCommandHandlerEvents extends CommandHandlerEvents { + commandBlocked: [message: CommandMessage, command: BotCommand, reason: string]; + commandBreakout: [message: CommandMessage, command: BotCommand, /* no util */ breakMessage: Message]; + commandCancelled: [message: CommandMessage, command: BotCommand, /* no util */ retryMessage?: Message]; + commandFinished: [message: CommandMessage, command: BotCommand, args: any, returnValue: any]; + commandInvalid: [message: CommandMessage, command: BotCommand]; + commandLocked: [message: CommandMessage, command: BotCommand]; + commandStarted: [message: CommandMessage, command: BotCommand, args: any]; + cooldown: [message: CommandMessage | SlashMessage, command: BotCommand, remaining: number]; + error: [error: Error, message: /* no util */ Message, command?: BotCommand]; + inPrompt: [message: /* no util */ Message]; + load: [command: BotCommand, isReload: boolean]; + messageBlocked: [message: /* no util */ Message | CommandMessage | SlashMessage, reason: string]; + messageInvalid: [message: CommandMessage]; + missingPermissions: [message: CommandMessage, command: BotCommand, type: 'client' | 'user', missing: PermissionsString[]]; + remove: [command: BotCommand]; + slashBlocked: [message: SlashMessage, command: BotCommand, reason: string]; + slashError: [error: Error, message: SlashMessage, command: BotCommand]; + slashFinished: [message: SlashMessage, command: BotCommand, args: any, returnValue: any]; + slashMissingPermissions: [message: SlashMessage, command: BotCommand, type: 'client' | 'user', missing: PermissionsString[]]; + slashStarted: [message: SlashMessage, command: BotCommand, args: any]; +} + +export class BotCommandHandler extends CommandHandler { + public declare modules: Collection<string, BotCommand>; + public declare categories: Collection<string, Category<string, BotCommand>>; +} + +export interface BotCommandHandler extends CommandHandler { + findCommand(name: string): BotCommand; +} |
