diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/context-menu-commands/message/viewRaw.ts | 23 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 29 | ||||
-rw-r--r-- | src/lib/utils/BushLogger.ts | 2 | ||||
-rw-r--r-- | src/listeners/client/interactionCreate.ts | 7 | ||||
-rw-r--r-- | src/listeners/client/ready.ts | 12 | ||||
-rw-r--r-- | src/listeners/commands/commandError.ts | 18 | ||||
-rw-r--r-- | src/listeners/message/automodCreate.ts | 2 | ||||
-rw-r--r-- | src/tasks/updateCache.ts | 8 |
8 files changed, 78 insertions, 23 deletions
diff --git a/src/context-menu-commands/message/viewRaw.ts b/src/context-menu-commands/message/viewRaw.ts new file mode 100644 index 0000000..c04ec3c --- /dev/null +++ b/src/context-menu-commands/message/viewRaw.ts @@ -0,0 +1,23 @@ +import { ContextMenuCommand } from 'discord-akairo'; +import { ContextMenuInteraction } from 'discord.js'; +import ViewRawCommand from '../../commands/utilities/viewraw'; +import { BushMessage } from '../../lib'; + +export default class ViewRawContextMenuCommand extends ContextMenuCommand { + public constructor() { + super('viewRaw', { + name: 'View Raw', + type: 'MESSAGE', + category: 'message' + }); + } + + public override async exec(interaction: ContextMenuInteraction): Promise<unknown> { + await interaction.deferReply({ ephemeral: true }); + const embed = await ViewRawCommand.getRawData(interaction.options.getMessage('message') as BushMessage, { + json: false, + js: false + }); + return await interaction.editReply({ embeds: [embed] }); + } +} diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index ee92ded..54392fd 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -1,5 +1,5 @@ import chalk from 'chalk'; -import { AkairoClient } from 'discord-akairo'; +import { AkairoClient, ContextMenuCommandHandler } from 'discord-akairo'; import { Collection, Intents, @@ -14,6 +14,8 @@ import { Structures, WebhookEditMessageOptions } from 'discord.js'; +//@ts-ignore: no typings +import eventsIntercept from 'events-intercept'; import JSON5 from 'json5'; import 'json5/lib/register'; import path from 'path'; @@ -138,6 +140,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re public inhibitorHandler: BushInhibitorHandler; public commandHandler: BushCommandHandler; public taskHandler: BushTaskHandler; + public contextMenuCommandHandler: ContextMenuCommandHandler; public declare util: BushClientUtil; public declare ownerID: Snowflake[]; public db: Sequelize; @@ -177,7 +180,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re // Create task handler this.taskHandler = new BushTaskHandler(this, { - directory: path.join(__dirname, '..', '..', '..', 'tasks') + directory: path.join(__dirname, '..', '..', '..', 'tasks'), + automateCategories: true }); // Create command handler @@ -210,7 +214,13 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re }, automateCategories: false, - autoRegisterSlashCommands: true + autoRegisterSlashCommands: true, + skipBuiltInPostInhibitors: false + }); + + this.contextMenuCommandHandler = new ContextMenuCommandHandler(this, { + directory: path.join(__dirname, '..', '..', '..', 'context-menu-commands'), + automateCategories: true }); this.util = new BushClientUtil(this); @@ -259,6 +269,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re // loads all the handlers const loaders = { commands: this.commandHandler, + contextMenuCommand: this.contextMenuCommandHandler, listeners: this.listenerHandler, inhibitors: this.inhibitorHandler, tasks: this.taskHandler @@ -299,6 +310,18 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re /** Starts the bot */ public async start(): Promise<void> { + // eslint-disable-next-line @typescript-eslint/no-this-alias + const that = this; + eventsIntercept.patch(this); + //@ts-ignore: no typings + this.intercept('ready', async (arg, done) => { + const promises = that.guilds.cache.map((guild) => { + return guild.members.fetch(); + }); + await Promise.all(promises); + return done(null, 'intercepted ' + arg); + }); + // global objects global.client = this; global.util = this.util; diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts index e716e68..fd0aa4d 100644 --- a/src/lib/utils/BushLogger.ts +++ b/src/lib/utils/BushLogger.ts @@ -17,7 +17,7 @@ export class BushLogger { if (index % 2 !== 0) { tempParsedArray.push(discordFormat ? `**${Util.escapeMarkdown(value)}**` : color ? chalk[color](value) : value); } else { - tempParsedArray.push(Util.escapeMarkdown(value)); + tempParsedArray.push(discordFormat ? Util.escapeMarkdown(value) : value); } }); return tempParsedArray.join(''); diff --git a/src/listeners/client/interactionCreate.ts b/src/listeners/client/interactionCreate.ts index 63775dd..7dc20ec 100644 --- a/src/listeners/client/interactionCreate.ts +++ b/src/listeners/client/interactionCreate.ts @@ -1,6 +1,5 @@ -import { BushListener, BushMessage } from '@lib'; +import { BushListener } from '@lib'; import { ClientEvents } from 'discord.js'; -import ViewRawCommand from '../../commands/utilities/viewraw'; export default class InteractionCreateListener extends BushListener { public constructor() { @@ -37,7 +36,7 @@ export default class InteractionCreateListener extends BushListener { }.`, ephemeral: true }); - } else if (interaction.isContextMenu()) { + } /* else if (interaction.isContextMenu()) { if (interaction.commandName === 'View Raw') { await interaction.deferReply({ ephemeral: true }); const embed = await ViewRawCommand.getRawData(interaction.options.getMessage('message') as BushMessage, { @@ -46,6 +45,6 @@ export default class InteractionCreateListener extends BushListener { }); return await interaction.editReply({ embeds: [embed] }); } - } + } */ } } diff --git a/src/listeners/client/ready.ts b/src/listeners/client/ready.ts index 89c9161..5806f7f 100644 --- a/src/listeners/client/ready.ts +++ b/src/listeners/client/ready.ts @@ -5,7 +5,8 @@ export default class ReadyListener extends BushListener { public constructor() { super('ready', { emitter: 'client', - event: 'ready' + event: 'ready', + type: 'once' }); } @@ -22,14 +23,5 @@ export default class ReadyListener extends BushListener { }` ) ); - - setTimeout( - // eslint-disable-next-line @typescript-eslint/no-misused-promises - async () => - await client.application?.commands - .create({ name: 'View Raw', type: 'MESSAGE' }) - .catch((e) => client.console.error(`Ready`, e?.stack ?? e)), - 2_000 - ); } } diff --git a/src/listeners/commands/commandError.ts b/src/listeners/commands/commandError.ts index 85cd465..5db4e1e 100644 --- a/src/listeners/commands/commandError.ts +++ b/src/listeners/commands/commandError.ts @@ -101,7 +101,23 @@ export default class CommandErrorListener extends BushListener { `**Error ${util.capitalizeFirstLetter(element)}:** ${ typeof (options.error as any)[element] === 'object' ? `[haste](${await util.inspectCleanRedactHaste((options.error as any)[element])})` - : '`' + util.discord.escapeInlineCode(util.inspectAndRedact((options.error as any)[element])) + '`' + : '`' + + util.discord.escapeInlineCode( + util.inspectAndRedact((options.error as any)[element], { + showHidden: false, + depth: 3, + colors: false, + customInspect: true, + showProxy: false, + maxArrayLength: Infinity, + maxStringLength: Infinity, + breakLength: 80, + compact: 3, + sorted: false, + getters: true + }) + ) + + '`' }` ); } diff --git a/src/listeners/message/automodCreate.ts b/src/listeners/message/automodCreate.ts index cfe3970..ff87513 100644 --- a/src/listeners/message/automodCreate.ts +++ b/src/listeners/message/automodCreate.ts @@ -104,7 +104,7 @@ export default class AutomodMessageCreateListener extends BushListener { .setDescription( `**User:** ${message.author} (${message.author.tag})\n**Sent From**: <#${message.channel.id}> [Jump to context](${ message.url - })\n**Blacklisted Words:** ${util.surroundArray(Object.keys(offences), '`').join()}` + })\n**Blacklisted Words:** ${util.surroundArray(Object.keys(offences), '`').join(', ')}` ) .addField('Message Content', `${await util.codeblock(message.content, 1024)}`) .setColor(color) diff --git a/src/tasks/updateCache.ts b/src/tasks/updateCache.ts index 7fb7eb3..69919d8 100644 --- a/src/tasks/updateCache.ts +++ b/src/tasks/updateCache.ts @@ -24,11 +24,13 @@ export class UpdateCacheTask extends BushTask { private static async updateGlobalCache(client: BushClient): Promise<void> { const environment = config.environment; - const row = ((await Global.findByPk(environment)) ?? (await Global.create({ environment }))).toJSON(); + const row: { [x: string]: any } = ((await Global.findByPk(environment)) ?? (await Global.create({ environment }))).toJSON(); for (const option in row) { - if (Object.keys(client.cache.global).includes(option)) - client.cache.global[option as keyof typeof client.cache.global] = row[option as keyof typeof row]; + if (Object.keys(client.cache.global).includes(option)) { + client.cache.global[option as keyof typeof client.cache.global] = row[option]; + if (option === 'superUsers') client.superUserID = row[option]; + } } } |