From 9f705a0e5a90177784d45d20200dbaa46a569e78 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Mon, 13 Dec 2021 20:22:20 -0500 Subject: fix more bugs --- src/commands/dev/eval.ts | 12 +++++++++++- src/commands/info/help.ts | 2 +- src/commands/info/links.ts | 2 +- src/lib/common/AutoMod.ts | 9 ++++----- src/lib/extensions/discord.js/BushButtonInteraction.ts | 10 ++++++++-- src/lib/extensions/discord.js/BushChannel.d.ts | 3 ++- src/lib/extensions/discord.js/BushCommandInteraction.ts | 10 ++++++++-- src/lib/extensions/discord.js/BushSelectMenuInteraction.ts | 10 ++++++++-- src/listeners/other/promiseRejection.ts | 5 +++++ src/listeners/other/uncaughtException.ts | 4 ++++ 10 files changed, 52 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 5b30d96..2393a9b 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -15,6 +15,15 @@ export default class EvalCommand extends BushCommand { usage: ['eval [--depth #] [--sudo] [--silent] [--delete] [--proto] [--hidden] [--ts]'], examples: ['eval message.channel.delete()'], args: [ + { + id: 'code', + description: 'The code you would like to evaluate.', + match: 'rest', + prompt: 'What would you like to eval?', + retry: '{error} Invalid code to eval.', + slashType: 'STRING', + only: 'slash' + }, { id: 'sel_depth', description: 'How deep to inspect the output.', @@ -96,7 +105,8 @@ export default class EvalCommand extends BushCommand { match: 'rest', prompt: 'What would you like to eval?', retry: '{error} Invalid code to eval.', - slashType: 'STRING' + slashType: 'STRING', + only: 'text' } ], slash: true, diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 455ad5f..eac48a6 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,7 +1,7 @@ import { BushCommand, BushMessage, BushSlashMessage } from '#lib'; import { MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; -const packageDotJSON = await import('../../../package.json').catch(() => null); +const packageDotJSON = await import('../../../package.json', { assert: { type: 'json' } }).catch(() => null); export default class HelpCommand extends BushCommand { public constructor() { diff --git a/src/commands/info/links.ts b/src/commands/info/links.ts index 3f82245..79f1041 100644 --- a/src/commands/info/links.ts +++ b/src/commands/info/links.ts @@ -1,6 +1,6 @@ import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { MessageActionRow, MessageButton } from 'discord.js'; -import packageDotJSON from '../../../package.json'; +import packageDotJSON from '../../../package.json' assert { type: 'json' }; export default class LinksCommand extends BushCommand { public constructor() { diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts index c52754a..932d457 100644 --- a/src/lib/common/AutoMod.ts +++ b/src/lib/common/AutoMod.ts @@ -32,8 +32,7 @@ export class AutoMod { */ private async handle() { if (this.message.channel.type === 'DM' || !this.message.guild) return; - const hasFeature = this.message.guild.hasFeature; - if (!(await hasFeature('automod'))) return; + if (!(await this.message.guild.hasFeature('automod'))) return; const customAutomodPhrases = (await this.message.guild.getSetting('autoModPhases')) ?? {}; const badLinks: BadWords = {}; @@ -52,8 +51,8 @@ export class AutoMod { const result = { ...this.checkWords(customAutomodPhrases), - ...this.checkWords((await hasFeature('excludeDefaultAutomod')) ? {} : badWords), - ...this.checkWords((await hasFeature('excludeAutomodScamLinks')) ? {} : badLinks) + ...this.checkWords((await this.message.guild.hasFeature('excludeDefaultAutomod')) ? {} : badWords), + ...this.checkWords((await this.message.guild.hasFeature('excludeAutomodScamLinks')) ? {} : badLinks) }; if (Object.keys(result).length === 0) return; @@ -77,7 +76,7 @@ export class AutoMod { void this.log(highestOffence, color, result); } - if (!this.punished && (await hasFeature('delScamMentions'))) void this.checkScamMentions(); + if (!this.punished && (await this.message.guild.hasFeature('delScamMentions'))) void this.checkScamMentions(); } /** diff --git a/src/lib/extensions/discord.js/BushButtonInteraction.ts b/src/lib/extensions/discord.js/BushButtonInteraction.ts index 9e62d46..18d6b35 100644 --- a/src/lib/extensions/discord.js/BushButtonInteraction.ts +++ b/src/lib/extensions/discord.js/BushButtonInteraction.ts @@ -1,10 +1,16 @@ -import type { BushClient, BushGuild, BushGuildMember, BushTextBasedChannels, BushUser } from '#lib'; +import type { BushClient, BushGuild, BushGuildMember, BushGuildTextBasedChannel, BushTextBasedChannels, BushUser } from '#lib'; import type { APIInteractionGuildMember } from 'discord-api-types/v9'; import { ButtonInteraction, type CacheType, type CacheTypeReducer } from 'discord.js'; import type { RawMessageButtonInteractionData } from 'discord.js/typings/rawDataTypes'; export class BushButtonInteraction extends ButtonInteraction { - public declare readonly channel: CacheTypeReducer; + public declare readonly channel: CacheTypeReducer< + Cached, + BushGuildTextBasedChannel | null, + BushGuildTextBasedChannel | null, + BushGuildTextBasedChannel | null, + BushTextBasedChannels | null + >; public declare readonly guild: CacheTypeReducer; public declare member: CacheTypeReducer; public declare user: BushUser; diff --git a/src/lib/extensions/discord.js/BushChannel.d.ts b/src/lib/extensions/discord.js/BushChannel.d.ts index 9a78b9a..497c33a 100644 --- a/src/lib/extensions/discord.js/BushChannel.d.ts +++ b/src/lib/extensions/discord.js/BushChannel.d.ts @@ -7,7 +7,8 @@ export class BushChannel extends Channel { public constructor(client: BushClient, data?: RawChannelData, immediatePatch?: boolean); public readonly createdAt: Date; public readonly createdTimestamp: number; - public deleted: boolean; + public get deleted(): boolean; + public set deleted(value: boolean); public id: Snowflake; public readonly partial: false; public type: keyof typeof ChannelTypes; diff --git a/src/lib/extensions/discord.js/BushCommandInteraction.ts b/src/lib/extensions/discord.js/BushCommandInteraction.ts index b61ec9b..174fd9c 100644 --- a/src/lib/extensions/discord.js/BushCommandInteraction.ts +++ b/src/lib/extensions/discord.js/BushCommandInteraction.ts @@ -10,14 +10,20 @@ import type { import type { APIInteractionGuildMember } from 'discord-api-types/v9'; import { CommandInteraction, type CacheType, type CacheTypeReducer, type Invite, type Snowflake } from 'discord.js'; import type { RawCommandInteractionData } from 'discord.js/typings/rawDataTypes'; -import { BushTextBasedChannels, type BushClient } from '../discord-akairo/BushClient'; +import { BushGuildTextBasedChannel, BushTextBasedChannels, type BushClient } from '../discord-akairo/BushClient'; export type BushGuildResolvable = BushGuild | BushGuildChannel | BushGuildMember | BushGuildEmoji | Invite | BushRole | Snowflake; export class BushCommandInteraction extends CommandInteraction { public declare readonly client: BushClient; public declare readonly command: BushApplicationCommand | BushApplicationCommand<{ guild: BushGuildResolvable }> | null; - public declare readonly channel: CacheTypeReducer; + public declare readonly channel: CacheTypeReducer< + Cached, + BushGuildTextBasedChannel | null, + BushGuildTextBasedChannel | null, + BushGuildTextBasedChannel | null, + BushTextBasedChannels | null + >; public declare readonly guild: CacheTypeReducer; public declare member: CacheTypeReducer; public declare user: BushUser; diff --git a/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts b/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts index 6b33c20..d33ddd3 100644 --- a/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts +++ b/src/lib/extensions/discord.js/BushSelectMenuInteraction.ts @@ -1,10 +1,16 @@ -import type { BushClient, BushGuild, BushGuildMember, BushTextBasedChannels, BushUser } from '#lib'; +import type { BushClient, BushGuild, BushGuildMember, BushGuildTextBasedChannel, BushTextBasedChannels, BushUser } from '#lib'; import type { APIInteractionGuildMember } from 'discord-api-types/v9'; import { SelectMenuInteraction, type CacheType, type CacheTypeReducer } from 'discord.js'; import type { RawMessageSelectMenuInteractionData } from 'discord.js/typings/rawDataTypes'; export class BushSelectMenuInteraction extends SelectMenuInteraction { - public declare readonly channel: CacheTypeReducer; + public declare readonly channel: CacheTypeReducer< + Cached, + BushGuildTextBasedChannel | null, + BushGuildTextBasedChannel | null, + BushGuildTextBasedChannel | null, + BushTextBasedChannels | null + >; public declare readonly guild: CacheTypeReducer; public declare member: CacheTypeReducer; public declare user: BushUser; diff --git a/src/listeners/other/promiseRejection.ts b/src/listeners/other/promiseRejection.ts index 699b676..69a62c7 100644 --- a/src/listeners/other/promiseRejection.ts +++ b/src/listeners/other/promiseRejection.ts @@ -12,6 +12,11 @@ export default class PromiseRejectionListener extends BushListener { } public override async exec(error: Error) { + process.listeners('unhandledRejection').forEach((listener) => { + if (listener.toString() === this.exec.toString()) return; + process.removeListener('unhandledRejection', listener); + }); + client.sentry.captureException(error, { level: Severity.Error }); diff --git a/src/listeners/other/uncaughtException.ts b/src/listeners/other/uncaughtException.ts index 34dcdd6..b650620 100644 --- a/src/listeners/other/uncaughtException.ts +++ b/src/listeners/other/uncaughtException.ts @@ -12,6 +12,10 @@ export default class UncaughtExceptionListener extends BushListener { } public override async exec(error: Error) { + process.listeners('uncaughtException').forEach((listener) => { + if (listener.toString() === this.exec.toString()) return; + process.removeListener('uncaughtException', listener); + }); client.sentry.captureException(error, { level: Severity.Error }); -- cgit