aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord-akairo
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/extensions/discord-akairo')
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts21
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts35
-rw-r--r--src/lib/extensions/discord-akairo/BushCommand.ts4
-rw-r--r--src/lib/extensions/discord-akairo/BushSlashMessage.ts12
4 files changed, 45 insertions, 27 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index cb1e50b..01620a8 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -24,6 +24,7 @@ import { patch, type PatchedElements } from '@notenoughupdates/events-intercept'
import * as Sentry from '@sentry/node';
import { AkairoClient, ContextMenuCommandHandler, version as akairoVersion } from 'discord-akairo';
import {
+ ActivityType,
Intents,
Options,
Structures,
@@ -61,7 +62,7 @@ import { BushConstants } from '../../utils/BushConstants.js';
import { BushLogger } from '../../utils/BushLogger.js';
import { BushButtonInteraction } from '../discord.js/BushButtonInteraction.js';
import { BushCategoryChannel } from '../discord.js/BushCategoryChannel.js';
-import { BushCommandInteraction } from '../discord.js/BushCommandInteraction.js';
+import { BushChatInputCommandInteraction } from '../discord.js/BushChatInputCommandInteraction.js';
import { BushDMChannel } from '../discord.js/BushDMChannel.js';
import { BushGuild } from '../discord.js/BushGuild.js';
import { BushGuildEmoji } from '../discord.js/BushGuildEmoji.js';
@@ -193,7 +194,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
activities: [
{
name: 'Beep Boop',
- type: 'WATCHING'
+ type: ActivityType.Watching
}
],
status: 'online'
@@ -252,7 +253,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
automateCategories: false,
autoRegisterSlashCommands: true,
skipBuiltInPostInhibitors: true,
- useSlashPermissions: true,
+ useSlashPermissions: false,
aliasReplacement: /-/g
});
this.contextMenuCommandHandler = new ContextMenuCommandHandler(this, {
@@ -320,7 +321,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
Structures.extend('VoiceState', () => BushVoiceState);
Structures.extend('Role', () => BushRole);
Structures.extend('User', () => BushUser);
- Structures.extend('CommandInteraction', () => BushCommandInteraction);
+ Structures.extend('ChatInputCommandInteraction', () => BushChatInputCommandInteraction);
Structures.extend('ButtonInteraction', () => BushButtonInteraction);
Structures.extend('SelectMenuInteraction', () => BushSelectMenuInteraction);
}
@@ -440,13 +441,17 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
*/
public async start() {
this.intercept('ready', async (arg, done) => {
- await this.guilds.fetch();
- const promises = this.guilds.cache.map((guild) => {
- return guild.members.fetch();
- });
+ console.debug('ready start');
+ console.time('ready');
+ const promises = this.guilds.cache
+ .filter((g) => g.large)
+ .map((guild) => {
+ return guild.members.fetch();
+ });
await Promise.all(promises);
this.customReady = true;
this.taskHandler.startAll();
+ console.timeEnd('ready');
return done(null, `intercepted ${arg}`);
});
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 12becd3..79aa4c1 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -26,13 +26,13 @@ import {
GuildMember,
Message,
MessageEmbed,
+ Permissions,
ThreadMember,
User,
Util as DiscordUtil,
type ColorResolvable,
type CommandInteraction,
type InteractionReplyOptions,
- type PermissionResolvable,
type Snowflake,
type TextChannel,
type UserResolvable
@@ -43,6 +43,8 @@ import { inspect, promisify } from 'util';
import CommandErrorListener from '../../../listeners/commands/commandError.js';
import { Format } from '../../common/util/Format.js';
+export type StripPrivate<T> = { [K in keyof T]: T[K] extends Record<string, any> ? StripPrivate<T[K]> : T[K] };
+
export class BushClientUtil extends ClientUtil {
/**
* The client.
@@ -208,7 +210,7 @@ export class BushClientUtil extends ClientUtil {
if (author)
embed = embed.setAuthor({
name: author.username,
- iconURL: author.displayAvatarURL({ dynamic: true }),
+ iconURL: author.displayAvatarURL(),
url: `https://discord.com/users/${author.id}`
});
if (color) embed = embed.setColor(color);
@@ -425,7 +427,7 @@ export class BushClientUtil extends ClientUtil {
* @returns The combined elements or `ifEmpty`.
*
* @example
- * const permissions = oxford(['ADMINISTRATOR', 'SEND_MESSAGES', 'MANAGE_MESSAGES'], 'and', 'none');
+ * 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
*/
public oxford(array: string[], conjunction: string, ifEmpty?: string): string | undefined {
@@ -785,10 +787,10 @@ export class BushClientUtil extends ClientUtil {
* @param permissions The permissions to check for.
* @returns The missing permissions or null if none are missing.
*/
- public userGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: PermissionResolvable) {
+ public userGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[]) {
const missing = message.member?.permissions.missing(permissions) ?? [];
- return missing.length ? missing : null;
+ return missing.length ? missing.map((p) => Permissions.FLAGS[p]) : null;
}
/**
@@ -797,10 +799,10 @@ export class BushClientUtil extends ClientUtil {
* @param permissions The permissions to check for.
* @returns The missing permissions or null if none are missing.
*/
- public clientGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: PermissionResolvable) {
+ public clientGuildPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[]) {
const missing = message.guild?.me?.permissions.missing(permissions) ?? [];
- return missing.length ? missing : null;
+ return missing.length ? missing.map((p) => Permissions.FLAGS[p]) : null;
}
/**
@@ -811,19 +813,18 @@ export class BushClientUtil extends ClientUtil {
* @param checkChannel Whether to check the channel permissions instead of the guild permissions.
* @returns The missing permissions or null if none are missing.
*/
- public clientSendAndPermCheck(
- message: BushMessage | BushSlashMessage,
- permissions: PermissionResolvable = [],
- checkChannel = false
- ) {
+ public clientSendAndPermCheck(message: BushMessage | BushSlashMessage, permissions: bigint[] = [], checkChannel = false) {
const missing = [];
- const sendPerm = message.channel!.isThread() ? 'SEND_MESSAGES' : 'SEND_MESSAGES_IN_THREADS';
+ const sendPerm = message.channel!.isThread() ? Permissions.FLAGS.SEND_MESSAGES : Permissions.FLAGS.SEND_MESSAGES_IN_THREADS;
if (!message.guild!.me!.permissionsIn(message.channel!.id!).has(sendPerm)) missing.push(sendPerm);
missing.push(
...(checkChannel
- ? message.guild!.me!.permissionsIn(message.channel!.id!).missing(permissions)
+ ? message
+ .guild!.me!.permissionsIn(message.channel!.id!)
+ .missing(permissions)
+ .map((p) => Permissions.FLAGS[p])
: this.clientGuildPermCheck(message, permissions) ?? [])
);
@@ -894,6 +895,12 @@ export class BushClientUtil extends ClientUtil {
return Object.fromEntries(values);
}
+ public get invite() {
+ return `https://discord.com/api/oauth2/authorize?client_id=${client.user!.id}&permissions=${
+ Permissions.ALL
+ }&scope=bot%20applications.commands`;
+ }
+
/**
* A wrapper for the Argument class that adds custom typings.
*/
diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts
index fb488be..0456b80 100644
--- a/src/lib/extensions/discord-akairo/BushCommand.ts
+++ b/src/lib/extensions/discord-akairo/BushCommand.ts
@@ -315,12 +315,12 @@ export interface BaseBushCommandOptions
/**
* Permissions required by the client to run this command.
*/
- clientPermissions: PermissionResolvable | PermissionResolvable[] | BushMissingPermissionSupplier;
+ clientPermissions: bigint | bigint[] | BushMissingPermissionSupplier;
/**
* Permissions required by the user to run this command.
*/
- userPermissions: PermissionResolvable | PermissionResolvable[] | BushMissingPermissionSupplier;
+ userPermissions: bigint | bigint[] | BushMissingPermissionSupplier;
/**
* Restrict this argument to owners
diff --git a/src/lib/extensions/discord-akairo/BushSlashMessage.ts b/src/lib/extensions/discord-akairo/BushSlashMessage.ts
index cefd360..d342ea6 100644
--- a/src/lib/extensions/discord-akairo/BushSlashMessage.ts
+++ b/src/lib/extensions/discord-akairo/BushSlashMessage.ts
@@ -1,4 +1,5 @@
import {
+ BushGuildTextBasedChannel,
type BushClient,
type BushCommandUtil,
type BushGuild,
@@ -7,14 +8,14 @@ import {
type BushUser
} from '#lib';
import { AkairoMessage } from 'discord-akairo';
-import { type CommandInteraction } from 'discord.js';
+import { type ChatInputCommandInteraction, type ContextMenuCommandInteraction } from 'discord.js';
export class BushSlashMessage extends AkairoMessage {
public declare client: BushClient;
public declare util: BushCommandUtil<BushSlashMessage>;
public declare author: BushUser;
public declare member: BushGuildMember | null;
- public constructor(client: BushClient, interaction: CommandInteraction) {
+ public constructor(client: BushClient, interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction) {
super(client, interaction);
}
}
@@ -22,5 +23,10 @@ export class BushSlashMessage extends AkairoMessage {
export interface BushSlashMessage extends AkairoMessage {
get channel(): BushTextBasedChannel | null;
get guild(): BushGuild | null;
- inGuild(): this is this & { guild: BushGuild; member: BushGuildMember };
+ inGuild(): this is BushSlashMessageInGuild & this;
+}
+
+interface BushSlashMessageInGuild {
+ guild: BushGuild;
+ channel: BushGuildTextBasedChannel;
}