diff options
Diffstat (limited to 'src/lib/extensions')
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 89 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushCommand.ts | 8 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushCommandHandler.ts | 7 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushInhibitor.ts | 8 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/ExtendedGuild.ts | 48 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/ExtendedGuildMember.ts | 77 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/ExtendedMessage.ts | 2 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/ExtendedUser.ts | 4 | ||||
-rw-r--r-- | src/lib/extensions/global.ts | 8 |
9 files changed, 160 insertions, 91 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index b382121..68b2599 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -63,7 +63,8 @@ import { Shared } from '../../models/shared/Shared.js'; import { Stat } from '../../models/shared/Stat.js'; import { AllowedMentions } from '../../utils/AllowedMentions.js'; import { BushCache } from '../../utils/BushCache.js'; -import BushLogger from '../../utils/BushLogger.js'; +import { BushClientUtils } from '../../utils/BushClientUtils.js'; +import { BushLogger } from '../../utils/BushLogger.js'; import { ExtendedGuild } from '../discord.js/ExtendedGuild.js'; import { ExtendedGuildMember } from '../discord.js/ExtendedGuildMember.js'; import { ExtendedMessage } from '../discord.js/ExtendedMessage.js'; @@ -76,14 +77,44 @@ const { Sequelize } = (await import('sequelize')).default; declare module 'discord.js' { export interface Client extends EventEmitter { - /** - * The ID of the owner(s). - */ + /** The ID of the owner(s). */ ownerID: Snowflake | Snowflake[]; - /** - * The ID of the superUser(s). - */ + /** The ID of the superUser(s). */ superUserID: Snowflake | Snowflake[]; + /** Whether or not the client is ready. */ + customReady: boolean; + /** The configuration for the client. */ + config: Config; + /** Stats for the client. */ + stats: BushStats; + /** The handler for the bot's listeners. */ + listenerHandler: BushListenerHandler; + /** The handler for the bot's command inhibitors. */ + inhibitorHandler: BushInhibitorHandler; + /** The handler for the bot's commands. */ + commandHandler: BushCommandHandler; + /** The handler for the bot's tasks. */ + taskHandler: BushTaskHandler; + /** The handler for the bot's context menu commands. */ + contextMenuCommandHandler: ContextMenuCommandHandler; + /** The database connection for this instance of the bot (production, beta, or development). */ + instanceDB: SequelizeType; + /** The database connection that is shared between all instances of the bot. */ + sharedDB: SequelizeType; + /** A custom logging system for the bot. */ + logger: BushLogger; + /** Cached global and guild database data. */ + cache: BushCache; + /** Sentry error reporting for the bot. */ + sentry: typeof Sentry; + /** Manages most aspects of the highlight command */ + highlightManager: HighlightManager; + /** The perspective api */ + perspective: any; + /** Client utilities. */ + utils: BushClientUtils; + /** 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; @@ -126,72 +157,77 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * Whether or not the client is ready. */ - public customReady = false; + public override customReady = false; /** * Stats for the client. */ - public stats: BushStats = { cpu: undefined, commandsUsed: 0n, slashCommandsUsed: 0n }; + public override stats: BushStats = { cpu: undefined, commandsUsed: 0n, slashCommandsUsed: 0n }; /** * The handler for the bot's listeners. */ - public listenerHandler: BushListenerHandler; + public override listenerHandler: BushListenerHandler; /** * The handler for the bot's command inhibitors. */ - public inhibitorHandler: BushInhibitorHandler; + public override inhibitorHandler: BushInhibitorHandler; /** * The handler for the bot's commands. */ - public commandHandler: BushCommandHandler; + public override commandHandler: BushCommandHandler; /** * The handler for the bot's tasks. */ - public taskHandler: BushTaskHandler; + public override taskHandler: BushTaskHandler; /** * The handler for the bot's context menu commands. */ - public contextMenuCommandHandler: ContextMenuCommandHandler; + public override contextMenuCommandHandler: ContextMenuCommandHandler; /** * The database connection for this instance of the bot (production, beta, or development). */ - public instanceDB: SequelizeType; + public override instanceDB: SequelizeType; /** * The database connection that is shared between all instances of the bot. */ - public sharedDB: SequelizeType; + public override sharedDB: SequelizeType; /** * A custom logging system for the bot. */ - public logger = BushLogger; + public override logger: BushLogger; /** * Cached global and guild database data. */ - public cache = new BushCache(); + public override cache = new BushCache(); /** * Sentry error reporting for the bot. */ - public sentry!: typeof Sentry; + public override sentry!: typeof Sentry; /** * Manages most aspects of the highlight command */ - public highlightManager = new HighlightManager(); + public override highlightManager = new HighlightManager(); /** * The perspective api */ - public perspective: any; + public override perspective: any; + + /** + * Client utilities. + */ + public override utils: BushClientUtils; /** * @param config The configuration for the bot. @@ -200,7 +236,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * The configuration for the client. */ - public config: Config + public override config: Config ) { super({ ownerID: config.owners, @@ -220,7 +256,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re patch(this); this.token = config.token as If<Ready, string, string | null>; - this.config = config; + this.logger = new BushLogger(this); + this.utils = new BushClientUtils(this); /* =-=-= handlers =-=-= */ this.listenerHandler = new BushListenerHandler(this, { @@ -320,7 +357,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** * A custom logging system for the bot. */ - public get console(): typeof BushLogger { + public override get console(): BushLogger { return this.logger; } @@ -474,7 +511,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re await this.highlightManager.syncCache(); await UpdateCacheTask.init(this); void this.console.success('startup', `Successfully created <<cache>>.`, false); - const stats = await UpdateStatsTask.init(); + const stats = await UpdateStatsTask.init(this); this.stats.commandsUsed = stats.commandsUsed; this.stats.slashCommandsUsed = stats.slashCommandsUsed; await this.login(this.token!); @@ -500,7 +537,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re public override isSuperUser(user: UserResolvable): boolean { const userID = this.users.resolveId(user)!; - return client.cache.shared.superUsers.includes(userID) || this.config.owners.includes(userID); + return this.cache.shared.superUsers.includes(userID) || this.config.owners.includes(userID); } } diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 5fb4e06..414da09 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -34,6 +34,8 @@ import { Message, User, type ApplicationCommandOptionChoiceData, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + type ApplicationCommandOptionType, type PermissionResolvable, type PermissionsString, type Snowflake @@ -93,7 +95,7 @@ interface BaseBushArgumentOptions extends Omit<ArgumentOptions, 'type' | 'prompt /** * Allows you to get a discord resolved object * - * ex. get the resolved member object when the type is `USER` + * ex. get the resolved member object when the type is {@link ApplicationCommandOptionType.User User} */ slashResolve?: SlashResolveType; @@ -113,12 +115,12 @@ interface BaseBushArgumentOptions extends Omit<ArgumentOptions, 'type' | 'prompt channelTypes?: AkairoApplicationCommandChannelOptionData['channelTypes']; /** - * The minimum value for an `INTEGER` or `NUMBER` option + * The minimum value for an {@link ApplicationCommandOptionType.Integer Integer} or {@link ApplicationCommandOptionType.Number Number} option */ minValue?: number; /** - * The maximum value for an `INTEGER` or `NUMBER` option + * The maximum value for an {@link ApplicationCommandOptionType.Integer Integer} or {@link ApplicationCommandOptionType.Number Number} option */ maxValue?: number; } diff --git a/src/lib/extensions/discord-akairo/BushCommandHandler.ts b/src/lib/extensions/discord-akairo/BushCommandHandler.ts index f095356..da49af9 100644 --- a/src/lib/extensions/discord-akairo/BushCommandHandler.ts +++ b/src/lib/extensions/discord-akairo/BushCommandHandler.ts @@ -1,4 +1,4 @@ -import { type BushClient, type BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +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'; @@ -28,13 +28,8 @@ export interface BushCommandHandlerEvents extends CommandHandlerEvents { } export class BushCommandHandler extends CommandHandler { - public declare client: BushClient; public declare modules: Collection<string, BushCommand>; public declare categories: Collection<string, Category<string, BushCommand>>; - - public constructor(client: BushClient, options: CommandHandlerOptions) { - super(client, options); - } } export interface BushCommandHandler extends CommandHandler { diff --git a/src/lib/extensions/discord-akairo/BushInhibitor.ts b/src/lib/extensions/discord-akairo/BushInhibitor.ts index b4e6797..be396cf 100644 --- a/src/lib/extensions/discord-akairo/BushInhibitor.ts +++ b/src/lib/extensions/discord-akairo/BushInhibitor.ts @@ -1,15 +1,15 @@ -import { type BushClient, type BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { type BushCommand, 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 { - public declare client: BushClient; - /** * Checks if message should be blocked. * A return value of true will block the message. * If returning a Promise, a resolved value of true will block the message. * - * **Note:** `all` type inhibitors do not have `message.util` defined. + * **Note:** `'all'` type inhibitors do not have {@link Message.util} defined. * * @param message - Message being handled. * @param command - Command to check. diff --git a/src/lib/extensions/discord.js/ExtendedGuild.ts b/src/lib/extensions/discord.js/ExtendedGuild.ts index c199899..c58916c 100644 --- a/src/lib/extensions/discord.js/ExtendedGuild.ts +++ b/src/lib/extensions/discord.js/ExtendedGuild.ts @@ -41,7 +41,7 @@ import _ from 'lodash'; import * as Moderation from '../../common/util/Moderation.js'; import { Guild as GuildDB } from '../../models/instance/Guild.js'; import { ModLogType } from '../../models/instance/ModLog.js'; -import { addOrRemoveFromArray, resolveNonCachedUser } from '../../utils/BushUtils.js'; +import { addOrRemoveFromArray } from '../../utils/BushUtils.js'; declare module 'discord.js' { export interface Guild { @@ -187,7 +187,7 @@ export class ExtendedGuild extends Guild { */ public override async getSetting<K extends keyof GuildModel>(setting: K): Promise<GuildModel[K]> { return ( - client.cache.guilds.get(this.id)?.[setting] ?? + this.client.cache.guilds.get(this.id)?.[setting] ?? ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }))[setting] ); } @@ -206,8 +206,8 @@ export class ExtendedGuild extends Guild { const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }); const oldValue = row[setting] as GuildDB[K]; row[setting] = value; - client.cache.guilds.set(this.id, row.toJSON() as GuildDB); - client.emit('bushUpdateSettings', setting, this, oldValue, row[setting], moderator); + this.client.cache.guilds.set(this.id, row.toJSON() as GuildDB); + this.client.emit('bushUpdateSettings', setting, this, oldValue, row[setting], moderator); return await row.save(); } @@ -253,7 +253,7 @@ export class ExtendedGuild extends Guild { * @param message The description of the error embed */ public override async error(title: string, message: string): Promise<void> { - void client.console.info(_.camelCase(title), message.replace(/\*\*(.*?)\*\*/g, '<<$1>>')); + void this.client.console.info(_.camelCase(title), message.replace(/\*\*(.*?)\*\*/g, '<<$1>>')); void this.sendLogChannel('error', { embeds: [{ title: title, description: message, color: colors.error }] }); } @@ -268,8 +268,8 @@ export class ExtendedGuild extends Guild { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const user = await resolveNonCachedUser(options.user); - const moderator = client.users.resolve(options.moderator ?? client.user!); + const user = await this.client.utils.resolveNonCachedUser(options.user); + const moderator = this.client.users.resolve(options.moderator ?? this.client.user!); if (!user || !moderator) return banResponse.CANNOT_RESOLVE_USER; if ((await this.bans.fetch()).has(user.id)) return banResponse.ALREADY_BANNED; @@ -277,6 +277,7 @@ export class ExtendedGuild extends Guild { const ret = await (async () => { // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: options.duration ? ModLogType.TEMP_BAN : ModLogType.PERM_BAN, user: user, moderator: moderator.id, @@ -290,6 +291,7 @@ export class ExtendedGuild extends Guild { // dm user dmSuccessEvent = await Moderation.punishDM({ + client: this.client, modlog: modlog.id, guild: this, user: user, @@ -310,6 +312,7 @@ export class ExtendedGuild extends Guild { // add punishment entry so they can be unbanned later const punishmentEntrySuccess = await Moderation.createPunishmentEntry({ + client: this.client, type: 'ban', user: user, guild: this, @@ -323,7 +326,7 @@ export class ExtendedGuild extends Guild { })(); if (!([banResponse.ACTION_ERROR, banResponse.MODLOG_ERROR, banResponse.PUNISHMENT_ENTRY_ADD_ERROR] as const).includes(ret)) - client.emit( + this.client.emit( 'bushBan', user, moderator, @@ -352,6 +355,7 @@ export class ExtendedGuild extends Guild { const ret = await (async () => { // add modlog entry const { log: modlog } = await Moderation.createModLogEntrySimple({ + client: this.client, type: ModLogType.PERM_BAN, user: options.user, moderator: options.moderator, @@ -365,6 +369,7 @@ export class ExtendedGuild extends Guild { // dm user if (this.members.cache.has(options.user)) { dmSuccessEvent = await Moderation.punishDM({ + client: this.client, modlog: modlog.id, guild: this, user: options.user, @@ -386,6 +391,7 @@ export class ExtendedGuild extends Guild { // add punishment entry so they can be unbanned later const punishmentEntrySuccess = await Moderation.createPunishmentEntry({ + client: this.client, type: 'ban', user: options.user, guild: this, @@ -411,8 +417,8 @@ export class ExtendedGuild extends Guild { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const user = await resolveNonCachedUser(options.user); - const moderator = client.users.resolve(options.moderator ?? client.user!); + const user = await this.client.utils.resolveNonCachedUser(options.user); + const moderator = this.client.users.resolve(options.moderator ?? this.client.user!); if (!user || !moderator) return unbanResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -435,6 +441,7 @@ export class ExtendedGuild extends Guild { // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.UNBAN, user: user.id, moderator: moderator.id, @@ -447,6 +454,7 @@ export class ExtendedGuild extends Guild { // remove punishment entry const removePunishmentEntrySuccess = await Moderation.removePunishmentEntry({ + client: this.client, type: 'ban', user: user.id, guild: this @@ -455,6 +463,7 @@ export class ExtendedGuild extends Guild { // dm user dmSuccessEvent = await Moderation.punishDM({ + client: this.client, guild: this, user: user, punishment: 'unbanned', @@ -470,7 +479,16 @@ export class ExtendedGuild extends Guild { ret ) ) - client.emit('bushUnban', user, moderator, this, options.reason ?? undefined, caseID!, dmSuccessEvent!, options.evidence); + this.client.emit( + 'bushUnban', + user, + moderator, + this, + options.reason ?? undefined, + caseID!, + dmSuccessEvent!, + options.evidence + ); return ret; } @@ -549,7 +567,7 @@ export class ExtendedGuild extends Guild { else return `success: ${success.filter((c) => c === true).size}`; })(); - client.emit(options.unlock ? 'bushUnlockdown' : 'bushLockdown', moderator, options.reason, success, options.all); + this.client.emit(options.unlock ? 'bushUnlockdown' : 'bushLockdown', moderator, options.reason, success, options.all); return ret; } @@ -557,7 +575,7 @@ export class ExtendedGuild extends Guild { if (!channel.isTextBased() || channel.isDMBased() || channel.guildId !== this.id || !this.members.me) return null; if (!channel.permissionsFor(this.members.me).has('ManageWebhooks')) return null; - const quote = new Message(client, rawQuote); + const quote = new Message(this.client, rawQuote); const target = channel instanceof ThreadChannel ? channel.parent : channel; if (!target) return null; @@ -570,8 +588,8 @@ export class ExtendedGuild extends Guild { if (!webhook) webhook = await target .createWebhook({ - name: `${client.user!.username} Quotes #${target.name}`, - avatar: client.user!.displayAvatarURL({ size: 2048 }), + name: `${this.client.user!.username} Quotes #${target.name}`, + avatar: this.client.user!.displayAvatarURL({ size: 2048 }), reason: 'Creating a webhook for quoting' }) .catch(() => null); diff --git a/src/lib/extensions/discord.js/ExtendedGuildMember.ts b/src/lib/extensions/discord.js/ExtendedGuildMember.ts index ad29236..947f9cd 100644 --- a/src/lib/extensions/discord.js/ExtendedGuildMember.ts +++ b/src/lib/extensions/discord.js/ExtendedGuildMember.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { BushClientEvents, formatError, Moderation, ModLogType, PunishmentTypeDM, resolveNonCachedUser, Time } from '#lib'; +import { BushClientEvents, formatError, Moderation, ModLogType, PunishmentTypeDM, Time } from '#lib'; import { ChannelType, GuildChannelResolvable, @@ -129,6 +129,7 @@ export class ExtendedGuildMember extends GuildMember { sendFooter = true ): Promise<boolean> { return Moderation.punishDM({ + client: this.client, modlog, guild: this.guild, user: this, @@ -148,13 +149,14 @@ export class ExtendedGuildMember extends GuildMember { public override async bushWarn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }> { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return { result: warnResponse.CANNOT_RESOLVE_USER, caseNum: null }; const ret = await (async (): Promise<{ result: WarnResponse; caseNum: number | null }> => { // add modlog entry const result = await Moderation.createModLogEntry( { + client: this.client, type: ModLogType.WARN, user: this, moderator: moderator.id, @@ -178,7 +180,7 @@ export class ExtendedGuildMember extends GuildMember { return { result: warnResponse.SUCCESS, caseNum: result.caseNum }; })(); if (!([warnResponse.MODLOG_ERROR] as const).includes(ret.result) && !options.silent) - client.emit('bushWarn', this, moderator, this.guild, options.reason ?? undefined, caseID!, dmSuccessEvent!); + this.client.emit('bushWarn', this, moderator, this.guild, options.reason ?? undefined, caseID!, dmSuccessEvent!); return ret; } @@ -195,12 +197,13 @@ export class ExtendedGuildMember extends GuildMember { if (ifShouldAddRole !== true) return ifShouldAddRole; let caseID: string | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return addRoleResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { if (options.addToModlog || options.duration) { const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: options.duration ? ModLogType.TEMP_PUNISHMENT_ROLE : ModLogType.PERM_PUNISHMENT_ROLE, guild: this.guild, moderator: moderator.id, @@ -216,6 +219,7 @@ export class ExtendedGuildMember extends GuildMember { if (options.addToModlog || options.duration) { const punishmentEntrySuccess = await Moderation.createPunishmentEntry({ + client: this.client, type: 'role', user: this, guild: this.guild, @@ -239,7 +243,7 @@ export class ExtendedGuildMember extends GuildMember { options.addToModlog && !options.silent ) - client.emit( + this.client.emit( 'bushPunishRole', this, moderator, @@ -266,12 +270,13 @@ export class ExtendedGuildMember extends GuildMember { if (ifShouldAddRole !== true) return ifShouldAddRole; let caseID: string | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return removeRoleResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { if (options.addToModlog) { const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.REMOVE_PUNISHMENT_ROLE, guild: this.guild, moderator: moderator.id, @@ -285,6 +290,7 @@ export class ExtendedGuildMember extends GuildMember { caseID = modlog.id; const punishmentEntrySuccess = await Moderation.removePunishmentEntry({ + client: this.client, type: 'role', user: this, guild: this.guild, @@ -311,7 +317,7 @@ export class ExtendedGuildMember extends GuildMember { options.addToModlog && !options.silent ) - client.emit( + this.client.emit( 'bushPunishRoleRemove', this, moderator, @@ -362,7 +368,7 @@ export class ExtendedGuildMember extends GuildMember { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return muteResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -370,14 +376,15 @@ export class ExtendedGuildMember extends GuildMember { const muteSuccess = await this.roles .add(muteRole, `[Mute] ${moderator.tag} | ${options.reason ?? 'No reason provided.'}`) .catch(async (e) => { - await client.console.warn('muteRoleAddError', e); - client.console.debug(e); + await this.client.console.warn('muteRoleAddError', e); + this.client.console.debug(e); return false; }); if (!muteSuccess) return muteResponse.ACTION_ERROR; // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: options.duration ? ModLogType.TEMP_MUTE : ModLogType.PERM_MUTE, user: this, moderator: moderator.id, @@ -393,6 +400,7 @@ export class ExtendedGuildMember extends GuildMember { // add punishment entry so they can be unmuted later const punishmentEntrySuccess = await Moderation.createPunishmentEntry({ + client: this.client, type: 'mute', user: this, guild: this.guild, @@ -416,7 +424,7 @@ export class ExtendedGuildMember extends GuildMember { !([muteResponse.ACTION_ERROR, muteResponse.MODLOG_ERROR, muteResponse.PUNISHMENT_ENTRY_ADD_ERROR] as const).includes(ret) && !options.silent ) - client.emit( + this.client.emit( 'bushMute', this, moderator, @@ -448,7 +456,7 @@ export class ExtendedGuildMember extends GuildMember { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return unmuteResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -456,13 +464,14 @@ export class ExtendedGuildMember extends GuildMember { const muteSuccess = await this.roles .remove(muteRole, `[Unmute] ${moderator.tag} | ${options.reason ?? 'No reason provided.'}`) .catch(async (e) => { - await client.console.warn('muteRoleAddError', formatError(e, true)); + await this.client.console.warn('muteRoleAddError', formatError(e, true)); return false; }); if (!muteSuccess) return unmuteResponse.ACTION_ERROR; // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.UNMUTE, user: this, moderator: moderator.id, @@ -477,6 +486,7 @@ export class ExtendedGuildMember extends GuildMember { // remove mute entry const removePunishmentEntrySuccess = await Moderation.removePunishmentEntry({ + client: this.client, type: 'mute', user: this, guild: this.guild @@ -500,7 +510,7 @@ export class ExtendedGuildMember extends GuildMember { ).includes(ret) && !options.silent ) - client.emit( + this.client.emit( 'bushUnmute', this, moderator, @@ -526,11 +536,12 @@ export class ExtendedGuildMember extends GuildMember { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return kickResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.KICK, user: this, moderator: moderator.id, @@ -554,7 +565,7 @@ export class ExtendedGuildMember extends GuildMember { return kickResponse.SUCCESS; })(); if (!([kickResponse.ACTION_ERROR, kickResponse.MODLOG_ERROR] as const).includes(ret) && !options.silent) - client.emit( + this.client.emit( 'bushKick', this, moderator, @@ -580,7 +591,7 @@ export class ExtendedGuildMember extends GuildMember { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return banResponse.CANNOT_RESOLVE_USER; // ignore result, they should still be banned even if their mute cannot be removed @@ -593,6 +604,7 @@ export class ExtendedGuildMember extends GuildMember { const ret = await (async () => { // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: options.duration ? ModLogType.TEMP_BAN : ModLogType.PERM_BAN, user: this, moderator: moderator.id, @@ -620,6 +632,7 @@ export class ExtendedGuildMember extends GuildMember { // add punishment entry so they can be unbanned later const punishmentEntrySuccess = await Moderation.createPunishmentEntry({ + client: this.client, type: 'ban', user: this, guild: this.guild, @@ -635,7 +648,7 @@ export class ExtendedGuildMember extends GuildMember { !([banResponse.ACTION_ERROR, banResponse.MODLOG_ERROR, banResponse.PUNISHMENT_ENTRY_ADD_ERROR] as const).includes(ret) && !options.silent ) - client.emit( + this.client.emit( 'bushBan', this, moderator, @@ -663,7 +676,7 @@ export class ExtendedGuildMember extends GuildMember { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return blockResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -677,6 +690,7 @@ export class ExtendedGuildMember extends GuildMember { // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: options.duration ? ModLogType.TEMP_CHANNEL_BLOCK : ModLogType.PERM_CHANNEL_BLOCK, user: this, moderator: moderator.id, @@ -690,6 +704,7 @@ export class ExtendedGuildMember extends GuildMember { // add punishment entry so they can be unblocked later const punishmentEntrySuccess = await Moderation.createPunishmentEntry({ + client: this.client, type: 'block', user: this, guild: this.guild, @@ -703,6 +718,7 @@ export class ExtendedGuildMember extends GuildMember { const dmSuccess = options.silent ? null : await Moderation.punishDM({ + client: this.client, punishment: 'blocked', reason: options.reason ?? undefined, duration: options.duration ?? 0, @@ -724,7 +740,7 @@ export class ExtendedGuildMember extends GuildMember { ) && !options.silent ) - client.emit( + this.client.emit( 'bushBlock', this, moderator, @@ -754,7 +770,7 @@ export class ExtendedGuildMember extends GuildMember { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return unblockResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -768,6 +784,7 @@ export class ExtendedGuildMember extends GuildMember { // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.CHANNEL_UNBLOCK, user: this, moderator: moderator.id, @@ -781,6 +798,7 @@ export class ExtendedGuildMember extends GuildMember { // remove punishment entry const punishmentEntrySuccess = await Moderation.removePunishmentEntry({ + client: this.client, type: 'block', user: this, guild: this.guild, @@ -792,6 +810,7 @@ export class ExtendedGuildMember extends GuildMember { const dmSuccess = options.silent ? null : await Moderation.punishDM({ + client: this.client, punishment: 'unblocked', reason: options.reason ?? undefined, guild: this.guild, @@ -812,7 +831,7 @@ export class ExtendedGuildMember extends GuildMember { !([unblockResponse.ACTION_ERROR, unblockResponse.MODLOG_ERROR, unblockResponse.ACTION_ERROR] as const).includes(ret) && !options.silent ) - client.emit( + this.client.emit( 'bushUnblock', this, moderator, @@ -839,7 +858,7 @@ export class ExtendedGuildMember extends GuildMember { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return timeoutResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -852,6 +871,7 @@ export class ExtendedGuildMember extends GuildMember { // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.TIMEOUT, user: this, moderator: moderator.id, @@ -876,7 +896,7 @@ export class ExtendedGuildMember extends GuildMember { })(); if (!([timeoutResponse.ACTION_ERROR, timeoutResponse.MODLOG_ERROR] as const).includes(ret) && !options.silent) - client.emit( + this.client.emit( 'bushTimeout', this, moderator, @@ -901,7 +921,7 @@ export class ExtendedGuildMember extends GuildMember { let caseID: string | undefined = undefined; let dmSuccessEvent: boolean | undefined = undefined; - const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me); + const moderator = await this.client.utils.resolveNonCachedUser(options.moderator ?? this.guild.members.me); if (!moderator) return removeTimeoutResponse.CANNOT_RESOLVE_USER; const ret = await (async () => { @@ -913,6 +933,7 @@ export class ExtendedGuildMember extends GuildMember { // add modlog entry const { log: modlog } = await Moderation.createModLogEntry({ + client: this.client, type: ModLogType.REMOVE_TIMEOUT, user: this, moderator: moderator.id, @@ -936,7 +957,7 @@ export class ExtendedGuildMember extends GuildMember { })(); if (!([removeTimeoutResponse.ACTION_ERROR, removeTimeoutResponse.MODLOG_ERROR] as const).includes(ret) && !options.silent) - client.emit( + this.client.emit( 'bushRemoveTimeout', this, moderator, @@ -953,14 +974,14 @@ export class ExtendedGuildMember extends GuildMember { * Whether or not the user is an owner of the bot. */ public override isOwner(): boolean { - return client.isOwner(this); + return this.client.isOwner(this); } /** * Whether or not the user is a super user of the bot. */ public override isSuperUser(): boolean { - return client.isSuperUser(this); + return this.client.isSuperUser(this); } } diff --git a/src/lib/extensions/discord.js/ExtendedMessage.ts b/src/lib/extensions/discord.js/ExtendedMessage.ts index 4431077..0d8ce37 100644 --- a/src/lib/extensions/discord.js/ExtendedMessage.ts +++ b/src/lib/extensions/discord.js/ExtendedMessage.ts @@ -7,6 +7,6 @@ export class ExtendedMessage<Cached extends boolean = boolean> extends Message<C public constructor(client_: Client, data: RawMessageData) { super(client_, data); - this.util = new CommandUtil(client.commandHandler, this); + this.util = new CommandUtil(this.client.commandHandler, this); } } diff --git a/src/lib/extensions/discord.js/ExtendedUser.ts b/src/lib/extensions/discord.js/ExtendedUser.ts index 556ab85..23de523 100644 --- a/src/lib/extensions/discord.js/ExtendedUser.ts +++ b/src/lib/extensions/discord.js/ExtendedUser.ts @@ -23,13 +23,13 @@ export class ExtendedUser extends User { * Indicates whether the user is an owner of the bot. */ public override isOwner(): boolean { - return client.isOwner(this); + return this.client.isOwner(this); } /** * Indicates whether the user is a superuser of the bot. */ public override isSuperUser(): boolean { - return client.isSuperUser(this); + return this.client.isSuperUser(this); } } diff --git a/src/lib/extensions/global.ts b/src/lib/extensions/global.ts index d9cfaec..a9020d7 100644 --- a/src/lib/extensions/global.ts +++ b/src/lib/extensions/global.ts @@ -1,11 +1,5 @@ /* eslint-disable no-var */ -import type { BushClient } from '#lib'; declare global { - /** - * The bushbot client. - */ - var client: BushClient; - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface ReadonlyArray<T> { includes<S, R extends `${Extract<S, string>}`>( @@ -15,3 +9,5 @@ declare global { ): searchElement is R & S; } } + +export {}; |