diff options
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; +} diff --git a/lib/extensions/discord-akairo/BushInhibitor.ts b/lib/extensions/discord-akairo/BotInhibitor.ts index be396cf..d134eab 100644 --- a/lib/extensions/discord-akairo/BushInhibitor.ts +++ b/lib/extensions/discord-akairo/BotInhibitor.ts @@ -1,9 +1,8 @@ -import { type BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; import { Inhibitor } from 'discord-akairo'; -// eslint-disable-next-line @typescript-eslint/no-unused-vars import { Message } from 'discord.js'; -export abstract class BushInhibitor extends Inhibitor { +export abstract class BotInhibitor extends Inhibitor { /** * Checks if message should be blocked. * A return value of true will block the message. @@ -14,6 +13,6 @@ export abstract class BushInhibitor extends Inhibitor { * @param message - Message being handled. * @param command - Command to check. */ - public abstract override exec(message: CommandMessage, command: BushCommand): any; - public abstract override exec(message: CommandMessage | SlashMessage, command: BushCommand): any; + public abstract override exec(message: CommandMessage, command: BotCommand): any; + public abstract override exec(message: CommandMessage | SlashMessage, command: BotCommand): any; } diff --git a/lib/extensions/discord-akairo/BotInhibitorHandler.ts b/lib/extensions/discord-akairo/BotInhibitorHandler.ts new file mode 100644 index 0000000..c6f318d --- /dev/null +++ b/lib/extensions/discord-akairo/BotInhibitorHandler.ts @@ -0,0 +1,3 @@ +import { InhibitorHandler } from 'discord-akairo'; + +export class BotInhibitorHandler extends InhibitorHandler {} diff --git a/lib/extensions/discord-akairo/BotListener.ts b/lib/extensions/discord-akairo/BotListener.ts new file mode 100644 index 0000000..f4bfd6c --- /dev/null +++ b/lib/extensions/discord-akairo/BotListener.ts @@ -0,0 +1,3 @@ +import { Listener } from 'discord-akairo'; + +export abstract class BotListener extends Listener {} diff --git a/lib/extensions/discord-akairo/BotListenerHandler.ts b/lib/extensions/discord-akairo/BotListenerHandler.ts new file mode 100644 index 0000000..9b3b525 --- /dev/null +++ b/lib/extensions/discord-akairo/BotListenerHandler.ts @@ -0,0 +1,3 @@ +import { ListenerHandler } from 'discord-akairo'; + +export class BotListenerHandler extends ListenerHandler {} diff --git a/lib/extensions/discord-akairo/BotTask.ts b/lib/extensions/discord-akairo/BotTask.ts new file mode 100644 index 0000000..09b30ed --- /dev/null +++ b/lib/extensions/discord-akairo/BotTask.ts @@ -0,0 +1,3 @@ +import { Task } from 'discord-akairo'; + +export abstract class BotTask extends Task {} diff --git a/lib/extensions/discord-akairo/BotTaskHandler.ts b/lib/extensions/discord-akairo/BotTaskHandler.ts new file mode 100644 index 0000000..b522f2c --- /dev/null +++ b/lib/extensions/discord-akairo/BotTaskHandler.ts @@ -0,0 +1,3 @@ +import { TaskHandler } from 'discord-akairo'; + +export class BotTaskHandler extends TaskHandler {} diff --git a/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts b/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts deleted file mode 100644 index def7ad6..0000000 --- a/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { type CommandMessage } from '#lib'; - -export type BushArgumentTypeCaster<R = unknown> = (message: CommandMessage, phrase: string) => R; diff --git a/lib/extensions/discord-akairo/BushCommandHandler.ts b/lib/extensions/discord-akairo/BushCommandHandler.ts deleted file mode 100644 index da49af9..0000000 --- a/lib/extensions/discord-akairo/BushCommandHandler.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { type BushCommand, 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 BushCommandHandlerOptions = CommandHandlerOptions; - -export interface BushCommandHandlerEvents extends CommandHandlerEvents { - commandBlocked: [message: CommandMessage, command: BushCommand, reason: string]; - commandBreakout: [message: CommandMessage, command: BushCommand, /* no util */ breakMessage: Message]; - commandCancelled: [message: CommandMessage, command: BushCommand, /* no util */ retryMessage?: Message]; - commandFinished: [message: CommandMessage, command: BushCommand, args: any, returnValue: any]; - commandInvalid: [message: CommandMessage, command: BushCommand]; - commandLocked: [message: CommandMessage, command: BushCommand]; - commandStarted: [message: CommandMessage, command: BushCommand, args: any]; - cooldown: [message: CommandMessage | SlashMessage, command: BushCommand, remaining: number]; - error: [error: Error, message: /* no util */ Message, command?: BushCommand]; - inPrompt: [message: /* no util */ Message]; - load: [command: BushCommand, isReload: boolean]; - messageBlocked: [message: /* no util */ Message | CommandMessage | SlashMessage, reason: string]; - messageInvalid: [message: CommandMessage]; - missingPermissions: [message: CommandMessage, command: BushCommand, type: 'client' | 'user', missing: PermissionsString[]]; - remove: [command: BushCommand]; - slashBlocked: [message: SlashMessage, command: BushCommand, reason: string]; - slashError: [error: Error, message: SlashMessage, command: BushCommand]; - slashFinished: [message: SlashMessage, command: BushCommand, args: any, returnValue: any]; - slashMissingPermissions: [message: SlashMessage, command: BushCommand, type: 'client' | 'user', missing: PermissionsString[]]; - slashStarted: [message: SlashMessage, command: BushCommand, args: any]; -} - -export class BushCommandHandler extends CommandHandler { - public declare modules: Collection<string, BushCommand>; - public declare categories: Collection<string, Category<string, BushCommand>>; -} - -export interface BushCommandHandler extends CommandHandler { - findCommand(name: string): BushCommand; -} diff --git a/lib/extensions/discord-akairo/BushInhibitorHandler.ts b/lib/extensions/discord-akairo/BushInhibitorHandler.ts deleted file mode 100644 index 5e4fb6c..0000000 --- a/lib/extensions/discord-akairo/BushInhibitorHandler.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { InhibitorHandler } from 'discord-akairo'; - -export class BushInhibitorHandler extends InhibitorHandler {} diff --git a/lib/extensions/discord-akairo/BushListener.ts b/lib/extensions/discord-akairo/BushListener.ts deleted file mode 100644 index 6917641..0000000 --- a/lib/extensions/discord-akairo/BushListener.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Listener } from 'discord-akairo'; - -export abstract class BushListener extends Listener {} diff --git a/lib/extensions/discord-akairo/BushListenerHandler.ts b/lib/extensions/discord-akairo/BushListenerHandler.ts deleted file mode 100644 index 9c3e4af..0000000 --- a/lib/extensions/discord-akairo/BushListenerHandler.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ListenerHandler } from 'discord-akairo'; - -export class BushListenerHandler extends ListenerHandler {} diff --git a/lib/extensions/discord-akairo/BushTask.ts b/lib/extensions/discord-akairo/BushTask.ts deleted file mode 100644 index 1b70c88..0000000 --- a/lib/extensions/discord-akairo/BushTask.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Task } from 'discord-akairo'; - -export abstract class BushTask extends Task {} diff --git a/lib/extensions/discord-akairo/BushTaskHandler.ts b/lib/extensions/discord-akairo/BushTaskHandler.ts deleted file mode 100644 index 6535abb..0000000 --- a/lib/extensions/discord-akairo/BushTaskHandler.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { TaskHandler } from 'discord-akairo'; - -export class BushTaskHandler extends TaskHandler {} diff --git a/lib/extensions/discord-akairo/BushClient.ts b/lib/extensions/discord-akairo/TanzaniteClient.ts index b311ffd..24ce962 100644 --- a/lib/extensions/discord-akairo/BushClient.ts +++ b/lib/extensions/discord-akairo/TanzaniteClient.ts @@ -11,7 +11,7 @@ import { snowflake } from '#args'; import type { Config } from '#config'; -import { BushClientEvents, emojis, formatError, inspect, updateEveryCache } from '#lib'; +import { BotClientEvents, emojis, formatError, inspect, updateEveryCache } from '#lib'; import { patch, type PatchedElements } from '@notenoughupdates/events-intercept'; import * as Sentry from '@sentry/node'; import { @@ -32,14 +32,10 @@ import { version as discordJsVersion, type Awaitable, type If, - type InteractionReplyOptions, type Message, - type MessageEditOptions, type MessageOptions, - type ReplyMessageOptions, type Snowflake, - type UserResolvable, - type WebhookEditMessageOptions + type UserResolvable } from 'discord.js'; import type EventEmitter from 'events'; import { google } from 'googleapis'; @@ -48,7 +44,7 @@ import readline from 'readline'; import { Options as SequelizeOptions, Sequelize, Sequelize as SequelizeType } from 'sequelize'; import { fileURLToPath } from 'url'; import { tinyColor } from '../../arguments/tinyColor.js'; -import { BushCache } from '../../common/BushCache.js'; +import { BotCache } from '../../common/BotCache.js'; import { HighlightManager } from '../../common/HighlightManager.js'; import { ActivePunishment, @@ -65,16 +61,16 @@ import { StickyRole } from '../../models/index.js'; import { AllowedMentions } from '../../utils/AllowedMentions.js'; -import { BushClientUtils } from '../../utils/BushClientUtils.js'; -import { BushLogger } from '../../utils/BushLogger.js'; +import { BotClientUtils } from '../../utils/BotClientUtils.js'; +import { Logger } from '../../utils/Logger.js'; import { ExtendedGuild } from '../discord.js/ExtendedGuild.js'; import { ExtendedGuildMember } from '../discord.js/ExtendedGuildMember.js'; import { ExtendedMessage } from '../discord.js/ExtendedMessage.js'; import { ExtendedUser } from '../discord.js/ExtendedUser.js'; -import { BushCommandHandler } from './BushCommandHandler.js'; -import { BushInhibitorHandler } from './BushInhibitorHandler.js'; -import { BushListenerHandler } from './BushListenerHandler.js'; -import { BushTaskHandler } from './BushTaskHandler.js'; +import { BotCommandHandler } from './BotCommandHandler.js'; +import { BotInhibitorHandler } from './BotInhibitorHandler.js'; +import { BotListenerHandler } from './BotListenerHandler.js'; +import { BotTaskHandler } from './BotTaskHandler.js'; declare module 'discord.js' { export interface Client extends EventEmitter { @@ -87,15 +83,15 @@ declare module 'discord.js' { /** The configuration for the client. */ readonly config: Config; /** Stats for the client. */ - readonly stats: BushStats; + readonly stats: BotStats; /** The handler for the bot's listeners. */ - readonly listenerHandler: BushListenerHandler; + readonly listenerHandler: BotListenerHandler; /** The handler for the bot's command inhibitors. */ - readonly inhibitorHandler: BushInhibitorHandler; + readonly inhibitorHandler: BotInhibitorHandler; /** The handler for the bot's commands. */ - readonly commandHandler: BushCommandHandler; + readonly commandHandler: BotCommandHandler; /** The handler for the bot's tasks. */ - readonly taskHandler: BushTaskHandler; + readonly taskHandler: BotTaskHandler; /** The handler for the bot's context menu commands. */ readonly contextMenuCommandHandler: ContextMenuCommandHandler; /** The database connection for this instance of the bot (production, beta, or development). */ @@ -103,9 +99,9 @@ declare module 'discord.js' { /** The database connection that is shared between all instances of the bot. */ readonly sharedDB: SequelizeType; /** A custom logging system for the bot. */ - readonly logger: BushLogger; + readonly logger: Logger; /** Cached global and guild database data. */ - readonly cache: BushCache; + readonly cache: BotCache; /** Sentry error reporting for the bot. */ readonly sentry: typeof Sentry; /** Manages most aspects of the highlight command */ @@ -113,14 +109,14 @@ declare module 'discord.js' { /** The perspective api */ perspective: any; /** Client utilities. */ - readonly utils: BushClientUtils; + readonly utils: BotClientUtils; /** A custom logging system for the bot. */ - get console(): BushLogger; - on<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; - once<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; - emit<K extends keyof BushClientEvents>(event: K, ...args: BushClientEvents[K]): boolean; - off<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; - removeAllListeners<K extends keyof BushClientEvents>(event?: K): this; + get console(): Logger; + on<K extends keyof BotClientEvents>(event: K, listener: (...args: BotClientEvents[K]) => Awaitable<void>): this; + once<K extends keyof BotClientEvents>(event: K, listener: (...args: BotClientEvents[K]) => Awaitable<void>): this; + emit<K extends keyof BotClientEvents>(event: K, ...args: BotClientEvents[K]): boolean; + off<K extends keyof BotClientEvents>(event: K, listener: (...args: BotClientEvents[K]) => Awaitable<void>): this; + removeAllListeners<K extends keyof BotClientEvents>(event?: K): this; /** * Checks if a user is the owner of this bot. * @param user - User to check. @@ -134,12 +130,6 @@ declare module 'discord.js' { } } -export type ReplyMessageType = string | MessagePayload | ReplyMessageOptions; -export type EditMessageType = string | MessageEditOptions | MessagePayload; -export type SlashSendMessageType = string | MessagePayload | InteractionReplyOptions; -export type SlashEditMessageType = string | MessagePayload | WebhookEditMessageOptions; -export type SendMessageType = string | MessagePayload | MessageOptions; - const rl = readline.createInterface({ input: process.stdin, output: process.stdout, @@ -151,7 +141,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); /** * The main hub for interacting with the Discord API. */ -export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Ready> { +export class TanzaniteClient<Ready extends boolean = boolean> extends AkairoClient<Ready> { public declare ownerID: Snowflake[]; public declare superUserID: Snowflake[]; @@ -163,27 +153,27 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * Stats for the client. */ - public override readonly stats: BushStats = { cpu: undefined, commandsUsed: 0n, slashCommandsUsed: 0n }; + public override readonly stats: BotStats = { cpu: undefined, commandsUsed: 0n, slashCommandsUsed: 0n }; /** * The handler for the bot's listeners. */ - public override readonly listenerHandler: BushListenerHandler; + public override readonly listenerHandler: BotListenerHandler; /** * The handler for the bot's command inhibitors. */ - public override readonly inhibitorHandler: BushInhibitorHandler; + public override readonly inhibitorHandler: BotInhibitorHandler; /** * The handler for the bot's commands. */ - public override readonly commandHandler: BushCommandHandler; + public override readonly commandHandler: BotCommandHandler; /** * The handler for the bot's tasks. */ - public override readonly taskHandler: BushTaskHandler; + public override readonly taskHandler: BotTaskHandler; /** * The handler for the bot's context menu commands. @@ -203,12 +193,12 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * A custom logging system for the bot. */ - public override readonly logger: BushLogger = new BushLogger(this); + public override readonly logger: Logger = new Logger(this); /** * Cached global and guild database data. */ - public override readonly cache = new BushCache(); + public override readonly cache = new BotCache(); /** * Sentry error reporting for the bot. @@ -228,7 +218,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * Client utilities. */ - public override readonly utils: BushClientUtils = new BushClientUtils(this); + public override readonly utils: BotClientUtils = new BotClientUtils(this); /** * @param config The configuration for the client. @@ -268,17 +258,17 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re this.token = config.token as If<Ready, string, string | null>; /* =-=-= handlers =-=-= */ - this.listenerHandler = new BushListenerHandler(this, { + this.listenerHandler = new BotListenerHandler(this, { directory: path.join(__dirname, '..', '..', '..', 'src', 'listeners'), extensions: ['.js'], automateCategories: true }); - this.inhibitorHandler = new BushInhibitorHandler(this, { + this.inhibitorHandler = new BotInhibitorHandler(this, { directory: path.join(__dirname, '..', '..', '..', 'src', 'inhibitors'), extensions: ['.js'], automateCategories: true }); - this.taskHandler = new BushTaskHandler(this, { + this.taskHandler = new BotTaskHandler(this, { directory: path.join(__dirname, '..', '..', '..', 'src', 'tasks'), extensions: ['.js'], automateCategories: true @@ -309,7 +299,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re return options; }; - this.commandHandler = new BushCommandHandler(this, { + this.commandHandler = new BotCommandHandler(this, { directory: path.join(__dirname, '..', '..', '..', 'src', 'commands'), extensions: ['.js'], prefix: async ({ guild }: Message) => { @@ -372,7 +362,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * A custom logging system for the bot. */ - public override get console(): BushLogger { + public override get console(): Logger { return this.logger; } @@ -558,18 +548,18 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re } } -export interface BushClient<Ready extends boolean = boolean> extends EventEmitter, PatchedElements, AkairoClient<Ready> { - on<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; - once<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; - emit<K extends keyof BushClientEvents>(event: K, ...args: BushClientEvents[K]): boolean; - off<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this; - removeAllListeners<K extends keyof BushClientEvents>(event?: K): this; +export interface TanzaniteClient<Ready extends boolean = boolean> extends EventEmitter, PatchedElements, AkairoClient<Ready> { + on<K extends keyof BotClientEvents>(event: K, listener: (...args: BotClientEvents[K]) => Awaitable<void>): this; + once<K extends keyof BotClientEvents>(event: K, listener: (...args: BotClientEvents[K]) => Awaitable<void>): this; + emit<K extends keyof BotClientEvents>(event: K, ...args: BotClientEvents[K]): boolean; + off<K extends keyof BotClientEvents>(event: K, listener: (...args: BotClientEvents[K]) => Awaitable<void>): this; + removeAllListeners<K extends keyof BotClientEvents>(event?: K): this; } /** * Various statistics */ -export interface BushStats { +export interface BotStats { /** * The average cpu usage of the bot from the past 60 seconds. */ @@ -587,15 +577,15 @@ export interface BushStats { } export interface Emitters { - client: BushClient; - commandHandler: BushClient['commandHandler']; - inhibitorHandler: BushClient['inhibitorHandler']; - listenerHandler: BushClient['listenerHandler']; - taskHandler: BushClient['taskHandler']; - contextMenuCommandHandler: BushClient['contextMenuCommandHandler']; + client: TanzaniteClient; + commandHandler: TanzaniteClient['commandHandler']; + inhibitorHandler: TanzaniteClient['inhibitorHandler']; + listenerHandler: TanzaniteClient['listenerHandler']; + taskHandler: TanzaniteClient['taskHandler']; + contextMenuCommandHandler: TanzaniteClient['contextMenuCommandHandler']; process: NodeJS.Process; stdin: readline.Interface; - gateway: BushClient['ws']; - rest: BushClient['rest']; - ws: BushClient['ws']; + gateway: TanzaniteClient['ws']; + rest: TanzaniteClient['rest']; + ws: TanzaniteClient['ws']; } diff --git a/lib/extensions/discord.js/BushClientEvents.ts b/lib/extensions/discord.js/BotClientEvents.ts index 22bae65..284ea32 100644 --- a/lib/extensions/discord.js/BushClientEvents.ts +++ b/lib/extensions/discord.js/BotClientEvents.ts @@ -1,9 +1,4 @@ -import type { - BanResponse, - CommandMessage, - Guild as GuildDB, - GuildSettings -} from '#lib'; +import type { BanResponse, CommandMessage, Guild as GuildDB, GuildSettings } from '#lib'; import type { AkairoClientEvents } from 'discord-akairo'; import type { ButtonInteraction, @@ -19,8 +14,34 @@ import type { User } from 'discord.js'; -export interface BushClientEvents extends AkairoClientEvents { - bushBan: [ +export enum TanzaniteEvent { + Ban = 'customBan', + Block = 'customBlock', + Kick = 'customKick', + Mute = 'customMute', + PunishRoleAdd = 'punishRoleAdd', + PunishRoleRemove = 'punishRoleRemove', + Purge = 'customPurge', + RemoveTimeout = 'customRemoveTimeout', + Timeout = 'customTimeout', + Unban = 'customUnban', + Unblock = 'customUnblock', + Unmute = 'customUnmute', + UpdateModlog = 'updateModlog', + UpdateSettings = 'updateSettings', + Warn = 'customWarn', + LevelUpdate = 'levelUpdate', + Lockdown = 'lockdown', + Unlockdown = 'unlockdown', + MassBan = 'massBan', + MassEvidence = 'massEvidence', + Button = 'button', + SelectMenu = 'selectMenu', + ModalSubmit = 'modal' +} + +export interface BotClientEvents extends AkairoClientEvents { + [TanzaniteEvent.Ban]: [ victim: GuildMember | User, moderator: User, guild: Guild, @@ -30,7 +51,7 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess?: boolean, evidence?: string ]; - bushBlock: [ + [TanzaniteEvent.Block]: [ victim: GuildMember, moderator: User, guild: Guild, @@ -41,7 +62,7 @@ export interface BushClientEvents extends AkairoClientEvents { channel: GuildTextBasedChannel, evidence?: string ]; - bushKick: [ + [TanzaniteEvent.Kick]: [ victim: GuildMember, moderator: User, guild: Guild, @@ -50,7 +71,7 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess: boolean, evidence?: string ]; - bushMute: [ + [TanzaniteEvent.Mute]: [ victim: GuildMember, moderator: User, guild: Guild, @@ -60,7 +81,7 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess: boolean, evidence?: string ]; - bushPunishRole: [ + [TanzaniteEvent.PunishRoleAdd]: [ victim: GuildMember, moderator: User, guild: Guild, @@ -70,7 +91,7 @@ export interface BushClientEvents extends AkairoClientEvents { role: Role, evidence?: string ]; - bushPunishRoleRemove: [ + [TanzaniteEvent.PunishRoleRemove]: [ victim: GuildMember, moderator: User, guild: Guild, @@ -79,13 +100,13 @@ export interface BushClientEvents extends AkairoClientEvents { role: Role, evidence?: string ]; - bushPurge: [ + [TanzaniteEvent.Purge]: [ moderator: User, guild: Guild, channel: GuildTextBasedChannel, messages: Collection<Snowflake, Message> ]; - bushRemoveTimeout: [ + [TanzaniteEvent.RemoveTimeout]: [ victim: GuildMember, moderator: User, guild: Guild, @@ -94,7 +115,7 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess: boolean, evidence?: string ]; - bushTimeout: [ + [TanzaniteEvent.Timeout]: [ victim: GuildMember, moderator: User, guild: Guild, @@ -104,7 +125,7 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess: boolean, evidence?: string ]; - bushUnban: [ + [TanzaniteEvent.Unban]: [ victim: User, moderator: User, guild: Guild, @@ -113,7 +134,7 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess: boolean, evidence?: string ]; - bushUnblock: [ + [TanzaniteEvent.Unblock]: [ victim: GuildMember | User, moderator: User, guild: Guild, @@ -123,7 +144,7 @@ export interface BushClientEvents extends AkairoClientEvents { channel: GuildTextBasedChannel, evidence?: string ]; - bushUnmute: [ + [TanzaniteEvent.Unmute]: [ victim: GuildMember, moderator: User, guild: Guild, @@ -132,21 +153,21 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess: boolean, evidence?: string ]; - bushUpdateModlog: [ + [TanzaniteEvent.UpdateModlog]: [ moderator: GuildMember, modlogID: string, key: 'evidence' | 'hidden', oldModlog: string | boolean, newModlog: string | boolean ]; - bushUpdateSettings: [ + [TanzaniteEvent.UpdateSettings]: [ setting: Setting, guild: Guild, oldValue: GuildDB[Setting], newValue: GuildDB[Setting], moderator?: GuildMember ]; - bushWarn: [ + [TanzaniteEvent.Warn]: [ victim: GuildMember, moderator: User, guild: Guild, @@ -155,46 +176,36 @@ export interface BushClientEvents extends AkairoClientEvents { dmSuccess: boolean, evidence?: string ]; - bushLevelUpdate: [ + [TanzaniteEvent.LevelUpdate]: [ member: GuildMember, oldLevel: number, newLevel: number, currentXp: number, message: CommandMessage ]; - bushLockdown: [ + [TanzaniteEvent.Lockdown]: [ moderator: GuildMember, reason: string | undefined, channelsSuccessMap: Collection<Snowflake, boolean>, all?: boolean ]; - bushUnlockdown: [ + [TanzaniteEvent.Unlockdown]: [ moderator: GuildMember, reason: string | undefined, channelsSuccessMap: Collection<Snowflake, boolean>, all?: boolean ]; - massBan: [ + [TanzaniteEvent.MassBan]: [ moderator: GuildMember, guild: Guild, reason: string | undefined, results: Collection<Snowflake, BanResponse> ]; - massEvidence: [ - moderator: GuildMember, - guild: Guild, - evidence: string, - lines: string[] - ]; + [TanzaniteEvent.MassEvidence]: [moderator: GuildMember, guild: Guild, evidence: string, lines: string[]]; /* components */ - button: [button: ButtonInteraction]; - selectMenu: [selectMenu: SelectMenuInteraction]; - modal: [modal: ModalSubmitInteraction]; + [TanzaniteEvent.Button]: [button: ButtonInteraction]; + [TanzaniteEvent.SelectMenu]: [selectMenu: SelectMenuInteraction]; + [TanzaniteEvent.ModalSubmit]: [modal: ModalSubmitInteraction]; } -type Setting = - | GuildSettings - | 'enabledFeatures' - | 'blacklistedChannels' - | 'blacklistedUsers' - | 'disabledCommands'; +type Setting = GuildSettings | 'enabledFeatures' | 'blacklistedChannels' | 'blacklistedUsers' | 'disabledCommands'; diff --git a/lib/extensions/discord.js/ExtendedGuild.ts b/lib/extensions/discord.js/ExtendedGuild.ts index 20c3d29..67de5cf 100644 --- a/lib/extensions/discord.js/ExtendedGuild.ts +++ b/lib/extensions/discord.js/ExtendedGuild.ts @@ -6,6 +6,7 @@ import { emojis, permissionsResponse, punishmentEntryRemove, + TanzaniteClient, type BanResponse, type GuildFeatures, type GuildLogType, @@ -13,7 +14,7 @@ import { } from '#lib'; import * as Moderation from '#lib/common/Moderation.js'; import { Guild as GuildDB, ModLogType } from '#lib/models/index.js'; -import { addOrRemoveFromArray } from '#lib/utils/BushUtils.js'; +import { addOrRemoveFromArray } from '#lib/utils/Utils.js'; import assert from 'assert/strict'; import { AttachmentBuilder, @@ -42,8 +43,13 @@ import { type WebhookMessageOptions } from 'discord.js'; import _ from 'lodash'; +import { TanzaniteEvent } from './BotClientEvents.js'; declare module 'discord.js' { + export interface BaseGuild { + client: TanzaniteClient; + } + export interface Guild { /** * Checks if the guild has a certain custom feature. @@ -93,7 +99,7 @@ declare module 'discord.js' { /** * Sends a message to the guild's specified logging channel * @param logType The corresponding channel that the message will be sent to - * @param message The parameters for {@link BushTextChannel.send} + * @param message The parameters for {@link TextChannel.send} */ sendLogChannel(logType: GuildLogType, message: string | MessagePayload | MessageOptions): Promise<Message | null | undefined>; /** @@ -107,15 +113,15 @@ declare module 'discord.js' { * @param options Options for banning the user. * @returns A string status message of the ban. */ - bushBan(options: GuildBushBanOptions): Promise<BanResponse>; + customBan(options: GuildCustomBanOptions): Promise<BanResponse>; /** - * {@link bushBan} with less resolving and checks + * {@link customBan} with less resolving and checks * @param options Options for banning the user. * @returns A string status message of the ban. * **Preconditions:** * - {@link me} has the `BanMembers` permission * **Warning:** - * - Doesn't emit bushBan Event + * - Doesn't emit customBan Event */ massBanOne(options: GuildMassBanOneOptions): Promise<BanResponse>; /** @@ -123,7 +129,7 @@ declare module 'discord.js' { * @param options Options for unbanning the user. * @returns A status message of the unban. */ - bushUnban(options: GuildBushUnbanOptions): Promise<UnbanResponse>; + customUnban(options: GuildCustomUnbanOptions): Promise<UnbanResponse>; /** * Denies send permissions in specified channels * @param options The options for locking down the guild @@ -207,7 +213,7 @@ export class ExtendedGuild extends Guild { const oldValue = row[setting] as GuildDB[K]; row[setting] = value; this.client.cache.guilds.set(this.id, row.toJSON() as GuildDB); - this.client.emit('bushUpdateSettings', setting, this, oldValue, row[setting], moderator); + this.client.emit(TanzaniteEvent.UpdateSettings, setting, this, oldValue, row[setting], moderator); return await row.save(); } @@ -229,7 +235,7 @@ export class ExtendedGuild extends Guild { /** * Sends a message to the guild's specified logging channel * @param logType The corresponding channel that the message will be sent to - * @param message The parameters for {@link BushTextChannel.send} + * @param message The parameters for {@link TextChannel.send} */ public override async sendLogChannel( logType: GuildLogType, @@ -265,7 +271,7 @@ export class ExtendedGuild extends Guild { * @param options Options for banning the user. * @returns A string status message of the ban. */ - public override async bushBan(options: GuildBushBanOptions): Promise<BanResponse> { + public override async customBan(options: GuildCustomBanOptions): Promise<BanResponse> { // checks if (!this.members.me!.permissions.has(PermissionFlagsBits.BanMembers)) return banResponse.MISSING_PERMISSIONS; @@ -330,7 +336,7 @@ export class ExtendedGuild extends Guild { if (!([banResponse.ACTION_ERROR, banResponse.MODLOG_ERROR, banResponse.PUNISHMENT_ENTRY_ADD_ERROR] as const).includes(ret)) this.client.emit( - 'bushBan', + TanzaniteEvent.Ban, user, moderator, this, @@ -344,13 +350,13 @@ export class ExtendedGuild extends Guild { } /** - * {@link bushBan} with less resolving and checks + * {@link customBan} with less resolving and checks * @param options Options for banning the user. * @returns A string status message of the ban. * **Preconditions:** * - {@link me} has the `BanMembers` permission * **Warning:** - * - Doesn't emit bushBan Event + * - Doesn't emit customBan Event */ public override async massBanOne(options: GuildMassBanOneOptions): Promise<BanResponse> { if (this.bans.cache.has(options.user)) return banResponse.ALREADY_BANNED; @@ -414,7 +420,7 @@ export class ExtendedGuild extends Guild { * @param options Options for unbanning the user. * @returns A status message of the unban. */ - public override async bushUnban(options: GuildBushUnbanOptions): Promise<UnbanResponse> { + public override async customUnban(options: GuildCustomUnbanOptions): Promise<UnbanResponse> { // checks if (!this.members.me!.permissions.has(PermissionFlagsBits.BanMembers)) return unbanResponse.MISSING_PERMISSIONS; @@ -483,7 +489,7 @@ export class ExtendedGuild extends Guild { ) ) this.client.emit( - 'bushUnban', + TanzaniteEvent.Unban, user, moderator, this, @@ -570,7 +576,13 @@ export class ExtendedGuild extends Guild { else return `success: ${success.filter((c) => c === true).size}`; })(); - this.client.emit(options.unlock ? 'bushUnlockdown' : 'bushLockdown', moderator, options.reason, success, options.all); + this.client.emit( + options.unlock ? TanzaniteEvent.Unlockdown : TanzaniteEvent.Lockdown, + moderator, + options.reason, + success, + options.all + ); return ret; } @@ -783,7 +795,7 @@ export class ExtendedGuild extends Guild { /** * Options for unbanning a user */ -export interface GuildBushUnbanOptions { +export interface GuildCustomUnbanOptions { /** * The user to unban */ @@ -830,7 +842,7 @@ export interface GuildMassBanOneOptions { /** * Options for banning a user */ -export interface GuildBushBanOptions { +export interface GuildCustomBanOptions { /** * The user to ban */ diff --git a/lib/extensions/discord.js/ExtendedGuildMember.ts b/lib/extensions/discord.js/ExtendedGuildMember.ts index f8add83..172f6df 100644 --- a/lib/extensions/discord.js/ExtendedGuildMember.ts +++ b/lib/extensions/discord.js/ExtendedGuildMember.ts @@ -1,5 +1,14 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { formatError, Moderation, ModLogType, Time, type BushClientEvents, type PunishmentTypeDM, type ValueOf } from '#lib'; +import { + formatError, + Moderation, + ModLogType, + TanzaniteClient, + Time, + type BotClientEvents, + type PunishmentTypeDM, + type ValueOf +} from '#lib'; import { ChannelType, GuildMember, @@ -8,10 +17,13 @@ import { type GuildTextBasedChannel, type Role } from 'discord.js'; +import { TanzaniteEvent } from './BotClientEvents.js'; /* eslint-enable @typescript-eslint/no-unused-vars */ declare module 'discord.js' { export interface GuildMember { + client: TanzaniteClient; + /** * Send a punishment dm to the user. * @param punishment The punishment that the user has received. @@ -21,7 +33,7 @@ declare module 'discord.js' { * @param sendFooter Whether or not to send the guild's punishment footer with the dm. * @returns Whether or not the dm was sent successfully. */ - bushPunishDM( + customPunishDM( punishment: PunishmentTypeDM, reason?: string | null, duration?: number, @@ -32,71 +44,71 @@ declare module 'discord.js' { * Warn the user, create a modlog entry, and send a dm to the user. * @param options Options for warning the user. * @returns An object with the result of the warning, and the case number of the warn. - * @emits {@link BushClientEvents.bushWarn} + * @emits {@link BotClientEvents.warnMember} */ - bushWarn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }>; + customWarn(options: CustomPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }>; /** * Add a role to the user, if it is a punishment create a modlog entry, and create a punishment entry if it is temporary or a punishment. * @param options Options for adding a role to the user. * @returns A status message for adding the add. - * @emits {@link BushClientEvents.bushPunishRole} + * @emits {@link BotClientEvents.punishRole} */ - bushAddRole(options: AddRoleOptions): Promise<AddRoleResponse>; + customAddRole(options: AddRoleOptions): Promise<AddRoleResponse>; /** * Remove a role from the user, if it is a punishment create a modlog entry, and destroy a punishment entry if it was temporary or a punishment. * @param options Options for removing a role from the user. * @returns A status message for removing the role. - * @emits {@link BushClientEvents.bushPunishRoleRemove} + * @emits {@link BotClientEvents.punishRoleRemove} */ - bushRemoveRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse>; + customRemoveRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse>; /** * Mute the user, create a modlog entry, creates a punishment entry, and dms the user. * @param options Options for muting the user. * @returns A status message for muting the user. - * @emits {@link BushClientEvents.bushMute} + * @emits {@link BotClientEvents.customMute} */ - bushMute(options: BushTimedPunishmentOptions): Promise<MuteResponse>; + customMute(options: CustomTimedPunishmentOptions): Promise<MuteResponse>; /** * Unmute the user, create a modlog entry, remove the punishment entry, and dm the user. * @param options Options for unmuting the user. * @returns A status message for unmuting the user. - * @emits {@link BushClientEvents.bushUnmute} + * @emits {@link BotClientEvents.customUnmute} */ - bushUnmute(options: BushPunishmentOptions): Promise<UnmuteResponse>; + customUnmute(options: CustomPunishmentOptions): Promise<UnmuteResponse>; /** * Kick the user, create a modlog entry, and dm the user. * @param options Options for kicking the user. * @returns A status message for kicking the user. - * @emits {@link BushClientEvents.bushKick} + * @emits {@link BotClientEvents.customKick} */ - bushKick(options: BushPunishmentOptions): Promise<KickResponse>; + customKick(options: CustomPunishmentOptions): Promise<KickResponse>; /** * Ban the user, create a modlog entry, create a punishment entry, and dm the user. * @param options Options for banning the user. * @returns A status message for banning the user. - * @emits {@link BushClientEvents.bushBan} + * @emits {@link BotClientEvents.customBan} */ - bushBan(options: BushBanOptions): Promise<Exclude<BanResponse, typeof banResponse['ALREADY_BANNED']>>; + customBan(options: CustomBanOptions): Promise<Exclude<BanResponse, typeof banResponse['ALREADY_BANNED']>>; /** * Prevents a user from speaking in a channel. * @param options Options for blocking the user. */ - bushBlock(options: BlockOptions): Promise<BlockResponse>; + customBlock(options: BlockOptions): Promise<BlockResponse>; /** * Allows a user to speak in a channel. * @param options Options for unblocking the user. */ - bushUnblock(options: UnblockOptions): Promise<UnblockResponse>; + customUnblock(options: UnblockOptions): Promise<UnblockResponse>; /** * Mutes a user using discord's timeout feature. * @param options Options for timing out the user. */ - bushTimeout(options: BushTimeoutOptions): Promise<TimeoutResponse>; + customTimeout(options: CustomTimeoutOptions): Promise<TimeoutResponse>; /** * Removes a timeout from a user. * @param options Options for removing the timeout. */ - bushRemoveTimeout(options: BushPunishmentOptions): Promise<RemoveTimeoutResponse>; + customRemoveTimeout(options: CustomPunishmentOptions): Promise<RemoveTimeoutResponse>; /** * Whether or not the user is an owner of the bot. */ @@ -121,7 +133,7 @@ export class ExtendedGuildMember extends GuildMember { * @param sendFooter Whether or not to send the guild's punishment footer with the dm. * @returns Whether or not the dm was sent successfully. */ - public override async bushPunishDM( + public override async customPunishDM( punishment: PunishmentTypeDM, reason?: string | null, duration?: number, @@ -144,9 +156,9 @@ export class ExtendedGuildMember extends GuildMember { * Warn the user, create a modlog entry, and send a dm to the user. * @param options Options for warning the user. * @returns An object with the result of the warning, and the case number of the warn. - * @emits {@link BushClientEvents.bushWarn} + * @emits {@link BotClientEvents.warnMember} */ - public override async bushWarn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }> { + public override async customWarn(options: CustomPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }> { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); @@ -172,7 +184,7 @@ export class ExtendedGuildMember extends GuildMember { if (!options.silent) { // dm user - const dmSuccess = await this.bushPunishDM('warned', options.reason); + const dmSuccess = await this.customPunishDM('warned', options.reason); dmSuccessEvent = dmSuccess; if (!dmSuccess) return { result: warnResponse.DM_ERROR, caseNum: result.caseNum }; } @@ -180,7 +192,7 @@ export class ExtendedGuildMember extends GuildMember { return { result: warnResponse.SUCCESS, caseNum: result.caseNum }; })(); if (!([warnResponse.MODLOG_ERROR] as const).includes(ret.result) && !options.silent) - this.client.emit('bushWarn', this, moderator, this.guild, options.reason ?? undefined, caseID!, dmSuccessEvent!); + this.client.emit(TanzaniteEvent.Warn, this, moderator, this.guild, options.reason ?? undefined, caseID!, dmSuccessEvent!); return ret; } @@ -188,9 +200,9 @@ export class ExtendedGuildMember extends GuildMember { * Add a role to the user, if it is a punishment create a modlog entry, and create a punishment entry if it is temporary or a punishment. * @param options Options for adding a role to the user. * @returns A status message for adding the add. - * @emits {@link BushClientEvents.bushPunishRole} + * @emits {@link BotClientEvents.punishRole} */ - public override async bushAddRole(options: AddRoleOptions): Promise<AddRoleResponse> { + public override async customAddRole(options: AddRoleOptions): Promise<AddRoleResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return addRoleResponse.MISSING_PERMISSIONS; const ifShouldAddRole = this.#checkIfShouldAddRole(options.role, options.moderator); @@ -244,7 +256,7 @@ export class ExtendedGuildMember extends GuildMember { !options.silent ) this.client.emit( - 'bushPunishRole', + TanzaniteEvent.PunishRoleAdd, this, moderator, this.guild, @@ -261,9 +273,9 @@ export class ExtendedGuildMember extends GuildMember { * Remove a role from the user, if it is a punishment create a modlog entry, and destroy a punishment entry if it was temporary or a punishment. * @param options Options for removing a role from the user. * @returns A status message for removing the role. - * @emits {@link BushClientEvents.bushPunishRoleRemove} + * @emits {@link BotClientEvents.punishRoleRemove} */ - public override async bushRemoveRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse> { + public override async customRemoveRole(options: RemoveRoleOptions): Promise<RemoveRoleResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ManageRoles)) return removeRoleResponse.MISSING_PERMISSIONS; const ifShouldAddRole = this.#checkIfShouldAddRole(options.role, options.moderator); @@ -318,7 +330,7 @@ export class ExtendedGuildMember extends GuildMember { !options.silent ) this.client.emit( - 'bushPunishRoleRemove', + TanzaniteEvent.PunishRoleRemove, this, moderator, this.guild, @@ -354,9 +366,9 @@ export class ExtendedGuildMember extends GuildMember { * Mute the user, create a modlog entry, creates a punishment entry, and dms the user. * @param options Options for muting the user. * @returns A status message for muting the user. - * @emits {@link BushClientEvents.bushMute} + * @emits {@link BotClientEvents.customMute} */ - public override async bushMute(options: BushTimedPunishmentOptions): Promise<MuteResponse> { + public override async customMute(options: CustomTimedPunishmentOptions): Promise<MuteResponse> { // checks const checks = await Moderation.checkMutePermissions(this.guild); if (checks !== true) return checks; @@ -410,7 +422,7 @@ export class ExtendedGuildMember extends GuildMember { if (!options.silent) { // dm user - const dmSuccess = await this.bushPunishDM('muted', options.reason, options.duration ?? 0, modlog.id); + const dmSuccess = await this.customPunishDM('muted', options.reason, options.duration ?? 0, modlog.id); dmSuccessEvent = dmSuccess; if (!dmSuccess) return muteResponse.DM_ERROR; } @@ -423,7 +435,7 @@ export class ExtendedGuildMember extends GuildMember { !options.silent ) this.client.emit( - 'bushMute', + TanzaniteEvent.Mute, this, moderator, this.guild, @@ -440,9 +452,9 @@ export class ExtendedGuildMember extends GuildMember { * Unmute the user, create a modlog entry, remove the punishment entry, and dm the user. * @param options Options for unmuting the user. * @returns A status message for unmuting the user. - * @emits {@link BushClientEvents.bushUnmute} + * @emits {@link BotClientEvents.customUnmute} */ - public override async bushUnmute(options: BushPunishmentOptions): Promise<UnmuteResponse> { + public override async customUnmute(options: CustomPunishmentOptions): Promise<UnmuteResponse> { // checks const checks = await Moderation.checkMutePermissions(this.guild); if (checks !== true) return checks; @@ -492,7 +504,7 @@ export class ExtendedGuildMember extends GuildMember { if (!options.silent) { // dm user - const dmSuccess = await this.bushPunishDM('unmuted', options.reason, undefined, '', false); + const dmSuccess = await this.customPunishDM('unmuted', options.reason, undefined, '', false); dmSuccessEvent = dmSuccess; if (!dmSuccess) return unmuteResponse.DM_ERROR; } @@ -507,7 +519,7 @@ export class ExtendedGuildMember extends GuildMember { !options.silent ) this.client.emit( - 'bushUnmute', + TanzaniteEvent.Unmute, this, moderator, this.guild, @@ -523,9 +535,9 @@ export class ExtendedGuildMember extends GuildMember { * Kick the user, create a modlog entry, and dm the user. * @param options Options for kicking the user. * @returns A status message for kicking the user. - * @emits {@link BushClientEvents.bushKick} + * @emits {@link BotClientEvents.customKick} */ - public override async bushKick(options: BushPunishmentOptions): Promise<KickResponse> { + public override async customKick(options: CustomPunishmentOptions): Promise<KickResponse> { // checks if (!this.guild.members.me?.permissions.has(PermissionFlagsBits.KickMembers) || !this.kickable) return kickResponse.MISSING_PERMISSIONS; @@ -550,7 +562,7 @@ export class ExtendedGuildMember extends GuildMember { caseID = modlog.id; // dm user - const dmSuccess = options.silent ? null : await this.bushPunishDM('kicked', options.reason, undefined, modlog.id); + const dmSuccess = options.silent ? null : await this.customPunishDM('kicked', options.reason, undefined, modlog.id); dmSuccessEvent = dmSuccess ?? undefined; // kick @@ -562,7 +574,7 @@ export class ExtendedGuildMember extends GuildMember { })(); if (!([kickResponse.ACTION_ERROR, kickResponse.MODLOG_ERROR] as const).includes(ret) && !options.silent) this.client.emit( - 'bushKick', + TanzaniteEvent.Kick, this, moderator, this.guild, @@ -578,9 +590,11 @@ export class ExtendedGuildMember extends GuildMember { * Ban the user, create a modlog entry, create a punishment entry, and dm the user. * @param options Options for banning the user. * @returns A status message for banning the user. - * @emits {@link BushClientEvents.bushBan} + * @emits {@link BotClientEvents.customBan} */ - public override async bushBan(options: BushBanOptions): Promise<Exclude<BanResponse, typeof banResponse['ALREADY_BANNED']>> { + public override async customBan( + options: CustomBanOptions + ): Promise<Exclude<BanResponse, typeof banResponse['ALREADY_BANNED']>> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.BanMembers) || !this.bannable) return banResponse.MISSING_PERMISSIONS; @@ -591,7 +605,7 @@ export class ExtendedGuildMember extends GuildMember { if (!moderator) return banResponse.CANNOT_RESOLVE_USER; // ignore result, they should still be banned even if their mute cannot be removed - await this.bushUnmute({ + await this.customUnmute({ reason: 'User is about to be banned, a mute is no longer necessary.', moderator: this.guild.members.me!, silent: true @@ -616,7 +630,7 @@ export class ExtendedGuildMember extends GuildMember { // dm user const dmSuccess = options.silent ? null - : await this.bushPunishDM('banned', options.reason, options.duration ?? 0, modlog.id); + : await this.customPunishDM('banned', options.reason, options.duration ?? 0, modlog.id); dmSuccessEvent = dmSuccess ?? undefined; // ban @@ -645,7 +659,7 @@ export class ExtendedGuildMember extends GuildMember { !options.silent ) this.client.emit( - 'bushBan', + TanzaniteEvent.Ban, this, moderator, this.guild, @@ -662,7 +676,7 @@ export class ExtendedGuildMember extends GuildMember { * Prevents a user from speaking in a channel. * @param options Options for blocking the user. */ - public override async bushBlock(options: BlockOptions): Promise<BlockResponse> { + public override async customBlock(options: BlockOptions): Promise<BlockResponse> { const channel = this.guild.channels.resolve(options.channel); if (!channel || (!channel.isTextBased() && !channel.isThread())) return blockResponse.INVALID_CHANNEL; @@ -737,7 +751,7 @@ export class ExtendedGuildMember extends GuildMember { !options.silent ) this.client.emit( - 'bushBlock', + TanzaniteEvent.Block, this, moderator, this.guild, @@ -755,7 +769,7 @@ export class ExtendedGuildMember extends GuildMember { * Allows a user to speak in a channel. * @param options Options for unblocking the user. */ - public override async bushUnblock(options: UnblockOptions): Promise<UnblockResponse> { + public override async customUnblock(options: UnblockOptions): Promise<UnblockResponse> { const _channel = this.guild.channels.resolve(options.channel); if (!_channel || (_channel.type !== ChannelType.GuildText && !_channel.isThread())) return unblockResponse.INVALID_CHANNEL; const channel = _channel as GuildTextBasedChannel; @@ -828,7 +842,7 @@ export class ExtendedGuildMember extends GuildMember { !options.silent ) this.client.emit( - 'bushUnblock', + TanzaniteEvent.Unblock, this, moderator, this.guild, @@ -845,7 +859,7 @@ export class ExtendedGuildMember extends GuildMember { * Mutes a user using discord's timeout feature. * @param options Options for timing out the user. */ - public override async bushTimeout(options: BushTimeoutOptions): Promise<TimeoutResponse> { + public override async customTimeout(options: CustomTimeoutOptions): Promise<TimeoutResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) return timeoutResponse.MISSING_PERMISSIONS; @@ -883,7 +897,7 @@ export class ExtendedGuildMember extends GuildMember { if (!options.silent) { // dm user - const dmSuccess = await this.bushPunishDM('timedout', options.reason, options.duration, modlog.id); + const dmSuccess = await this.customPunishDM('timedout', options.reason, options.duration, modlog.id); dmSuccessEvent = dmSuccess; if (!dmSuccess) return timeoutResponse.DM_ERROR; } @@ -893,7 +907,7 @@ export class ExtendedGuildMember extends GuildMember { if (!([timeoutResponse.ACTION_ERROR, timeoutResponse.MODLOG_ERROR] as const).includes(ret) && !options.silent) this.client.emit( - 'bushTimeout', + TanzaniteEvent.Timeout, this, moderator, this.guild, @@ -910,7 +924,7 @@ export class ExtendedGuildMember extends GuildMember { * Removes a timeout from a user. * @param options Options for removing the timeout. */ - public override async bushRemoveTimeout(options: BushPunishmentOptions): Promise<RemoveTimeoutResponse> { + public override async customRemoveTimeout(options: CustomPunishmentOptions): Promise<RemoveTimeoutResponse> { // checks if (!this.guild.members.me!.permissions.has(PermissionFlagsBits.ModerateMembers)) return removeTimeoutResponse.MISSING_PERMISSIONS; @@ -944,7 +958,7 @@ export class ExtendedGuildMember extends GuildMember { if (!options.silent) { // dm user - const dmSuccess = await this.bushPunishDM('untimedout', options.reason, undefined, '', false); + const dmSuccess = await this.customPunishDM('untimedout', options.reason, undefined, '', false); dmSuccessEvent = dmSuccess; if (!dmSuccess) return removeTimeoutResponse.DM_ERROR; } @@ -954,7 +968,7 @@ export class ExtendedGuildMember extends GuildMember { if (!([removeTimeoutResponse.ACTION_ERROR, removeTimeoutResponse.MODLOG_ERROR] as const).includes(ret) && !options.silent) this.client.emit( - 'bushRemoveTimeout', + TanzaniteEvent.RemoveTimeout, this, moderator, this.guild, @@ -984,7 +998,7 @@ export class ExtendedGuildMember extends GuildMember { /** * Options for punishing a user. */ -export interface BushPunishmentOptions { +export interface CustomPunishmentOptions { /** * The reason for the punishment. */ @@ -1009,7 +1023,7 @@ export interface BushPunishmentOptions { /** * Punishment options for punishments that can be temporary. */ -export interface BushTimedPunishmentOptions extends BushPunishmentOptions { +export interface CustomTimedPunishmentOptions extends CustomPunishmentOptions { /** * The duration of the punishment. */ @@ -1019,7 +1033,7 @@ export interface BushTimedPunishmentOptions extends BushPunishmentOptions { /** * Options for a role add punishment. */ -export interface AddRoleOptions extends BushTimedPunishmentOptions { +export interface AddRoleOptions extends CustomTimedPunishmentOptions { /** * The role to add to the user. */ @@ -1034,7 +1048,7 @@ export interface AddRoleOptions extends BushTimedPunishmentOptions { /** * Options for a role remove punishment. */ -export interface RemoveRoleOptions extends BushTimedPunishmentOptions { +export interface RemoveRoleOptions extends CustomTimedPunishmentOptions { /** * The role to remove from the user. */ @@ -1049,7 +1063,7 @@ export interface RemoveRoleOptions extends BushTimedPunishmentOptions { /** * Options for banning a user. */ -export interface BushBanOptions extends BushTimedPunishmentOptions { +export interface CustomBanOptions extends CustomTimedPunishmentOptions { /** * The number of days to delete the user's messages for. */ @@ -1059,7 +1073,7 @@ export interface BushBanOptions extends BushTimedPunishmentOptions { /** * Options for blocking a user from a channel. */ -export interface BlockOptions extends BushTimedPunishmentOptions { +export interface BlockOptions extends CustomTimedPunishmentOptions { /** * The channel to block the user from. */ @@ -1069,7 +1083,7 @@ export interface BlockOptions extends BushTimedPunishmentOptions { /** * Options for unblocking a user from a channel. */ -export interface UnblockOptions extends BushPunishmentOptions { +export interface UnblockOptions extends CustomPunishmentOptions { /** * The channel to unblock the user from. */ @@ -1079,7 +1093,7 @@ export interface UnblockOptions extends BushPunishmentOptions { /** * Punishment options for punishments that can be temporary. */ -export interface BushTimeoutOptions extends BushPunishmentOptions { +export interface CustomTimeoutOptions extends CustomPunishmentOptions { /** * The duration of the punishment. */ @@ -1251,5 +1265,5 @@ export type TimeoutResponse = ValueOf<typeof timeoutResponse>; export type RemoveTimeoutResponse = ValueOf<typeof removeTimeoutResponse>; /** - * @typedef {BushClientEvents} VSCodePleaseDontRemove + * @typedef {BotClientEvents} VSCodePleaseDontRemove */ diff --git a/lib/extensions/discord.js/ExtendedUser.ts b/lib/extensions/discord.js/ExtendedUser.ts index 23de523..65b14c7 100644 --- a/lib/extensions/discord.js/ExtendedUser.ts +++ b/lib/extensions/discord.js/ExtendedUser.ts @@ -1,4 +1,4 @@ -import { User, type Partialize } from 'discord.js'; +import { User } from 'discord.js'; declare module 'discord.js' { export interface User { @@ -13,8 +13,6 @@ declare module 'discord.js' { } } -export type PartialBushUser = Partialize<ExtendedUser, 'username' | 'tag' | 'discriminator' | 'isOwner' | 'isSuperUser'>; - /** * Represents a user on Discord. */ diff --git a/lib/index.ts b/lib/index.ts index ca23177..fc7bb4c 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,10 +1,9 @@ import './global.js'; - export * from './automod/AutomodShared.js'; export * from './automod/MemberAutomod.js'; export * from './automod/MessageAutomod.js'; export * from './automod/PresenceAutomod.js'; -export * from './common/BushCache.js'; +export * from './common/BotCache.js'; export * from './common/ButtonPaginator.js'; export * from './common/CanvasProgressBar.js'; export * from './common/ConfirmationPrompt.js'; @@ -20,42 +19,32 @@ export type { RemovePunishmentEntryOptions, SimpleCreateModLogEntryOptions } from './common/Moderation.js'; -export * from './extensions/discord-akairo/BushArgumentTypeCaster.js'; -export * from './extensions/discord-akairo/BushClient.js'; -export * from './extensions/discord-akairo/BushCommand.js'; -export * from './extensions/discord-akairo/BushCommandHandler.js'; -export * from './extensions/discord-akairo/BushInhibitor.js'; -export * from './extensions/discord-akairo/BushInhibitorHandler.js'; -export * from './extensions/discord-akairo/BushListener.js'; -export * from './extensions/discord-akairo/BushListenerHandler.js'; -export * from './extensions/discord-akairo/BushTask.js'; -export * from './extensions/discord-akairo/BushTaskHandler.js'; +export * from './extensions/discord-akairo/BotArgumentTypeCaster.js'; +export * from './extensions/discord-akairo/BotCommand.js'; +export * from './extensions/discord-akairo/BotCommandHandler.js'; +export * from './extensions/discord-akairo/BotInhibitor.js'; +export * from './extensions/discord-akairo/BotInhibitorHandler.js'; +export * from './extensions/discord-akairo/BotListener.js'; +export * from './extensions/discord-akairo/BotListenerHandler.js'; +export * from './extensions/discord-akairo/BotTask.js'; +export * from './extensions/discord-akairo/BotTaskHandler.js'; export * from './extensions/discord-akairo/SlashMessage.js'; -export type { BushClientEvents } from './extensions/discord.js/BushClientEvents.js'; +export * from './extensions/discord-akairo/TanzaniteClient.js'; +export * from './extensions/discord.js/BotClientEvents.js'; export * from './extensions/discord.js/ExtendedGuild.js'; export * from './extensions/discord.js/ExtendedGuildMember.js'; export * from './extensions/discord.js/ExtendedMessage.js'; export * from './extensions/discord.js/ExtendedUser.js'; -export * from './models/BaseModel.js'; -export * from './models/instance/ActivePunishment.js'; -export * from './models/instance/Guild.js'; -export * from './models/instance/Highlight.js'; -export * from './models/instance/Level.js'; -export * from './models/instance/ModLog.js'; -export * from './models/instance/Reminder.js'; -export * from './models/instance/StickyRole.js'; -export * from './models/shared/Global.js'; -export * from './models/shared/MemberCount.js'; -export * from './models/shared/Shared.js'; -export * from './models/shared/Stat.js'; -export type { BushInspectOptions } from './types/BushInspectOptions.js'; +export * from './models/index.js'; export type { CodeBlockLang } from './types/CodeBlockLang.js'; +export type { CustomInspectOptions } from './types/InspectOptions.js'; +export * from './types/misc.js'; export * from './utils/AllowedMentions.js'; export * as Arg from './utils/Arg.js'; -export * from './utils/BushConstants.js'; -export * from './utils/BushLogger.js'; -export * from './utils/BushUtils.js'; +export * from './utils/Constants.js'; export * from './utils/ErrorHandler.js'; export * as Format from './utils/Format.js'; export * from './utils/FormatResponse.js'; +export * from './utils/Logger.js'; export * from './utils/UpdateCache.js'; +export * from './utils/Utils.js'; diff --git a/lib/models/instance/Guild.ts b/lib/models/instance/Guild.ts index 763485f..72091ca 100644 --- a/lib/models/instance/Guild.ts +++ b/lib/models/instance/Guild.ts @@ -1,6 +1,6 @@ import config from '#config'; import { BadWordDetails } from '#lib/automod/AutomodShared.js'; -import { type BushClient } from '#lib/extensions/discord-akairo/BushClient.js'; +import { type TanzaniteClient } from '#lib/extensions/discord-akairo/TanzaniteClient.js'; import { ChannelType, Constants, type Snowflake } from 'discord.js'; import { DataTypes, type Sequelize } from 'sequelize'; import { BaseModel } from '../BaseModel.js'; @@ -145,7 +145,7 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i * Initializes the model. * @param sequelize The sequelize instance. */ - public static initModel(sequelize: Sequelize, client: BushClient): void { + public static initModel(sequelize: Sequelize, client: TanzaniteClient): void { Guild.init( { id: { type: DataTypes.STRING, primaryKey: true }, diff --git a/lib/types/BushInspectOptions.ts b/lib/types/BushInspectOptions.ts deleted file mode 100644 index 30ed01a..0000000 --- a/lib/types/BushInspectOptions.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { type InspectOptions } from 'util'; - -/** - * {@link https://nodejs.org/api/util.html#utilinspectobject-showhidden-depth-colors util.inspect Options Documentation} - */ -export interface BushInspectOptions extends InspectOptions { - /** - * If `true`, object's non-enumerable symbols and properties are included in the - * formatted result. [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) - * and [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) entries - * are also included as well as user defined prototype properties (excluding method properties). - * - * @default false - */ - showHidden?: boolean | undefined; - - /** - * Specifies the number of times to recurse while formatting `object`. This is useful - * for inspecting large objects. To recurse up to the maximum call stack size pass - * `Infinity` or `null`. - * - * @default 2 - */ - depth?: number | null | undefined; - - /** - * If `true`, the output is styled with ANSI color codes. Colors are customizable. See - * [Customizing util.inspect colors](https://nodejs.org/api/util.html#util_customizing_util_inspect_colors). - * - * @default false - */ - colors?: boolean | undefined; - - /** - * If `false`, `[util.inspect.custom](depth, opts)` functions are not invoked. - * - * @default true - */ - customInspect?: boolean | undefined; - - /** - * If `true`, `Proxy` inspection includes the - * [`target` and `handler`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#Terminology) - * objects. - * - * @default false - */ - showProxy?: boolean | undefined; - - /** - * Specifies the maximum number of `Array`, [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), - * [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) and - * [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) elements to - * include when formatting. Set to `null` or `Infinity` to show all elements. - * Set to `0` or negative to show no elements. - * - * @default 100 - */ - maxArrayLength?: number | null | undefined; - - /** - * Specifies the maximum number of characters to include when formatting. Set to - * `null` or `Infinity` to show all elements. Set to `0` or negative to show no - * characters. - * - * @default 10000 - */ - maxStringLength?: number | null | undefined; - - /** - * The length at which input values are split across multiple lines. Set to - * `Infinity` to format the input as a single line (in combination with compact set - * to `true` or any number >= `1`). - * - * @default 80 - */ - breakLength?: number | undefined; - - /** - * Setting this to `false` causes each object key to be displayed on a new line. It - * will break on new lines in text that is longer than `breakLength`. If set to a - * number, the most `n` inner elements are united on a single line as long as all - * properties fit into `breakLength`. Short array elements are also grouped together. - * - * @default 3 - */ - compact?: boolean | number | undefined; - - /** - * If set to `true` or a function, all properties of an object, and `Set` and `Map` - * entries are sorted in the resulting string. If set to `true` the - * [default sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) is used. - * If set to a function, it is used as a - * [compare function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters). - * - * @default false - */ - sorted?: boolean | ((a: string, b: string) => number) | undefined; - - /** - * If set to `true`, getters are inspected. If set to `'get'`, only getters without a - * corresponding setter are inspected. If set to `'set'`, only getters with a - * corresponding setter are inspected. This might cause side effects depending on - * the getter function. - * - * @default false - */ - getters?: 'get' | 'set' | boolean | undefined; - - /** - * If set to `true`, an underscore is used to separate every three digits in all bigints and numbers. - * - * @default false - */ - numericSeparator?: boolean; - - /** - * Whether or not to inspect strings. - * - * @default false - */ - inspectStrings?: boolean; -} diff --git a/lib/types/InspectOptions.ts b/lib/types/InspectOptions.ts new file mode 100644 index 0000000..1113f2b --- /dev/null +++ b/lib/types/InspectOptions.ts @@ -0,0 +1,127 @@ +import { InspectOptions } from 'node:util'; + +declare module 'util' { + /** + * {@link https://nodejs.org/api/util.html#utilinspectobject-showhidden-depth-colors util.inspect Options Documentation} + */ + export interface InspectOptions { + /** + * If `true`, object's non-enumerable symbols and properties are included in the + * formatted result. [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) + * and [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) entries + * are also included as well as user defined prototype properties (excluding method properties). + * + * @default false + */ + showHidden?: boolean | undefined; + + /** + * Specifies the number of times to recurse while formatting `object`. This is useful + * for inspecting large objects. To recurse up to the maximum call stack size pass + * `Infinity` or `null`. + * + * @default 2 + */ + depth?: number | null | undefined; + + /** + * If `true`, the output is styled with ANSI color codes. Colors are customizable. See + * [Customizing util.inspect colors](https://nodejs.org/api/util.html#util_customizing_util_inspect_colors). + * + * @default false + */ + colors?: boolean | undefined; + + /** + * If `false`, `[util.inspect.custom](depth, opts)` functions are not invoked. + * + * @default true + */ + customInspect?: boolean | undefined; + + /** + * If `true`, `Proxy` inspection includes the + * [`target` and `handler`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#Terminology) + * objects. + * + * @default false + */ + showProxy?: boolean | undefined; + + /** + * Specifies the maximum number of `Array`, [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), + * [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) and + * [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) elements to + * include when formatting. Set to `null` or `Infinity` to show all elements. + * Set to `0` or negative to show no elements. + * + * @default 100 + */ + maxArrayLength?: number | null | undefined; + + /** + * Specifies the maximum number of characters to include when formatting. Set to + * `null` or `Infinity` to show all elements. Set to `0` or negative to show no + * characters. + * + * @default 10000 + */ + maxStringLength?: number | null | undefined; + + /** + * The length at which input values are split across multiple lines. Set to + * `Infinity` to format the input as a single line (in combination with compact set + * to `true` or any number >= `1`). + * + * @default 80 + */ + breakLength?: number | undefined; + + /** + * Setting this to `false` causes each object key to be displayed on a new line. It + * will break on new lines in text that is longer than `breakLength`. If set to a + * number, the most `n` inner elements are united on a single line as long as all + * properties fit into `breakLength`. Short array elements are also grouped together. + * + * @default 3 + */ + compact?: boolean | number | undefined; + + /** + * If set to `true` or a function, all properties of an object, and `Set` and `Map` + * entries are sorted in the resulting string. If set to `true` the + * [default sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) is used. + * If set to a function, it is used as a + * [compare function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters). + * + * @default false + */ + sorted?: boolean | ((a: string, b: string) => number) | undefined; + + /** + * If set to `true`, getters are inspected. If set to `'get'`, only getters without a + * corresponding setter are inspected. If set to `'set'`, only getters with a + * corresponding setter are inspected. This might cause side effects depending on + * the getter function. + * + * @default false + */ + getters?: 'get' | 'set' | boolean | undefined; + + /** + * If set to `true`, an underscore is used to separate every three digits in all bigints and numbers. + * + * @default false + */ + numericSeparator?: boolean; + } +} + +export interface CustomInspectOptions extends InspectOptions { + /** + * Whether or not to inspect strings. + * + * @default false + */ + inspectStrings?: boolean; +} diff --git a/lib/types/misc.ts b/lib/types/misc.ts new file mode 100644 index 0000000..5bf760c --- /dev/null +++ b/lib/types/misc.ts @@ -0,0 +1,14 @@ +import type { + InteractionReplyOptions, + MessageEditOptions, + MessageOptions, + MessagePayload, + ReplyMessageOptions, + WebhookEditMessageOptions +} from 'discord.js'; + +export type ReplyMessageType = string | MessagePayload | ReplyMessageOptions; +export type EditMessageType = string | MessageEditOptions | MessagePayload; +export type SlashSendMessageType = string | MessagePayload | InteractionReplyOptions; +export type SlashEditMessageType = string | MessagePayload | WebhookEditMessageOptions; +export type SendMessageType = string | MessagePayload | MessageOptions; diff --git a/lib/utils/Arg.ts b/lib/utils/Arg.ts index d362225..99060fb 100644 --- a/lib/utils/Arg.ts +++ b/lib/utils/Arg.ts @@ -1,7 +1,7 @@ import { - type BaseBushArgumentType, - type BushArgumentType, - type BushArgumentTypeCaster, + type BaseBotArgumentType, + type BotArgumentType, + type BotArgumentTypeCaster, type CommandMessage, type SlashMessage } from '#lib'; @@ -160,33 +160,33 @@ export function withInput(type: AT | ATC): ATC { return Argument.withInput(type as any); } -type BushArgumentTypeCasterReturn<R> = R extends BushArgumentTypeCaster<infer S> ? S : R; +type CustomArgumentTypeCasterReturn<R> = R extends BotArgumentTypeCaster<infer S> ? S : R; /** ```ts - * <R = unknown> = BushArgumentTypeCaster<R> + * <R = unknown> = CustomArgumentTypeCaster<R> * ``` */ -type ATC<R = unknown> = BushArgumentTypeCaster<R>; +type ATC<R = unknown> = BotArgumentTypeCaster<R>; /** ```ts - * keyof BaseBushArgumentType + * keyof BaseCustomArgumentType * ``` */ -type KBAT = keyof BaseBushArgumentType; +type KBAT = keyof BaseBotArgumentType; /** ```ts - * <R> = BushArgumentTypeCasterReturn<R> + * <R> = CustomArgumentTypeCasterReturn<R> * ``` */ -type ATCR<R> = BushArgumentTypeCasterReturn<R>; +type ATCR<R> = CustomArgumentTypeCasterReturn<R>; /** ```ts - * BushArgumentType + * CustomArgumentType * ``` */ -type AT = BushArgumentType; +type AT = BotArgumentType; /** ```ts - * BaseBushArgumentType + * BaseCustomArgumentType * ``` */ -type BAT = BaseBushArgumentType; +type BAT = BaseBotArgumentType; /** ```ts - * <T extends BushArgumentTypeCaster> = BushArgumentTypeCaster<BushArgumentTypeCasterReturn<T>> + * <T extends CustomArgumentTypeCaster> = CustomArgumentTypeCaster<CustomArgumentTypeCasterReturn<T>> * ``` */ -type ATCATCR<T extends BushArgumentTypeCaster> = BushArgumentTypeCaster<BushArgumentTypeCasterReturn<T>>; +type ATCATCR<T extends BotArgumentTypeCaster> = BotArgumentTypeCaster<CustomArgumentTypeCasterReturn<T>>; /** ```ts - * <T extends keyof BaseBushArgumentType> = BushArgumentTypeCaster<BaseBushArgumentType[T]> + * <T extends keyof BaseCustomArgumentType> = CustomArgumentTypeCaster<BaseCustomArgumentType[T]> * ``` */ -type ATCBAT<T extends keyof BaseBushArgumentType> = BushArgumentTypeCaster<BaseBushArgumentType[T]>; +type ATCBAT<T extends keyof BaseBotArgumentType> = BotArgumentTypeCaster<BaseBotArgumentType[T]>; diff --git a/lib/utils/BushClientUtils.ts b/lib/utils/BotClientUtils.ts index e468cd7..a251bdf 100644 --- a/lib/utils/BushClientUtils.ts +++ b/lib/utils/BotClientUtils.ts @@ -1,7 +1,7 @@ import { ConfigChannelKey } from '#config'; -import type { BushInspectOptions, CodeBlockLang } from '#lib'; -import { GlobalCache, SharedCache } from '#lib/common/BushCache.js'; -import { CommandMessage } from '#lib/extensions/discord-akairo/BushCommand.js'; +import type { CodeBlockLang, CustomInspectOptions } from '#lib'; +import { GlobalCache, SharedCache } from '#lib/common/BotCache.js'; +import { CommandMessage } from '#lib/extensions/discord-akairo/BotCommand.js'; import { SlashMessage } from '#lib/extensions/discord-akairo/SlashMessage.js'; import { Global, Shared } from '#lib/models/index.js'; import assert from 'assert/strict'; @@ -22,14 +22,14 @@ import { type UserResolvable } from 'discord.js'; import _ from 'lodash'; -import { emojis, Pronoun, PronounCode, pronounMapping, regex } from './BushConstants.js'; -import { addOrRemoveFromArray, formatError, inspect } from './BushUtils.js'; +import { emojis, Pronoun, PronounCode, pronounMapping, regex } from './Constants.js'; import { generateErrorEmbed } from './ErrorHandler.js'; +import { addOrRemoveFromArray, formatError, inspect } from './Utils.js'; /** * Utilities that require access to the client. */ -export class BushClientUtils { +export class BotClientUtils { /** * The hastebin urls used to post to hastebin, attempts to post in order */ @@ -185,14 +185,14 @@ export class BushClientUtils { * (and uploads to hast if the content is too long). * @param input The object to be inspect, redacted, and put into a codeblock. * @param language The language to make the codeblock. - * @param inspectOptions The options for {@link BushClientUtil.inspect}. + * @param inspectOptions The options for {@link CustomClientUtil.inspect}. * @param length The maximum length that the codeblock can be. * @returns The generated codeblock. */ public async inspectCleanRedactCodeblock( input: any, language?: CodeBlockLang | '', - inspectOptions?: BushInspectOptions, + inspectOptions?: CustomInspectOptions, length = 1024 ) { input = inspect(input, inspectOptions ?? undefined); @@ -205,10 +205,10 @@ export class BushClientUtils { /** * Takes an any value, inspects it, redacts credentials, and uploads it to haste. * @param input The object to be inspect, redacted, and upload. - * @param inspectOptions The options for {@link BushClientUtil.inspect}. + * @param inspectOptions The options for {@link BotClientUtils.inspect}. * @returns The {@link HasteResults}. */ - public async inspectCleanRedactHaste(input: any, inspectOptions?: BushInspectOptions): Promise<HasteResults> { + public async inspectCleanRedactHaste(input: any, inspectOptions?: CustomInspectOptions): Promise<HasteResults> { input = inspect(input, inspectOptions ?? undefined); input = this.redact(input); return this.haste(input, true); @@ -217,10 +217,10 @@ export class BushClientUtils { /** * Takes an any value, inspects it and redacts credentials. * @param input The object to be inspect and redacted. - * @param inspectOptions The options for {@link BushClientUtil.inspect}. + * @param inspectOptions The options for {@link BotClientUtils.inspect}. * @returns The redacted and inspected object. */ - public inspectAndRedact(input: any, inspectOptions?: BushInspectOptions): string { + public inspectAndRedact(input: any, inspectOptions?: CustomInspectOptions): string { input = inspect(input, inspectOptions ?? undefined); return this.redact(input); } diff --git a/lib/utils/BushConstants.ts b/lib/utils/Constants.ts index 8e4871b..8e4871b 100644 --- a/lib/utils/BushConstants.ts +++ b/lib/utils/Constants.ts diff --git a/lib/utils/ErrorHandler.ts b/lib/utils/ErrorHandler.ts index 923da75..3f8be89 100644 --- a/lib/utils/ErrorHandler.ts +++ b/lib/utils/ErrorHandler.ts @@ -1,14 +1,14 @@ import { AkairoMessage, Command } from 'discord-akairo'; import { ChannelType, Client, EmbedBuilder, escapeInlineCode, GuildTextBasedChannel, Message } from 'discord.js'; -import { BushCommandHandlerEvents } from '../extensions/discord-akairo/BushCommandHandler.js'; +import { BotCommandHandlerEvents } from '../extensions/discord-akairo/BotCommandHandler.js'; import { SlashMessage } from '../extensions/discord-akairo/SlashMessage.js'; -import { colors } from './BushConstants.js'; -import { capitalize, formatError } from './BushUtils.js'; +import { colors } from './Constants.js'; import { bold, input } from './Format.js'; +import { capitalize, formatError } from './Utils.js'; export async function handleCommandError( client: Client, - ...[error, message, _command]: BushCommandHandlerEvents['error'] | BushCommandHandlerEvents['slashError'] + ...[error, message, _command]: BotCommandHandlerEvents['error'] | BotCommandHandlerEvents['slashError'] ) { try { const isSlash = message.util?.isSlash; diff --git a/lib/utils/FormatResponse.ts b/lib/utils/FormatResponse.ts index f094601..470fea7 100644 --- a/lib/utils/FormatResponse.ts +++ b/lib/utils/FormatResponse.ts @@ -1,8 +1,8 @@ import type { GuildMember } from 'discord.js'; import { unmuteResponse, UnmuteResponse } from '../extensions/discord.js/ExtendedGuildMember.js'; -import { emojis } from './BushConstants.js'; -import { format } from './BushUtils.js'; +import { emojis } from './Constants.js'; import { input } from './Format.js'; +import { format } from './Utils.js'; export function formatUnmuteResponse(prefix: string, member: GuildMember, code: UnmuteResponse): string { const error = emojis.error; diff --git a/lib/utils/BushLogger.ts b/lib/utils/Logger.ts index f575b50..872ff3e 100644 --- a/lib/utils/BushLogger.ts +++ b/lib/utils/Logger.ts @@ -1,12 +1,11 @@ import chalk from 'chalk'; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { type SendMessageType } from '#lib/extensions/discord-akairo/BushClient.js'; import { bold, Client, EmbedBuilder, escapeMarkdown, PartialTextBasedChannelFields, type Message } from 'discord.js'; import { stripVTControlCharacters as stripColor } from 'node:util'; import repl, { REPLServer, REPL_MODE_STRICT } from 'repl'; import { WriteStream } from 'tty'; -import { colors } from './BushConstants.js'; -import { inspect } from './BushUtils.js'; +import type { SendMessageType } from '../types/misc.js'; +import { colors } from './Constants.js'; +import { inspect } from './Utils.js'; let REPL: REPLServer; let replGone = false; @@ -25,7 +24,7 @@ export function init() { }); const apply = (stream: WriteStream, symbol: symbol): ProxyHandler<typeof console['log']>['apply'] => - function apply(target, thisArg, args) { + function apply(target, _thisArg, args) { if (stream.isTTY) { stream.moveCursor(0, -1); stream.write('\n'); @@ -121,7 +120,7 @@ function pad(num: number) { /** * Custom logging utility for the bot. */ -export class BushLogger { +export class Logger { /** * @param client The client. */ diff --git a/lib/utils/Minecraft.ts b/lib/utils/Minecraft.ts index 50c44ef..e189b66 100644 --- a/lib/utils/Minecraft.ts +++ b/lib/utils/Minecraft.ts @@ -2,10 +2,6 @@ import { Byte, Int } from '@ironm00n/nbt-ts'; import { BitField } from 'discord.js'; -import path from 'path'; -import { fileURLToPath } from 'url'; - -const __dirname = path.dirname(fileURLToPath(import.meta.url)); export enum FormattingCodes { Black = '§0', diff --git a/lib/utils/Minecraft_Test.ts b/lib/utils/Minecraft_Test.ts index fce9d5b..7dae3f6 100644 --- a/lib/utils/Minecraft_Test.ts +++ b/lib/utils/Minecraft_Test.ts @@ -110,7 +110,7 @@ export class NeuItem { this.petLoreReplacements(); } - private petLoreReplacements(level = -1) { + private petLoreReplacements(_level = -1) { if (/.*?;[0-5]$/.test(this.internalName) && this.displayName.includes('LVL')) { const maxLevel = neuPets?.custom_pet_leveling?.[this.internalName]?.max_level ?? 100; this.displayName = this.displayName.replace('LVL', `1➡${maxLevel}`); @@ -122,14 +122,14 @@ export class NeuItem { const petInfoTier = nums[teir]; if (!petInfoTier) throw new Error(`Pet (${this.internalName}) has no pet nums for ${teir} rarity.`); - const curve = petInfoTier?.stats_levelling_curve?.split(';'); + // const curve = petInfoTier?.stats_levelling_curve?.split(';'); // todo: finish copying from neu - const minStatsLevel = parseInt(curve?.[0] ?? '0'); - const maxStatsLevel = parseInt(curve?.[0] ?? '100'); + // const minStatsLevel = parseInt(curve?.[0] ?? '0'); + // const maxStatsLevel = parseInt(curve?.[0] ?? '100'); - const lore = ''; + // const lore = ''; } } } diff --git a/lib/utils/BushUtils.ts b/lib/utils/Utils.ts index 1922204..f7404e1 100644 --- a/lib/utils/BushUtils.ts +++ b/lib/utils/Utils.ts @@ -1,12 +1,12 @@ import { Arg, - BushClient, CommandMessage, SlashEditMessageType, SlashSendMessageType, + TanzaniteClient, timeUnits, - type BaseBushArgumentType, - type BushInspectOptions, + type BaseBotArgumentType, + type CustomInspectOptions, type SlashMessage } from '#lib'; import { humanizeDuration as humanizeDurationMod } from '@notenoughupdates/humanize-duration'; @@ -117,7 +117,7 @@ export interface UuidRes { * @param options The options to create defaults with. * @returns The default options combined with the specified options. */ -function getDefaultInspectOptions(options?: BushInspectOptions): BushInspectOptions { +function getDefaultInspectOptions(options?: CustomInspectOptions): CustomInspectOptions { return { showHidden: options?.showHidden ?? false, depth: options?.depth ?? 2, @@ -140,7 +140,7 @@ function getDefaultInspectOptions(options?: BushInspectOptions): BushInspectOpti * @param options - The options you would like to use to inspect the object. * @returns The inspected object. */ -export function inspect(object: any, options?: BushInspectOptions): string { +export function inspect(object: any, options?: CustomInspectOptions): string { const optionsWithDefaults = getDefaultInspectOptions(options); if (!optionsWithDefaults.inspectStrings && typeof object === 'string') return object; @@ -497,7 +497,7 @@ export { AkairoUtil as akairo }; /** * The link to invite the bot with all permissions. */ -export function invite(client: BushClient) { +export function invite(client: TanzaniteClient) { return client.generateInvite({ permissions: PermissionsBitField.All - @@ -545,9 +545,9 @@ export interface ParsedDurationRes { * @param message The message that triggered the command. * @returns The casted argument. */ -export async function cast<T extends keyof BaseBushArgumentType>( +export async function cast<T extends keyof BaseBotArgumentType>( type: T, - arg: BaseBushArgumentType[T] | string, + arg: BaseBotArgumentType[T] | string, message: CommandMessage | SlashMessage ) { return typeof arg === 'string' ? await Arg.cast(type, message, arg) : arg; |