diff options
-rw-r--r-- | package.json | 11 | ||||
-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 | ||||
-rw-r--r-- | yarn.lock | 109 |
10 files changed, 149 insertions, 72 deletions
diff --git a/package.json b/package.json index 0d13714..d471f9a 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "esbuild": "^0.12.11", "eslint": "^7.29.0", "eslint-config-prettier": "^8.3.0", + "events-intercept": "^2.0.0", "fuse.js": "^6.4.6", "got": "^11.8.2", "humanize-duration": "^3.27.0", @@ -136,5 +137,13 @@ "singleQuote": true, "trailingComma": "none" }, - "packageManager": "yarn@3.0.0" + "packageManager": "yarn@3.0.0", + "dependenciesMeta": { + "discord-akairo@8.2.2": { + "unplugged": true + }, + "discord.js@13.2.0-dev": { + "unplugged": true + } + } } 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]; + } } } @@ -406,11 +406,11 @@ __metadata: linkType: hard "@typescript-eslint/eslint-plugin@npm:^4.14.1": - version: 4.29.2 - resolution: "@typescript-eslint/eslint-plugin@npm:4.29.2" + version: 4.29.3 + resolution: "@typescript-eslint/eslint-plugin@npm:4.29.3" dependencies: - "@typescript-eslint/experimental-utils": 4.29.2 - "@typescript-eslint/scope-manager": 4.29.2 + "@typescript-eslint/experimental-utils": 4.29.3 + "@typescript-eslint/scope-manager": 4.29.3 debug: ^4.3.1 functional-red-black-tree: ^1.0.1 regexpp: ^3.1.0 @@ -422,66 +422,66 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 3d3646059daa3d95200d71945a1ec8daebf62c7fedc3f29e1bece87bee9d689b06856fb18a8c55917f9c0bb5e86ddc8bc4c4f65f171e7d5784756dd59e3ff51d + checksum: ded1580fc6348848df3ed92d4365586bf13a05cd698c07aa7727155ca13788b5c33bd326b5435af3e97b702156b1eef811ace20fb5ca44eab6388cecfd8e264a languageName: node linkType: hard -"@typescript-eslint/experimental-utils@npm:4.29.2": - version: 4.29.2 - resolution: "@typescript-eslint/experimental-utils@npm:4.29.2" +"@typescript-eslint/experimental-utils@npm:4.29.3": + version: 4.29.3 + resolution: "@typescript-eslint/experimental-utils@npm:4.29.3" dependencies: "@types/json-schema": ^7.0.7 - "@typescript-eslint/scope-manager": 4.29.2 - "@typescript-eslint/types": 4.29.2 - "@typescript-eslint/typescript-estree": 4.29.2 + "@typescript-eslint/scope-manager": 4.29.3 + "@typescript-eslint/types": 4.29.3 + "@typescript-eslint/typescript-estree": 4.29.3 eslint-scope: ^5.1.1 eslint-utils: ^3.0.0 peerDependencies: eslint: "*" - checksum: e07b6b58f386ba84801d10bfe494548c3af20448c2f5596b77d13ba8621345ced4e1c6cf946dcf118c1e8566e0eed8284200f3f3a96f89aa7f367d9cdf6549a3 + checksum: 7cd398bf3fccee1c769006c9d28fc0a353c2978cbc33e21449d186ab413ccf5f731b3ac30f557550c1daac767a5b97dce15ec10fe9ad5a632846d285dafac5b0 languageName: node linkType: hard "@typescript-eslint/parser@npm:^4.14.1": - version: 4.29.2 - resolution: "@typescript-eslint/parser@npm:4.29.2" + version: 4.29.3 + resolution: "@typescript-eslint/parser@npm:4.29.3" dependencies: - "@typescript-eslint/scope-manager": 4.29.2 - "@typescript-eslint/types": 4.29.2 - "@typescript-eslint/typescript-estree": 4.29.2 + "@typescript-eslint/scope-manager": 4.29.3 + "@typescript-eslint/types": 4.29.3 + "@typescript-eslint/typescript-estree": 4.29.3 debug: ^4.3.1 peerDependencies: eslint: ^5.0.0 || ^6.0.0 || ^7.0.0 peerDependenciesMeta: typescript: optional: true - checksum: 59f9727cea89c208fb31433c24dd7c1b4f2feb3af831b9320f4577f7b84f014f803864d4660b0f6bd16a4026d7ecd22b88523feb8c1593ef4a0a43ca9ea09c33 + checksum: 3fac6b5219de8b9aea361cc2fa170105661068d5eee5594f2f68526801a66b9525a766fc17427a8d410ada0da2d852f8c021d0b2fac7442a1e913f248ac85d90 languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:4.29.2": - version: 4.29.2 - resolution: "@typescript-eslint/scope-manager@npm:4.29.2" +"@typescript-eslint/scope-manager@npm:4.29.3": + version: 4.29.3 + resolution: "@typescript-eslint/scope-manager@npm:4.29.3" dependencies: - "@typescript-eslint/types": 4.29.2 - "@typescript-eslint/visitor-keys": 4.29.2 - checksum: f89d11cf7ce28c37a913db432d3dd2c4e5f5bc431bac205dd55c3d49704be691a28d5f27ae96fde7feee23d3e80192d7aff3d8350aef53b415e5b0b53cd965d7 + "@typescript-eslint/types": 4.29.3 + "@typescript-eslint/visitor-keys": 4.29.3 + checksum: 53a4d3cd0844df789ad3548644d9214cf234ce87bbc7843c55949f63e98925b4685b36f0514afbab891b4f8f0da85c249850023be5d5e9b175780aa62d181aac languageName: node linkType: hard -"@typescript-eslint/types@npm:4.29.2": - version: 4.29.2 - resolution: "@typescript-eslint/types@npm:4.29.2" - checksum: 0bcab66bb1848e2361bb366abebe1f94baa56d7d2058b62467f14c054b969b72d1aa17717a52c11f48e9cfb50846f0e227e49ccc7f06ff750b9eb28ca8b064de +"@typescript-eslint/types@npm:4.29.3": + version: 4.29.3 + resolution: "@typescript-eslint/types@npm:4.29.3" + checksum: 26fd2bd6782b763ff6d5ef3bcc08e1d29b64d15ef6f3604203f6171517935d822c103f803d8755c8e0cb77319143e5d5108dc90e8e897c8e72bab9f178be67ce languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:4.29.2": - version: 4.29.2 - resolution: "@typescript-eslint/typescript-estree@npm:4.29.2" +"@typescript-eslint/typescript-estree@npm:4.29.3": + version: 4.29.3 + resolution: "@typescript-eslint/typescript-estree@npm:4.29.3" dependencies: - "@typescript-eslint/types": 4.29.2 - "@typescript-eslint/visitor-keys": 4.29.2 + "@typescript-eslint/types": 4.29.3 + "@typescript-eslint/visitor-keys": 4.29.3 debug: ^4.3.1 globby: ^11.0.3 is-glob: ^4.0.1 @@ -490,17 +490,17 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 90342d27f3f0837ad39f9b7e7d7c3c0b6de9c5b0770f5a18d490ebaf7be78efa65ba46ce0ca3004ad946ca1adc5865c5d3ba3b049c95b3b193bfdf0eb5e23095 + checksum: b7ea37db1a2f43806bf16090dfb44c7243ad07b7cb75d398fc2a1ce347fa04a59a5c729a41d1e34862cc3ed60275f5565fe3343393df1c42d95395ed42c761f0 languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:4.29.2": - version: 4.29.2 - resolution: "@typescript-eslint/visitor-keys@npm:4.29.2" +"@typescript-eslint/visitor-keys@npm:4.29.3": + version: 4.29.3 + resolution: "@typescript-eslint/visitor-keys@npm:4.29.3" dependencies: - "@typescript-eslint/types": 4.29.2 + "@typescript-eslint/types": 4.29.3 eslint-visitor-keys: ^2.0.0 - checksum: 34185d8c6466340aba746d69b36d357da2d06577d73f58358648c142bd0f181d7fae01ca1138188a665ef074ea7e1bc6306ef9d50f29914c8bcea4e9ea1f82f2 + checksum: 76d485cb573cfccb8a6aded5b98fd58266c10f82362685d3d0b870e197cbe5e3d61b485e220a7a973765c4861df9ea52a35757ecb818f125e405925556ee1f90 languageName: node linkType: hard @@ -751,6 +751,7 @@ __metadata: esbuild: ^0.12.11 eslint: ^7.29.0 eslint-config-prettier: ^8.3.0 + events-intercept: ^2.0.0 fuse.js: ^6.4.6 got: ^11.8.2 humanize-duration: ^3.27.0 @@ -769,6 +770,11 @@ __metadata: tinycolor2: ^1.4.2 typescript: ^4.3.5 uuid: ^8.3.2 + dependenciesMeta: + discord-akairo@8.2.2: + unplugged: true + discord.js@13.2.0-dev: + unplugged: true languageName: unknown linkType: soft @@ -1075,12 +1081,12 @@ discord-akairo-message-util@NotEnoughUpdates/discord-akairo-message-util: discord-akairo@NotEnoughUpdates/discord-akairo: version: 8.2.2 - resolution: "discord-akairo@https://github.com/NotEnoughUpdates/discord-akairo.git#commit=840437bfc666689add3a24037fc5ef90e0335345" + resolution: "discord-akairo@https://github.com/NotEnoughUpdates/discord-akairo.git#commit=26e248e3e427d9f68500b151294c6bbb59efc48d" dependencies: discord-akairo-message-util: NotEnoughUpdates/discord-akairo-message-util lodash: ^4.17.21 source-map-support: ^0.5.19 - checksum: 6af32d8b76a22ec25582e806f04e500b3f4ce13d960df871535ef1b34adedbe6940fd19fdc0f12e3ba72f1272fba1f860ffee8e86beac7e624def943c2e57be0 + checksum: c2435ae6c0bcbd0fec0756ff9b34cd164a713e2fae8d2dd1cc80d6761ef3049d390b4bda1ecef1fb862d979474559422289b5728d6822509e8f6f42c18f9b4ad languageName: node linkType: hard @@ -1100,7 +1106,7 @@ discord-akairo@NotEnoughUpdates/discord-akairo: discord.js@NotEnoughUpdates/discord.js: version: 13.2.0-dev - resolution: "discord.js@https://github.com/NotEnoughUpdates/discord.js.git#commit=2965801e1334034c81974a43a9b9e4afdcbfd990" + resolution: "discord.js@https://github.com/NotEnoughUpdates/discord.js.git#commit=e0c7f18a5c43cce502cfb6578f0b74940afe4859" dependencies: "@discordjs/builders": ^0.5.0 "@discordjs/collection": ^0.2.1 @@ -1110,7 +1116,7 @@ discord.js@NotEnoughUpdates/discord.js: discord-api-types: ^0.22.0 node-fetch: ^2.6.1 ws: ^7.5.1 - checksum: 45864600112bd1563c0b0780c1bfe5259a1635ca03e915255f636f40f1efe99b7fb16036cfeddb83d8ea8de895708382a9af845e87ebf03b31f3d4972199b612 + checksum: 0a6839d548cbbbaa1ae12d7a712a9c94cef73c4cd2a76f094a9ab364fef020395cf8685238a4d71c91e53cf27512d0ce5daee06733fc58fa17ab26f8a614a501 languageName: node linkType: hard @@ -1382,6 +1388,13 @@ discord.js@NotEnoughUpdates/discord.js: languageName: node linkType: hard +"events-intercept@npm:^2.0.0": + version: 2.0.0 + resolution: "events-intercept@npm:2.0.0" + checksum: 1aa3447249584abb15d046ce847476e57772a98ec856d3093cea33c90bdd60428125834668c624f9f0e54203d6efd0b35550547082ddcc374e029d85664eddb0 + languageName: node + linkType: hard + "fast-deep-equal@npm:^3.1.1, fast-deep-equal@npm:^3.1.3": version: 3.1.3 resolution: "fast-deep-equal@npm:3.1.3" @@ -2235,8 +2248,8 @@ discord.js@NotEnoughUpdates/discord.js: linkType: hard "node-gyp@npm:latest": - version: 8.1.0 - resolution: "node-gyp@npm:8.1.0" + version: 8.2.0 + resolution: "node-gyp@npm:8.2.0" dependencies: env-paths: ^2.2.0 glob: ^7.1.4 @@ -2246,11 +2259,11 @@ discord.js@NotEnoughUpdates/discord.js: npmlog: ^4.1.2 rimraf: ^3.0.2 semver: ^7.3.5 - tar: ^6.1.0 + tar: ^6.1.2 which: ^2.0.2 bin: node-gyp: bin/node-gyp.js - checksum: d9f11a9ab20d2ec900cd910ecd77bc3909d4b5cd9eaf9854b00be4ba930227c5ce2ee0681216c326739dd445b1787aa933ac8d6a16ce222455d85092bb047901 + checksum: 5e0e755eab8ca88647d20fc8aba4095560c3dd549686e86761b57b8489d93a1af68b0dccf881e5314bfce4d7ca290f8248e192915ccd3e18bf46571d72da6a9d languageName: node linkType: hard @@ -3059,7 +3072,7 @@ discord.js@NotEnoughUpdates/discord.js: languageName: node linkType: hard -"tar@npm:^6.0.2, tar@npm:^6.1.0": +"tar@npm:^6.0.2, tar@npm:^6.1.0, tar@npm:^6.1.2": version: 6.1.10 resolution: "tar@npm:6.1.10" dependencies: |