diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-17 12:31:09 -0400 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-17 12:31:09 -0400 |
| commit | d40527d0a2d9f209905750258f71bedff1cdf089 (patch) | |
| tree | e017fd844c2135bfc85228d00ef2617d24ce0a3f /src/lib/extensions/discord-akairo | |
| parent | d431ad00754f3f250103deedea495b9bcee73fc0 (diff) | |
| download | tanzanite-d40527d0a2d9f209905750258f71bedff1cdf089.tar.gz tanzanite-d40527d0a2d9f209905750258f71bedff1cdf089.tar.bz2 tanzanite-d40527d0a2d9f209905750258f71bedff1cdf089.zip | |
turned on ts strict option
Diffstat (limited to 'src/lib/extensions/discord-akairo')
| -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 |
5 files changed, 58 insertions, 50 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); } } |
