diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 15 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 74 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushCommand.ts | 15 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushListener.ts | 2 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushTask.ts | 2 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuild.ts | 6 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushGuildMember.ts | 47 | ||||
-rw-r--r-- | src/lib/extensions/discord.js/BushMessage.ts | 2 | ||||
-rw-r--r-- | src/lib/models/ActivePunishment.ts | 2 | ||||
-rw-r--r-- | src/lib/models/ModLog.ts | 4 | ||||
-rw-r--r-- | src/lib/utils/BushConstants.ts | 22 | ||||
-rw-r--r-- | src/lib/utils/BushLogger.ts | 2 | ||||
-rw-r--r-- | src/lib/utils/CanvasProgressBar.ts | 4 |
13 files changed, 109 insertions, 88 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 5b9ac1b..3feae96 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -2,7 +2,6 @@ import chalk from 'chalk'; import { AkairoClient } from 'discord-akairo'; import { Collection, - Guild, Intents, InteractionReplyOptions, Message, @@ -182,7 +181,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re // Create command handler this.commandHandler = new BushCommandHandler(this, { directory: path.join(__dirname, '..', '..', '..', 'commands'), - prefix: async ({ guild }: { guild: Guild }) => { + prefix: async ({ guild }: Message) => { if (this.config.isDevelopment) return 'dev '; if (!guild) return this.config.prefix; const row = await GuildModel.findByPk(guild.id); @@ -262,7 +261,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re }; for (const loader of Object.keys(loaders)) { try { - loaders[loader].loadAll(); + loaders[loader as keyof typeof loaders].loadAll(); void this.logger.success('Startup', `Successfully loaded <<${loader}>>.`, false); } catch (e) { void this.logger.error('Startup', `Unable to load loader <<${loader}>> with error:\n${e?.stack || e}`, false); @@ -271,7 +270,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re await this.dbPreInit(); await UpdateCacheTask.init(this); void this.console.success('Startup', `Successfully created <<cache>>.`, false); - this.taskHandler.startAll(); + this.taskHandler.startAll!(); } public async dbPreInit(): Promise<void> { @@ -302,7 +301,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re try { await this.#init(); - await this.login(this.token); + await this.login(this.token!); } catch (e) { await this.console.error('Start', chalk.red(e?.stack || e), false); exit(2); @@ -313,15 +312,15 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re public override destroy(relogin = false): void | Promise<string> { super.destroy(); if (relogin) { - return this.login(this.token); + return this.login(this.token!); } } public override isOwner(user: BushUserResolvable): boolean { - return this.config.owners.includes(this.users.resolveId(user)); + return this.config.owners.includes(this.users.resolveId(user!)!); } public override isSuperUser(user: BushUserResolvable): boolean { - const userID = this.users.resolveId(user); + const userID = this.users.resolveId(user)!; return !!BushCache?.global?.superUsers?.includes(userID) || this.config.owners.includes(userID); } } diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 4f9f09b..88985e1 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -597,7 +597,7 @@ export class BushClientUtil extends ClientUtil { const mentionMatch = text.match(mentionReg); if (mentionMatch) { try { - return await client.users.fetch(mentionMatch.groups.id as Snowflake); + return await client.users.fetch(mentionMatch.groups!.id as Snowflake); } catch { // pass } @@ -626,8 +626,8 @@ export class BushClientUtil extends ClientUtil { */ public chunk<T>(arr: T[], perChunk: number): T[][] { return arr.reduce((all, one, i) => { - const ch = Math.floor(i / perChunk); - all[ch] = [].concat(all[ch] || [], one); + const ch: number = Math.floor(i / perChunk); + (all as any[])[ch] = [].concat(all[ch] || [], one as any); return all; }, []); } @@ -668,7 +668,11 @@ export class BushClientUtil extends ClientUtil { mad: '<:mad:783046135392239626>', join: '<:join:850198029809614858>', leave: '<:leave:850198048205307919>', - loading: '<a:Loading:853419254619963392>' + loading: '<a:Loading:853419254619963392>', + offlineCircle: '<:offline:787550565382750239>', + dndCircle: '<:dnd:787550487633330176>', + idleCircle: '<:idle:787550520956551218>', + onlineCircle: '<:online:787550449435803658>' }; /** @@ -716,6 +720,7 @@ export class BushClientUtil extends ClientUtil { let curPage = 0; if (typeof embeds !== 'object') throw new Error('embeds must be an object'); const msg = (await message.util.reply({ + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing content: text || null, embeds: [embeds[curPage]], components: [getPaginationRow()] @@ -886,7 +891,7 @@ export class BushClientUtil extends ClientUtil { ['betaToken']: 'Beta Token', ['hypixelApiKey']: 'Hypixel Api Key' }; - return mapping[old] || old; + return mapping[old as keyof typeof mapping] || old; } /** @@ -894,7 +899,7 @@ export class BushClientUtil extends ClientUtil { */ public redact(text: string) { for (const credentialName in client.config.credentials) { - const credential = client.config.credentials[credentialName]; + const credential = client.config.credentials[credentialName as keyof typeof client.config.credentials]; const replacement = this.#mapCredential(credentialName); const escapeRegex = /[.*+?^${}()|[\]\\]/g; text = text.replace(new RegExp(credential.toString().replace(escapeRegex, '\\$&'), 'g'), `[${replacement} Omitted]`); @@ -908,7 +913,7 @@ export class BushClientUtil extends ClientUtil { public async inspectCleanRedactCodeblock( input: any, - language: CodeBlockLang, + language?: CodeBlockLang, inspectOptions?: BushInspectOptions, length = 1024 ) { @@ -950,7 +955,7 @@ export class BushClientUtil extends ClientUtil { public async slashRespond( interaction: CommandInteraction, responseOptions: BushSlashSendMessageType | BushSlashEditMessageType - ): Promise<Message | APIMessage> { + ): Promise<Message | APIMessage | undefined> { let newResponseOptions: BushSlashSendMessageType | BushSlashEditMessageType = {}; if (typeof responseOptions === 'string') { newResponseOptions.content = responseOptions; @@ -985,7 +990,7 @@ export class BushClientUtil extends ClientUtil { * const permissions = oxford(['ADMINISTRATOR', 'SEND_MESSAGES', 'MANAGE_MESSAGES'], 'and', 'none'); * console.log(permissions); // ADMINISTRATOR, SEND_MESSAGES and MANAGE_MESSAGES */ - public oxford(array: string[], conjunction: string, ifEmpty: string): string { + public oxford(array: string[], conjunction: string, ifEmpty?: string): string | undefined { const l = array.length; if (!l) return ifEmpty; if (l < 2) return array[0]; @@ -1000,7 +1005,8 @@ export class BushClientUtil extends ClientUtil { key: keyof typeof BushCache['global'], value: any ): Promise<Global | void> { - const row = await Global.findByPk(client.config.environment); + const row = + (await Global.findByPk(client.config.environment)) ?? (await Global.create({ environment: client.config.environment })); const oldValue: any[] = row[key]; const newValue = this.addOrRemoveFromArray(action, oldValue, value); row[key] = newValue; @@ -1010,7 +1016,7 @@ export class BushClientUtil extends ClientUtil { public addOrRemoveFromArray(action: 'add' | 'remove', array: any[], value: any): any[] { let newValue: any[]; - if (!array) return null; + if (!array) throw new Error('array is either null or undefined'); if (action === 'add') { if (!array.includes(action)) array.push(value); newValue = array; @@ -1029,14 +1035,14 @@ export class BushClientUtil extends ClientUtil { * @returns {string[]} */ public surroundArray(array: string[], surroundChar1: string, surroundChar2?: string): string[] { - const newArray = []; + const newArray: string[] = []; array.forEach((a) => { - newArray.push(`${surroundChar1}${a}${surroundChar2 || surroundChar1}`); + newArray.push(`${surroundChar1}${a}${surroundChar2 ?? surroundChar1}`); }); return newArray; } - public parseDuration(content: string, remove = true): { duration: number; contentWithoutTime: string } { + public parseDuration(content: string, remove = true): { duration: number; contentWithoutTime: string | null } { if (!content) return { duration: 0, contentWithoutTime: null }; let duration = 0; @@ -1047,6 +1053,7 @@ export class BushClientUtil extends ClientUtil { for (const unit in BushConstants.TimeUnits) { const regex = BushConstants.TimeUnits[unit].match; const match = regex.exec(contentWithoutTime); + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const value = Number(match?.groups?.[unit] || 0); duration += value * BushConstants.TimeUnits[unit].value; @@ -1086,7 +1093,7 @@ export class BushClientUtil extends ClientUtil { if (moderator.roles.highest.position <= victim.roles.highest.position && !isOwner) { return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they have higher or equal role hierarchy as you do.`; } - if (victim.roles.highest.position >= victim.guild.me.roles.highest.position) { + if (victim.roles.highest.position >= victim.guild.me!.roles.highest.position) { return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they have higher or equal role hierarchy as I do.`; } if (checkModerator && victim.permissions.has('MANAGE_MESSAGES')) { @@ -1100,16 +1107,17 @@ export class BushClientUtil extends ClientUtil { type: ModLogType; user: BushGuildMemberResolvable; moderator: BushGuildMemberResolvable; - reason: string; + reason: string | undefined; duration?: number; guild: BushGuildResolvable; }, getCaseNumber = false - ): Promise<{ log: ModLog; caseNum: number }> { - const user = client.users.resolveId(options.user); - const moderator = client.users.resolveId(options.moderator); - const guild = client.guilds.resolveId(options.guild); - const duration = options.duration || null; + ): Promise<{ log: ModLog | null; caseNum: number | null }> { + const user = client.users.resolveId(options.user)!; + const moderator = client.users.resolveId(options.moderator)!; + const guild = client.guilds.resolveId(options.guild)!; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const duration = options.duration || undefined; // If guild does not exist create it so the modlog can reference a guild. await Guild.findOrCreate({ @@ -1129,7 +1137,7 @@ export class BushClientUtil extends ClientUtil { duration: duration, guild }); - const saveResult: ModLog = await modLogEntry.save().catch((e) => { + const saveResult: ModLog | null = await modLogEntry.save().catch((e) => { void client.console.error('createModLogEntry', e?.stack || e); return null; }); @@ -1143,15 +1151,15 @@ export class BushClientUtil extends ClientUtil { public async createPunishmentEntry(options: { type: 'mute' | 'ban' | 'role' | 'block'; user: BushGuildMemberResolvable; - duration: number; + duration: number | undefined; guild: BushGuildResolvable; modlog: string; extraInfo?: Snowflake; - }): Promise<ActivePunishment> { - const expires = options.duration ? new Date(new Date().getTime() + options.duration) : null; - const user = client.users.resolveId(options.user); - const guild = client.guilds.resolveId(options.guild); - const type = this.#findTypeEnum(options.type); + }): Promise<ActivePunishment | null> { + const expires = options.duration ? new Date(new Date().getTime() + options.duration) : undefined; + const user = client.users.resolveId(options.user)!; + const guild = client.guilds.resolveId(options.guild)!; + const type = this.#findTypeEnum(options.type)!; const entry = options.extraInfo ? ActivePunishment.build({ user, type, guild, expires, modlog: options.modlog, extraInfo: options.extraInfo }) @@ -1266,7 +1274,7 @@ export class BushClientUtil extends ClientUtil { * @param types - Types to use. */ public compose(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.compose(types); + return Argument.compose(...types); } /** @@ -1275,7 +1283,7 @@ export class BushClientUtil extends ClientUtil { * @param types - Types to use. */ public composeWithFailure(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.composeWithFailure(types); + return Argument.composeWithFailure(...types); } /** @@ -1292,7 +1300,7 @@ export class BushClientUtil extends ClientUtil { * @param types - Types to use. */ public product(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.product(types); + return Argument.product(...types); } /** @@ -1323,7 +1331,7 @@ export class BushClientUtil extends ClientUtil { * @param types - Types to use. */ public taggedUnion(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.taggedUnion(types); + return Argument.taggedUnion(...types); } /** @@ -1342,7 +1350,7 @@ export class BushClientUtil extends ClientUtil { * @param types - Types to use. */ public union(...types: BushArgumentType[]): ArgumentTypeCaster { - return Argument.union(types); + return Argument.union(...types); } /** diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 9f91905..0eaa5e0 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -127,7 +127,7 @@ export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { * A regular expression can also be used. * The evaluated argument will be an object containing the `match` and `matches` if global. */ - customType?: ArgumentTypeCaster | (string | string[])[] | RegExp | string; + customType?: ArgumentTypeCaster | (string | string[])[] | RegExp | string | null; } export interface BushCommandOptions extends CommandOptions { @@ -163,22 +163,23 @@ export class BushCommand extends Command { /** Completely hide this command from the help command. */ public completelyHide: boolean; - public constructor(id: string, options?: BushCommandOptions) { + public constructor(id: string, options: BushCommandOptions) { if (options.args && typeof options.args !== 'function') { options.args.forEach((_, index: number) => { - if ('customType' in options.args[index]) { + if ('customType' in options.args![index]) { // @ts-expect-error: shut if (!options.args[index]['type']) options.args[index]['type'] = options.args[index]['customType']; - delete options.args[index]['customType']; + delete options.args![index]['customType']; } }); } super(id, options); this.options = options; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing this.hidden = options.hidden || false; - this.restrictedChannels = options.restrictedChannels; - this.restrictedGuilds = options.restrictedGuilds; - this.completelyHide = options.completelyHide; + this.restrictedChannels = options.restrictedChannels!; + this.restrictedGuilds = options.restrictedGuilds!; + this.completelyHide = options.completelyHide!; } public override exec(message: BushMessage, args: any): any; diff --git a/src/lib/extensions/discord-akairo/BushListener.ts b/src/lib/extensions/discord-akairo/BushListener.ts index 59b6162..b98bb02 100644 --- a/src/lib/extensions/discord-akairo/BushListener.ts +++ b/src/lib/extensions/discord-akairo/BushListener.ts @@ -5,7 +5,7 @@ export class BushListener extends Listener { public declare client: BushClient; public constructor( id: string, - options?: { emitter: string | EventEmitter; event: string; type?: 'on' | 'once'; category?: string } + options: { emitter: string | EventEmitter; event: string; type?: 'on' | 'once'; category?: string } ) { super(id, options); } diff --git a/src/lib/extensions/discord-akairo/BushTask.ts b/src/lib/extensions/discord-akairo/BushTask.ts index b315270..1b14a2b 100644 --- a/src/lib/extensions/discord-akairo/BushTask.ts +++ b/src/lib/extensions/discord-akairo/BushTask.ts @@ -3,7 +3,7 @@ import { BushClient } from './BushClient'; export class BushTask extends Task { public declare client: BushClient; - public constructor(id: string, options?: TaskOptions) { + public constructor(id: string, options: TaskOptions) { super(id, options); } } diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts index dafa1a4..81c0108 100644 --- a/src/lib/extensions/discord.js/BushGuild.ts +++ b/src/lib/extensions/discord.js/BushGuild.ts @@ -41,8 +41,8 @@ export class BushGuild extends Guild { | 'error creating modlog entry' | 'error removing ban entry' > { - const user = client.users.resolveId(options.user); - const moderator = client.users.cache.get(client.users.resolveId(options.moderator)); + const user = client.users.resolveId(options.user)!; + const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!)!; const bans = await this.bans.fetch(); @@ -50,6 +50,7 @@ export class BushGuild extends Guild { if (!bans.has(user)) notBanned = true; const unbanSuccess = await this.bans + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing .remove(user, `${moderator.tag} | ${options.reason || 'No reason provided.'}`) .catch((e) => { if (e?.code === 'UNKNOWN_BAN') { @@ -84,6 +85,7 @@ export class BushGuild extends Guild { const userObject = client.users.cache.get(user); + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing userObject?.send(`You have been unbanned from **${this}** for **${options.reason || 'No reason provided'}**.`); if (notBanned) return 'user not banned'; diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts index 7db31c5..641cc74 100644 --- a/src/lib/extensions/discord.js/BushGuildMember.ts +++ b/src/lib/extensions/discord.js/BushGuildMember.ts @@ -80,8 +80,8 @@ export class BushGuildMember extends GuildMember { super(client, data, guild); } - public async warn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number }> { - const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user; + public async warn(options: BushPunishmentOptions): Promise<{ result: WarnResponse | null; caseNum: number | null }> { + const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!; // add modlog entry const result = await util.createModLogEntry( { @@ -98,6 +98,7 @@ export class BushGuildMember extends GuildMember { // dm user const ending = await this.guild.getSetting('punishmentEnding'); const dmSuccess = await this.send({ + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing content: `You have been warned in **${this.guild}** for **${options.reason || 'No reason provided'}**.${ ending ? `\n\n${ending}` : '' }` @@ -112,7 +113,7 @@ export class BushGuildMember extends GuildMember { const ifShouldAddRole = this.#checkIfShouldAddRole(options.role); if (ifShouldAddRole !== true) return ifShouldAddRole; - const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user; + const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!; if (options.addToModlog) { const { log: modlog } = await util.createModLogEntry({ @@ -147,7 +148,7 @@ export class BushGuildMember extends GuildMember { const ifShouldAddRole = this.#checkIfShouldAddRole(options.role); if (ifShouldAddRole !== true) return ifShouldAddRole; - const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user; + const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!; if (options.addToModlog) { const { log: modlog } = await util.createModLogEntry({ @@ -180,7 +181,7 @@ export class BushGuildMember extends GuildMember { return 'user hierarchy'; } else if (role.managed) { return 'role managed'; - } else if (this.guild.me.roles.highest.position <= role.position) { + } else if (this.guild.me!.roles.highest.position <= role.position) { return 'client hierarchy'; } return true; @@ -188,17 +189,18 @@ export class BushGuildMember extends GuildMember { public async mute(options: BushTimedPunishmentOptions): Promise<MuteResponse> { // checks - if (!this.guild.me.permissions.has('MANAGE_ROLES')) return 'missing permissions'; + if (!this.guild.me!.permissions.has('MANAGE_ROLES')) return 'missing permissions'; const muteRoleID = await this.guild.getSetting('muteRole'); if (!muteRoleID) return 'no mute role'; const muteRole = this.guild.roles.cache.get(muteRoleID); if (!muteRole) return 'invalid mute role'; - if (muteRole.position >= this.guild.me.roles.highest.position || muteRole.managed) return 'mute role not manageable'; + if (muteRole.position >= this.guild.me!.roles.highest.position || muteRole.managed) return 'mute role not manageable'; - const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user; + const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!; // add role const muteSuccess = await this.roles + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing .add(muteRole, `[Mute] ${moderator.tag} | ${options.reason || 'No reason provided.'}`) .catch(async (e) => { await client.console.warn('muteRoleAddError', e?.stack || e); @@ -234,6 +236,7 @@ export class BushGuildMember extends GuildMember { const dmSuccess = await this.send({ content: `You have been muted ${ options.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently' + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing } in **${this.guild}** for **${options.reason || 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}` }).catch(() => false); @@ -244,17 +247,18 @@ export class BushGuildMember extends GuildMember { public async unmute(options: BushPunishmentOptions): Promise<UnmuteResponse> { //checks - if (!this.guild.me.permissions.has('MANAGE_ROLES')) return 'missing permissions'; + if (!this.guild.me!.permissions.has('MANAGE_ROLES')) return 'missing permissions'; const muteRoleID = await this.guild.getSetting('muteRole'); if (!muteRoleID) return 'no mute role'; const muteRole = this.guild.roles.cache.get(muteRoleID); if (!muteRole) return 'invalid mute role'; - if (muteRole.position >= this.guild.me.roles.highest.position || muteRole.managed) return 'mute role not manageable'; + if (muteRole.position >= this.guild.me!.roles.highest.position || muteRole.managed) return 'mute role not manageable'; - const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user; + const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!; //remove role const muteSuccess = await this.roles + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing .remove(muteRole, `[Unmute] ${moderator.tag} | ${options.reason || 'No reason provided.'}`) .catch(async (e) => { await client.console.warn('muteRoleAddError', e?.stack || e); @@ -284,6 +288,7 @@ export class BushGuildMember extends GuildMember { //dm user const dmSuccess = await this.send({ + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing content: `You have been unmuted in **${this.guild}** because **${options.reason || 'No reason provided'}**.` }).catch(() => false); @@ -294,20 +299,22 @@ export class BushGuildMember extends GuildMember { public async bushKick(options: BushPunishmentOptions): Promise<KickResponse> { // checks - if (!this.guild.me.permissions.has('KICK_MEMBERS') || !this.kickable) return 'missing permissions'; + if (!this.guild.me?.permissions.has('KICK_MEMBERS') || !this.kickable) return 'missing permissions'; - const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user; + const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!; // dm user const ending = await this.guild.getSetting('punishmentEnding'); const dmSuccess = await this.send({ + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing content: `You have been kicked from **${this.guild}** for **${options.reason || 'No reason provided'}**.${ ending ? `\n\n${ending}` : '' }` }).catch(() => false); // kick - const kickSuccess = await this.kick(`${moderator.tag} | ${options.reason || 'No reason provided.'}`).catch(() => false); + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const kickSuccess = await this.kick(`${moderator?.tag} | ${options.reason || 'No reason provided.'}`).catch(() => false); if (!kickSuccess) return 'error kicking'; // add modlog entry @@ -319,28 +326,30 @@ export class BushGuildMember extends GuildMember { reason: options.reason, guild: this.guild }) - .catch(() => null); + .catch(() => ({ log: null })); if (!modlog) return 'error creating modlog entry'; if (!dmSuccess) return 'failed to dm'; return 'success'; } - public async bushBan(options?: BushBanOptions): Promise<BanResponse> { + public async bushBan(options: BushBanOptions): Promise<BanResponse> { // checks - if (!this.guild.me.permissions.has('BAN_MEMBERS') || !this.bannable) return 'missing permissions'; + if (!this.guild.me!.permissions.has('BAN_MEMBERS') || !this.bannable) return 'missing permissions'; - const moderator = client.users.cache.get(client.users.resolveId(options.moderator)) ?? client.user; + const moderator = client.users.cache.get(client.users.resolveId(options.moderator!)!) ?? client.user!; // dm user const ending = await this.guild.getSetting('punishmentEnding'); const dmSuccess = await this.send({ content: `You have been banned ${ - options.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently' + options?.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently' + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing } from **${this.guild}** for **${options.reason || 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}` }).catch(() => false); // ban const banSuccess = await this.ban({ + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing reason: `${moderator.tag} | ${options.reason || 'No reason provided.'}`, days: options.deleteDays }).catch(() => false); diff --git a/src/lib/extensions/discord.js/BushMessage.ts b/src/lib/extensions/discord.js/BushMessage.ts index 921d03e..6d9a332 100644 --- a/src/lib/extensions/discord.js/BushMessage.ts +++ b/src/lib/extensions/discord.js/BushMessage.ts @@ -11,7 +11,7 @@ export interface BushPartialMessage extends Partialize<BushMessage, 'type' | 'system' | 'pinned' | 'tts', 'content' | 'cleanContent' | 'author'> {} export class BushMessage extends Message { public declare readonly client: BushClient; - public override util: BushCommandUtil; + public override util!: BushCommandUtil; public declare readonly guild: BushGuild | null; public declare readonly member: BushGuildMember | null; public declare author: BushUser; diff --git a/src/lib/models/ActivePunishment.ts b/src/lib/models/ActivePunishment.ts index fb2e79f..62bb73e 100644 --- a/src/lib/models/ActivePunishment.ts +++ b/src/lib/models/ActivePunishment.ts @@ -16,7 +16,7 @@ export interface ActivePunishmentModel { user: Snowflake; guild: Snowflake; extraInfo: Snowflake; - expires: Date; + expires: Date | null; modlog: string; } export interface ActivePunishmentModelCreationAttributes { diff --git a/src/lib/models/ModLog.ts b/src/lib/models/ModLog.ts index 5da6027..50d142a 100644 --- a/src/lib/models/ModLog.ts +++ b/src/lib/models/ModLog.ts @@ -25,8 +25,8 @@ export interface ModLogModel { type: ModLogType; user: Snowflake; moderator: Snowflake; - reason: string; - duration: number; + reason: string | null; + duration: number | null; guild: Snowflake; evidence: string; } diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts index 391db75..e58380b 100644 --- a/src/lib/utils/BushConstants.ts +++ b/src/lib/utils/BushConstants.ts @@ -106,12 +106,13 @@ export class BushConstants { PRIVATE_THREADS: { name: 'Private Threads', important: false, emoji: '<:privateThreads:869763711894700093>', weight: 17 }, THREE_DAY_THREAD_ARCHIVE: { name: 'Three Day Thread Archive', important: false, emoji: '<:threeDayThreadArchive:869767841652564008>', weight: 19 }, SEVEN_DAY_THREAD_ARCHIVE: { name: 'Seven Day Thread Archive', important: false, emoji: '<:sevenDayThreadArchive:869767896123998288>', weight: 20 }, - NEWS: { name: 'Announcement Channels', important: false, emoji: '<:announcementChannels:850790491796013067>', weight: 21 }, - MEMBER_VERIFICATION_GATE_ENABLED: { name: 'Membership Verification Gate', important: false, emoji: '<:memberVerificationGateEnabled:850786829984858212>', weight: 22 }, - WELCOME_SCREEN_ENABLED: { name: 'Welcome Screen Enabled', important: false, emoji: '<:welcomeScreenEnabled:850790575875817504>', weight: 23 }, - COMMUNITY: { name: 'Community', important: false, emoji: '<:community:850786714271875094>', weight: 24 }, - THREADS_ENABLED: {name: 'Threads Enabled', important: false, emoji: '<:threadsEnabled:869756035345317919>', weight: 24 }, - THREADS_ENABLED_TESTING: {name: 'Threads Enabled Testing', important: false, emoji: null, weight: 24 } + ROLE_ICONS: { name: 'Role Icons', important: false, emoji: '<:roleIcons:876993381929222175>', weight: 21 }, + NEWS: { name: 'Announcement Channels', important: false, emoji: '<:announcementChannels:850790491796013067>', weight: 22 }, + MEMBER_VERIFICATION_GATE_ENABLED: { name: 'Membership Verification Gate', important: false, emoji: '<:memberVerificationGateEnabled:850786829984858212>', weight: 23 }, + WELCOME_SCREEN_ENABLED: { name: 'Welcome Screen Enabled', important: false, emoji: '<:welcomeScreenEnabled:850790575875817504>', weight: 24 }, + COMMUNITY: { name: 'Community', important: false, emoji: '<:community:850786714271875094>', weight: 25 }, + THREADS_ENABLED: {name: 'Threads Enabled', important: false, emoji: '<:threadsEnabled:869756035345317919>', weight: 26 }, + THREADS_ENABLED_TESTING: {name: 'Threads Enabled Testing', important: false, emoji: null, weight: 27 }, }, regions: { @@ -169,11 +170,12 @@ export class BushConstants { HOUSE_BRILLIANCE: '<:hypeSquadBrilliance:848742840649646101>', HOUSE_BALANCE: '<:hypeSquadBalance:848742877537370133>', EARLY_SUPPORTER: '<:earlySupporter:848741030102171648>', - //'TEAM_USER': '', - //'SYSTEM': '', + TEAM_USER: 'TEAM_USER', + SYSTEM: 'SYSTEM', BUGHUNTER_LEVEL_2: '<:bugHunterGold:848743283080822794>', - //'VERIFIED_BOT': '', - EARLY_VERIFIED_BOT_DEVELOPER: '<:earlyVerifiedBotDeveloper:848741079875846174>' + VERIFIED_BOT: 'VERIFIED_BOT', + EARLY_VERIFIED_BOT_DEVELOPER: '<:earlyVerifiedBotDeveloper:848741079875846174>', + DISCORD_CERTIFIED_MODERATOR: '<:discordCertifiedModerator:877224285901582366>' }, status: { diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts index 27c8cd1..60817b9 100644 --- a/src/lib/utils/BushLogger.ts +++ b/src/lib/utils/BushLogger.ts @@ -15,7 +15,7 @@ export class BushLogger { const tempParsedArray: Array<string> = []; newContent.forEach((value, index) => { if (index % 2 !== 0) { - tempParsedArray.push(discordFormat ? `**${Util.escapeMarkdown(value)}**` : chalk[color](value)); + tempParsedArray.push(discordFormat ? `**${Util.escapeMarkdown(value)}**` : color ? chalk[color](value) : value); } else { tempParsedArray.push(Util.escapeMarkdown(value)); } diff --git a/src/lib/utils/CanvasProgressBar.ts b/src/lib/utils/CanvasProgressBar.ts index 521a444..cd86532 100644 --- a/src/lib/utils/CanvasProgressBar.ts +++ b/src/lib/utils/CanvasProgressBar.ts @@ -6,7 +6,7 @@ export class CanvasProgressBar { private readonly h: number; private readonly color: string; private percentage: number; - private p: number; + private p?: number; private ctx: CanvasRenderingContext2D; public constructor( @@ -18,7 +18,7 @@ export class CanvasProgressBar { ({ x: this.x, y: this.y, width: this.w, height: this.h } = dimension); this.color = color; this.percentage = percentage; - this.p; + this.p = undefined; this.ctx = ctx; } |