diff options
Diffstat (limited to 'src/lib/extensions/discord-akairo')
4 files changed, 51 insertions, 33 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 712d610..ce72ee2 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -25,8 +25,8 @@ import * as Sentry from '@sentry/node'; import { AkairoClient, ContextMenuCommandHandler, version as akairoVersion } from 'discord-akairo'; import { ActivityType, - Intents, Options, + Partials, Structures, version as discordJsVersion, type Awaitable, @@ -189,21 +189,18 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re public constructor(config: Config) { super({ ownerID: config.owners, - intents: Object.values(Intents.FLAGS).reduce((acc, p) => acc | p, 0), - partials: ['USER', 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE', 'REACTION', 'GUILD_SCHEDULED_EVENT'], + intents: Object.keys(GatewayIntentBits) + .map((i) => (typeof i === 'string' ? GatewayIntentBits[i as keyof typeof GatewayIntentBits] : i)) + .reduce((acc, p) => acc | p, 0), + partials: Object.keys(Partials).map((p) => Partials[p as keyof typeof Partials]), presence: { - activities: [ - { - name: 'Beep Boop', - type: ActivityType.Watching - } - ], + activities: [{ name: 'Beep Boop', type: ActivityType.Watching }], status: 'online' }, - http: { api: 'https://canary.discord.com/api' }, allowedMentions: AllowedMentions.users(), // No everyone or role mentions by default makeCache: Options.cacheWithLimits({}), - failIfNotExists: false + failIfNotExists: false, + rest: { api: 'https://canary.discord.com/api' } }); patch(this); @@ -211,7 +208,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re this.config = config; this.util = new BushClientUtil(this); - /* handlers */ + /* =-=-= handlers =-=-= */ this.listenerHandler = new BushListenerHandler(this, { directory: path.join(__dirname, '..', '..', '..', 'listeners'), automateCategories: true @@ -238,12 +235,12 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re commandUtilLifetime: 300_000, // 5 minutes argumentDefaults: { prompt: { - start: 'Placeholder argument prompt. If you see this please tell my developers.', - retry: 'Placeholder failed argument prompt. If you see this please tell my developers.', + start: 'Placeholder argument prompt. **If you see this please tell my developers**.', + retry: 'Placeholder failed argument prompt. **If you see this please tell my developers**.', modifyStart: (_: Message, str: string): string => `${str}\n\n Type \`cancel\` to cancel the command`, modifyRetry: (_: Message, str: string): string => `${str.replace('{error}', this.util.emojis.error)}\n\n Type \`cancel\` to cancel the command`, - timeout: 'You took too long the command has been cancelled', + timeout: ':hourglass: You took too long the command has been cancelled.', ended: 'You exceeded the maximum amount of tries the command has been cancelled', cancel: 'The command has been cancelled', retries: 3, @@ -262,7 +259,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re automateCategories: true }); - /* databases */ + /* =-=-= databases =-=-= */ const sharedDBOptions: SequelizeOptions = { username: this.config.db.username, password: this.config.db.password, @@ -281,8 +278,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re database: 'bushbot-shared' }); - // eslint-disable-next-line @typescript-eslint/no-unused-vars - /* global objects */ + /* =-=-= global objects =-=-= */ global.client = this; global.util = this.util; } @@ -351,7 +347,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re contextMenuCommandHandler: this.contextMenuCommandHandler, process, stdin: rl, - gateway: this.ws + gateway: this.ws, + rest: this.rest }); this.commandHandler.resolver.addTypes({ duration, @@ -515,3 +512,23 @@ export interface BushStats { */ commandsUsed: bigint; } + +// exported as const enum from discord-api-types +enum GatewayIntentBits { + Guilds = 1, + GuildMembers = 2, + GuildBans = 4, + GuildEmojisAndStickers = 8, + GuildIntegrations = 16, + GuildWebhooks = 32, + GuildInvites = 64, + GuildVoiceStates = 128, + GuildPresences = 256, + GuildMessages = 512, + GuildMessageReactions = 1024, + GuildMessageTyping = 2048, + DirectMessages = 4096, + DirectMessageReactions = 8192, + DirectMessageTyping = 16384, + GuildScheduledEvents = 65536 +} diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index e3c0803..7a4d5b0 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -20,12 +20,13 @@ import { humanizeDuration } from '@notenoughupdates/humanize-duration'; import { exec } from 'child_process'; import deepLock from 'deep-lock'; import { ClientUtil, Util as AkairoUtil } from 'discord-akairo'; -import type { APIMessage } from 'discord-api-types'; +import { APIMessage } from 'discord-api-types'; import { Constants as DiscordConstants, GuildMember, Message, - Permissions, + PermissionFlagsBits, + PermissionsBitField, ThreadMember, User, Util as DiscordUtil, @@ -404,8 +405,8 @@ export class BushClientUtil extends ClientUtil { * @returns The combined elements or `ifEmpty`. * * @example - * const permissions = oxford([Permissions.FLAGS.ADMINISTRATOR, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.MANAGE_MESSAGES], 'and', 'none'); - * console.log(permissions); // ADMINISTRATOR, SEND_MESSAGES and MANAGE_MESSAGES + * const permissions = oxford([PermissionFlagsBits.Administrator, PermissionFlagsBits.SendMessages, PermissionFlagsBits.ManageMessages], 'and', 'none'); + * console.log(permissions); // Administrator, SendMessages and ManageMessages */ public oxford(array: string[], conjunction: string, ifEmpty?: string): string | undefined { const l = array.length; @@ -767,7 +768,7 @@ export class BushClientUtil extends ClientUtil { public userGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[]) { const missing = message.member?.permissions.missing(permissions) ?? []; - return missing.length ? missing.map((p) => Permissions.FLAGS[p]) : null; + return missing.length ? missing.map((p) => PermissionFlagsBits[p]) : null; } /** @@ -779,7 +780,7 @@ export class BushClientUtil extends ClientUtil { public clientGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[]) { const missing = message.guild?.me?.permissions.missing(permissions) ?? []; - return missing.length ? missing.map((p) => Permissions.FLAGS[p]) : null; + return missing.length ? missing.map((p) => PermissionFlagsBits[p]) : null; } /** @@ -792,7 +793,7 @@ export class BushClientUtil extends ClientUtil { */ public clientSendAndPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[] = [], checkChannel = false) { const missing = []; - const sendPerm = message.channel!.isThread() ? Permissions.FLAGS.SEND_MESSAGES : Permissions.FLAGS.SEND_MESSAGES_IN_THREADS; + const sendPerm = message.channel!.isThread() ? PermissionFlagsBits.SendMessages : PermissionFlagsBits.SendMessagesInThreads; if (!message.inGuild()) return null; if (!message.guild.me!.permissionsIn(message.channel.id).has(sendPerm)) missing.push(sendPerm); @@ -802,7 +803,7 @@ export class BushClientUtil extends ClientUtil { ? message .guild!.me!.permissionsIn(message.channel!.id!) .missing(permissions) - .map((p) => Permissions.FLAGS[p]) + .map((p) => PermissionFlagsBits[p]) : this.clientGuildPermCheck(message, permissions) ?? []) ); @@ -875,7 +876,7 @@ export class BushClientUtil extends ClientUtil { return `https://discord.com/api/oauth2/authorize?client_id=${Buffer.from( client.token!.split('.')[0], 'base64' - ).toString()}&permissions=${Permissions.ALL}&scope=bot%20applications.commands`; + ).toString()}&permissions=${PermissionsBitField.All}&scope=bot%20applications.commands`; } /** diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 0456b80..650b538 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -51,7 +51,7 @@ import { type Collection, type Invite, type PermissionResolvable, - type PermissionString, + type PermissionsString, type Snowflake } from 'discord.js'; @@ -106,7 +106,7 @@ export interface OverriddenBaseArgumentType extends BaseArgumentType { export interface BaseBushArgumentType extends OverriddenBaseArgumentType { duration: number | null; contentWithDuration: ParsedDuration; - permission: PermissionString | null; + permission: PermissionsString | null; snowflake: Snowflake | null; discordEmoji: DiscordEmojiInfo | null; roleWithDuration: RoleWithDuration | null; diff --git a/src/lib/extensions/discord-akairo/BushCommandHandler.ts b/src/lib/extensions/discord-akairo/BushCommandHandler.ts index 6c06c5b..2c1903f 100644 --- a/src/lib/extensions/discord-akairo/BushCommandHandler.ts +++ b/src/lib/extensions/discord-akairo/BushCommandHandler.ts @@ -1,6 +1,6 @@ import { type BushClient, type BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { CommandHandler, type Category, type CommandHandlerEvents, type CommandHandlerOptions } from 'discord-akairo'; -import { type Collection, type PermissionString } from 'discord.js'; +import { type Collection, type PermissionsString } from 'discord.js'; export type BushCommandHandlerOptions = CommandHandlerOptions; @@ -18,7 +18,7 @@ export interface BushCommandHandlerEvents extends CommandHandlerEvents { load: [command: BushCommand, isReload: boolean]; messageBlocked: [message: BushMessage | BushSlashMessage, reason: string]; messageInvalid: [message: BushMessage]; - missingPermissions: [message: BushMessage, command: BushCommand, type: 'client' | 'user', missing: Array<PermissionString>]; + missingPermissions: [message: BushMessage, command: BushCommand, type: 'client' | 'user', missing: PermissionsString[]]; remove: [command: BushCommand]; slashBlocked: [message: BushSlashMessage, command: BushCommand, reason: string]; slashError: [error: Error, message: BushSlashMessage, command: BushCommand]; @@ -27,7 +27,7 @@ export interface BushCommandHandlerEvents extends CommandHandlerEvents { message: BushSlashMessage, command: BushCommand, type: 'client' | 'user', - missing: Array<PermissionString> + missing: PermissionsString[] ]; slashStarted: [message: BushSlashMessage, command: BushCommand, args: any]; } |