Socket
Socket
Sign inDemoInstall

@notenoughupdates/discord-akairo

Package Overview
Dependencies
0
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 9.1.3-dev.1653854301.456923a to 9.1.3-dev.1655139686.c58c530

.yarn/cache/@discordjs-builders-npm-0.16.0-dev.1654949068-96053ba-5aff0216b3-6ad6bb403b.zip

18

dist/package.json
{
"name": "@notenoughupdates/discord-akairo",
"version": "9.1.3-dev.1653854301.456923a",
"version": "9.1.3-dev.1655139686.c58c530",
"description": "A highly customizable bot framework for Discord.js.",

@@ -41,18 +41,18 @@ "main": "./dist/src/index.js",

"@favware/npm-deprecate": "^1.0.4",
"@types/node": "^17.0.36",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"@types/node": "^17.0.42",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"copyfiles": "^2.4.1",
"discord-api-types": "0.33.0",
"discord-api-types": "0.33.5",
"discord.js": "npm:@notenoughupdates/discord.js@dev",
"eslint": "^8.16.0",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-deprecation": "^1.3.2",
"node-fetch": "^3.2.4",
"node-fetch": "^3.2.6",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"typedoc": "^0.22.15",
"typescript": "^4.7.2"
"typedoc": "^0.22.17",
"typescript": "^4.7.3"
},
"packageManager": "yarn@3.2.1"
}

@@ -1,2 +0,1 @@

/// <reference types="node" />
import { Collection } from "discord.js";

@@ -3,0 +2,0 @@ import EventEmitter from "events";

/// <reference types="node" />
import { APIEmbed } from "discord-api-types/v10";
import { Attachment, BufferResolvable, Collection, EmbedBuilder, EmbedData, Emoji, Guild, GuildChannel, GuildMember, PermissionsString, Role, Snowflake, ThreadChannel, User } from "discord.js";
import { AttachmentBuilder, BufferResolvable, Collection, EmbedBuilder, EmbedData, Emoji, Guild, GuildBasedChannel, GuildMember, PermissionsString, Role, Snowflake, User } from "discord.js";
import type { Stream } from "stream";

@@ -22,4 +22,5 @@ import type { AkairoClient } from "./AkairoClient.js";

* @param name - The filename.
* @param description - The description of the file.
*/
attachment(file: BufferResolvable | Stream, name?: string): Attachment;
attachment(file: BufferResolvable | Stream, name?: string, description?: string): AttachmentBuilder;
/**

@@ -32,3 +33,3 @@ * Checks if a string could be referring to a channel.

*/
checkChannel<C extends ThreadChannel | GuildChannel>(text: string, channel: C, caseSensitive?: boolean, wholeWord?: boolean): boolean;
checkChannel<C extends GuildBasedChannel>(text: string, channel: C, caseSensitive?: boolean, wholeWord?: boolean): boolean;
/**

@@ -109,3 +110,3 @@ * Checks if a string could be referring to a emoji.

*/
resolveChannel<C extends ThreadChannel | GuildChannel>(text: string, channels: Collection<Snowflake, C>, caseSensitive?: boolean, wholeWord?: boolean): C | null;
resolveChannel<C extends GuildBasedChannel>(text: string, channels: Collection<Snowflake, C>, caseSensitive?: boolean, wholeWord?: boolean): C | null;
/**

@@ -118,3 +119,3 @@ * Resolves multiple channels from a string, such as an ID, a name, or a mention.

*/
resolveChannels<C extends ThreadChannel | GuildChannel>(text: string, channels: Collection<Snowflake, C>, caseSensitive?: boolean, wholeWord?: boolean): Collection<Snowflake, C>;
resolveChannels<C extends GuildBasedChannel>(text: string, channels: Collection<Snowflake, C>, caseSensitive?: boolean, wholeWord?: boolean): Collection<Snowflake, C>;
/**

@@ -121,0 +122,0 @@ * Resolves a custom emoji from a string, such as a name or a mention.

@@ -19,5 +19,6 @@ "use strict";

* @param name - The filename.
* @param description - The description of the file.
*/
attachment(file, name) {
return new discord_js_1.Attachment(file, name);
attachment(file, name, description) {
return new discord_js_1.AttachmentBuilder(file, { name, description });
}

@@ -24,0 +25,0 @@ /**

@@ -175,3 +175,3 @@ "use strict";

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isText())
if (channel?.type !== discord_js_1.ChannelType.GuildText)
return null;

@@ -188,3 +188,3 @@ return channel;

return null;
const textChannels = channels.filter(c => c.isText());
const textChannels = channels.filter(c => c.type === discord_js_1.ChannelType.GuildText);
return textChannels.size ? textChannels : null;

@@ -198,3 +198,3 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isVoice())
if (channel?.type !== discord_js_1.ChannelType.GuildVoice)
return null;

@@ -211,3 +211,3 @@ return channel;

return null;
const voiceChannels = channels.filter(c => c.isVoice());
const voiceChannels = channels.filter(c => c.type === discord_js_1.ChannelType.GuildVoice);
return voiceChannels.size ? voiceChannels : null;

@@ -221,3 +221,3 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isCategory())
if (channel?.type !== discord_js_1.ChannelType.GuildCategory)
return null;

@@ -234,3 +234,3 @@ return channel;

return null;
const categoryChannels = channels.filter(c => c.isCategory());
const categoryChannels = channels.filter(c => c.type === discord_js_1.ChannelType.GuildCategory);
return categoryChannels.size ? categoryChannels : null;

@@ -244,3 +244,3 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isNews())
if (channel?.type !== discord_js_1.ChannelType.GuildNews)
return null;

@@ -257,3 +257,3 @@ return channel;

return null;
const newsChannels = channels.filter(c => c.isNews());
const newsChannels = channels.filter(c => c.type === discord_js_1.ChannelType.GuildNews);
return newsChannels.size ? newsChannels : null;

@@ -267,3 +267,3 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isStage())
if (channel?.type !== discord_js_1.ChannelType.GuildStageVoice)
return null;

@@ -280,3 +280,3 @@ return channel;

return null;
const stageChannels = channels.filter(c => c.isStage());
const stageChannels = channels.filter(c => c.type === discord_js_1.ChannelType.GuildStageVoice);
return stageChannels.size ? stageChannels : null;

@@ -311,3 +311,4 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isDirectory())
// @ts-expect-error
if (channel?.type !== discord_js_1.ChannelType.GuildDirectory)
return null;

@@ -324,3 +325,4 @@ return channel;

return null;
const directoryChannels = channels.filter(c => c.isDirectory());
// @ts-expect-error
const directoryChannels = channels.filter(c => c.type === discord_js_1.ChannelType.GuildDirectory);
return directoryChannels.size ? directoryChannels : null;

@@ -327,0 +329,0 @@ },

@@ -1,2 +0,2 @@

import { ApplicationCommandAutocompleteOption, ApplicationCommandChannelOptionData, ApplicationCommandChoicesData, ApplicationCommandNonOptionsData, ApplicationCommandNumericOptionData, ApplicationCommandPermissionData, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, AutocompleteInteraction, Guild, LocalizationMap, Message, PermissionResolvable, Snowflake } from "discord.js";
import { ApplicationCommandAutocompleteOption, ApplicationCommandChannelOptionData, ApplicationCommandChoicesData, ApplicationCommandNonOptionsData, ApplicationCommandNumericOptionData, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, AutocompleteInteraction, LocalizationMap, Message, PermissionResolvable, Snowflake } from "discord.js";
import type { AkairoMessage } from "../../util/AkairoMessage.js";

@@ -46,3 +46,3 @@ import type { Category } from "../../util/Category.js";

*/
clientPermissions?: PermissionResolvable | PermissionResolvable[] | MissingPermissionSupplier;
clientPermissions?: PermissionResolvable | MissingPermissionSupplier;
/**

@@ -91,3 +91,3 @@ * Cooldown in milliseconds.

*/
lock?: KeySupplier | "channel" | "guild" | "user";
lock?: KeySupplier;
/**

@@ -126,7 +126,11 @@ * Stores the current locks.

/**
* The default permission to set when creating the slash command.
* The default bitfield used to determine whether this command be used in a guild
*/
slashDefaultMemberPermissions?: PermissionResolvable;
/**
* Whether the command is enabled in DMs
*
* **Note:** Requires the useSlashPermissions to be enabled in the command handler
* **Cannot be enabled for commands that specify `slashGuilds`**
*/
slashDefaultPermission: boolean;
slashDmPermission?: boolean;
/**

@@ -145,6 +149,2 @@ * Whether slash command responses for this command should be ephemeral or not.

/**
* The slash permissions to set in each guild for this command.
*/
slashPermissions?: ApplicationCommandPermissionData[] | SlashPermissionsSupplier;
/**
* Only allows this command to be executed as a slash command.

@@ -164,3 +164,3 @@ */

*/
userPermissions?: PermissionResolvable | PermissionResolvable[] | MissingPermissionSupplier;
userPermissions?: PermissionResolvable | MissingPermissionSupplier;
/**

@@ -262,3 +262,3 @@ * Generator for arguments.

*/
clientPermissions?: PermissionResolvable | PermissionResolvable[] | MissingPermissionSupplier;
clientPermissions?: PermissionResolvable | MissingPermissionSupplier;
/**

@@ -350,8 +350,14 @@ * Whether or not to run on messages that are not directly commands.

/**
* The default permission to set when creating the slash command.
* The default bitfield used to determine whether this command be used in a guild
* @default typeof this.userPermissions !== "function" ? this.userPermissions : undefined
*/
slashDefaultMemberPermissions?: PermissionResolvable;
/**
* Whether the command is enabled in DMs
*
* **Note:** Requires `useSlashPermissions` to be enabled in the command handler
* @default this.handler.useSlashPermissions ? !this.ownerOnly : true
* **Cannot be enabled for commands that specify `slashGuilds`**
*
* @default this.channel === 'dm'
*/
slashDefaultPermission?: boolean;
slashDmPermission?: boolean;
/**

@@ -372,6 +378,2 @@ * Whether slash command responses for this command should be ephemeral or not.

/**
* The slash permissions to set in each guild for this command.
*/
slashPermissions?: ApplicationCommandPermissionData[] | SlashPermissionsSupplier;
/**
* Only allow this command to be used as a slash command. Also makes `slash` `true`

@@ -394,3 +396,3 @@ */

*/
userPermissions?: PermissionResolvable | PermissionResolvable[] | MissingPermissionSupplier;
userPermissions?: PermissionResolvable | MissingPermissionSupplier;
}

@@ -420,7 +422,2 @@ /**

/**
* A function used to create slash permissions depending on the guild.
* @param guild The guild to create slash permissions for.
*/
export declare type SlashPermissionsSupplier = (guild: Guild) => ApplicationCommandPermissionData[];
/**
* A function used to return a regular expression.

@@ -427,0 +424,0 @@ * @param message - Message to get regex for.

@@ -21,3 +21,5 @@ "use strict";

super(id, { category: options?.category });
const { aliases = [], args = this._args || this.args || [], argumentDefaults = {}, before = this.before || (() => undefined), channel = null, clientPermissions = this.clientPermissions, condition = this.condition || (() => false), cooldown = null, description = "", editable = true, flags = [], ignoreCooldown, ignorePermissions, localization = {}, lock, onlyNsfw = false, optionFlags = [], ownerOnly = false, prefix = this.prefix, quoted = true, ratelimit = 1, regex = this.regex, separator, slash = false, slashDefaultPermission, slashEphemeral = false, slashGuilds = [], slashOnly = false, slashOptions, slashPermissions, superUserOnly = false, typing = false, userPermissions = this.userPermissions } = options ?? {};
const { aliases = [], args = this._args || this.args || [], argumentDefaults = {}, before = this.before || (() => undefined), channel = null, clientPermissions = this.clientPermissions, condition = this.condition || (() => false), cooldown = null, description = "", editable = true, flags = [], ignoreCooldown, ignorePermissions, localization = {}, lock, onlyNsfw = false, optionFlags = [], ownerOnly = false, prefix = this.prefix, quoted = true, ratelimit = 1, regex = this.regex, separator, slash = false, slashEphemeral = false, slashGuilds = [], slashOnly = false, slashOptions, superUserOnly = false, typing = false, userPermissions = this.userPermissions } = options ?? {};
// ts doesn't like it when I reference other properties when using destructuring syntax
const { slashDefaultMemberPermissions = userPermissions && typeof userPermissions !== "function" ? userPermissions : undefined, slashDmPermission = slashGuilds.length > 0 ? channel === null || channel === "dm" : undefined } = options ?? {};
if (!Util_js_1.Util.isArrayOf(aliases, "string"))

@@ -67,4 +69,6 @@ throw new TypeError("options.aliases must be an array of strings.");

throw new TypeError("options.slash must be a boolean.");
if (slashDefaultPermission && typeof slashDefaultPermission !== "boolean")
throw new TypeError("options.slashDefaultPermission must be a boolean.");
if (slashDmPermission !== undefined && typeof slashDmPermission !== "boolean")
throw new TypeError("options.slashDmPermission must be a boolean.");
if (typeof slashDmPermission !== "boolean" && slashGuilds.length > 0)
throw new TypeError("You cannot set `options.slashDmPermission` with commands configured with `options.slashGuilds`.");
if (typeof slashEphemeral !== "boolean")

@@ -78,4 +82,2 @@ throw new TypeError("options.slashEphemeral must be a boolean.");

throw new TypeError("options.slashOptions must be an array of objects.");
if (slashPermissions !== undefined && typeof slashPermissions !== "function" && !Util_js_1.Util.isArrayOf(slashPermissions, "object"))
throw new TypeError("options.slashPermissions must be an array of objects or a function.");
if (typeof superUserOnly !== "boolean")

@@ -107,3 +109,2 @@ throw new TypeError("options.superUserOnly must be a boolean.");

this.editable = Boolean(editable);
this.lock = lock;
this.localization = localization;

@@ -118,9 +119,10 @@ this.onlyNsfw = Boolean(onlyNsfw);

this.userPermissions = typeof userPermissions === "function" ? userPermissions.bind(this) : userPermissions;
if (typeof lock === "string") {
this.lock = {
guild: (message) => message.guild && message.guild.id,
channel: (message) => message.channel.id,
user: (message) => message.author.id
}[lock];
}
this.lock =
typeof lock === "string"
? {
guild: (message) => message.guild && message.guild.id,
channel: (message) => message.channel.id,
user: (message) => message.author.id
}[lock]
: lock;
if (this.lock)

@@ -131,3 +133,4 @@ this.locker = new Set();

this.slash = slash;
this.slashDefaultPermission = slashDefaultPermission;
this.slashDefaultMemberPermissions = slashDefaultMemberPermissions;
this.slashDmPermission = slashDmPermission;
this.slashEphemeral = slashEphemeral;

@@ -137,3 +140,2 @@ this.slashGuilds = slashGuilds;

this.slashOptions = slashOptions;
this.slashPermissions = typeof slashPermissions === "function" ? slashPermissions.bind(this) : slashPermissions;
}

@@ -140,0 +142,0 @@ /**

@@ -154,8 +154,2 @@ /// <reference types="node" />

/**
* Use slash command permissions for owner only commands
*
* Warning: this is experimental
*/
useSlashPermissions: boolean;
/**
* @param client - The Akairo client.

@@ -174,6 +168,2 @@ * @param options - Options.

/**
* updates interaction permissions
*/
protected updateInteractionPermissions(owners: Snowflake | Snowflake[]): Promise<void>;
/**
* Registers a module.

@@ -488,9 +478,2 @@ * @param command - Module to use.

skipBuiltInPostInhibitors?: boolean;
/**
* Use slash command permissions for owner only commands
*
* Warning: this is experimental
* @default false
*/
useSlashPermissions?: boolean;
}

@@ -497,0 +480,0 @@ /**

@@ -19,2 +19,8 @@ "use strict";

class CommandHandler extends AkairoHandler_js_1.AkairoHandler {
// /**
// * Use slash command permissions for owner only commands
// *
// * Warning: this is experimental
// */
// public declare useSlashPermissions: boolean;
/**

@@ -26,3 +32,5 @@ * @param client - The Akairo client.

constructor(client, options) {
const { directory, classToHandle = Command_1.Command, extensions = [".js", ".ts"], automateCategories, loadFilter, blockClient = true, blockBots = true, fetchMembers = false, handleEdits = false, storeMessages = false, commandUtil = false, commandUtilLifetime = 3e5, commandUtilSweepInterval = 3e5, defaultCooldown = 0, ignoreCooldown = client.ownerID, ignorePermissions = [], argumentDefaults = {}, prefix = "!", allowMention = true, aliasReplacement, autoDefer = false, typing = false, autoRegisterSlashCommands = false, execSlash = false, skipBuiltInPostInhibitors = false, useSlashPermissions = false } = options ?? {};
const { directory, classToHandle = Command_1.Command, extensions = [".js", ".ts"], automateCategories, loadFilter, blockClient = true, blockBots = true, fetchMembers = false, handleEdits = false, storeMessages = false, commandUtil = false, commandUtilLifetime = 3e5, commandUtilSweepInterval = 3e5, defaultCooldown = 0, ignoreCooldown = client.ownerID, ignorePermissions = [], argumentDefaults = {}, prefix = "!", allowMention = true, aliasReplacement, autoDefer = false, typing = false, autoRegisterSlashCommands = false, execSlash = false, skipBuiltInPostInhibitors = false
// useSlashPermissions = false
} = options ?? {};
if (!(classToHandle.prototype instanceof Command_1.Command || classToHandle === Command_1.Command)) {

@@ -71,4 +79,3 @@ throw new AkairoError_js_1.AkairoError("INVALID_CLASS_TO_HANDLE", classToHandle.name, Command_1.Command.name);

throw new TypeError("options.skipBuiltInPostInhibitors must be a boolean.");
if (typeof useSlashPermissions !== "boolean")
throw new TypeError("options.useSlashPermissions must be a boolean.");
// if (typeof useSlashPermissions !== "boolean") throw new TypeError("options.useSlashPermissions must be a boolean.");
super(client, {

@@ -128,4 +135,4 @@ directory,

this.execSlash = Boolean(execSlash);
this.skipBuiltInPostInhibitors = Boolean(skipBuiltInPostInhibitors);
this.useSlashPermissions = Boolean(useSlashPermissions);
// this.skipBuiltInPostInhibitors = Boolean(skipBuiltInPostInhibitors);
// this.useSlashPermissions = Boolean(useSlashPermissions);
this.setup();

@@ -138,7 +145,6 @@ }

this.client.once("ready", () => {
if (this.autoRegisterSlashCommands)
this.registerInteractionCommands().then(() => {
if (this.useSlashPermissions)
this.updateInteractionPermissions(this.client.ownerID /* this.client.superUserID */);
});
// if (this.autoRegisterSlashCommands)
// this.registerInteractionCommands().then(() => {
// if (this.useSlashPermissions) this.updateInteractionPermissions(this.client.ownerID /* this.client.superUserID */);
// });
this.client.on("messageCreate", async (m) => {

@@ -167,3 +173,3 @@ const message = m.partial ? await m.fetch().catch(() => null) : m;

this.handleSlash(i);
if (i.isAutocomplete())
if (i.type === discord_js_1.InteractionType.ApplicationCommandAutocomplete)
this.handleAutocomplete(i);

@@ -207,3 +213,4 @@ });

guilds: data.slashGuilds ?? [],
defaultPermission: data.slashDefaultPermission,
defaultMemberPermissions: data.slashDefaultMemberPermissions,
dmPermission: data.slashDmPermission,
type: discord_js_1.ApplicationCommandType.ChatInput,

@@ -226,3 +233,4 @@ nameLocalizations: data.localization.nameLocalizations,

guilds: data.guilds ?? [],
defaultPermission: this.useSlashPermissions ? !(data.ownerOnly || /* data.superUserOnly || */ false) : true,
defaultMemberPermissions: data.defaultMemberPermissions,
dmPermission: data.dmPermission,
type: data.type,

@@ -240,3 +248,4 @@ nameLocalizations: data.nameLocalizations

options: options.type === discord_js_1.ApplicationCommandType.ChatInput ? options.options ?? [] : undefined,
defaultPermission: options.defaultPermission,
defaultMemberPermissions: options.defaultMemberPermissions,
dmPermission: options.dmPermission,
type: options.type,

@@ -258,3 +267,4 @@ nameLocalizations: options.nameLocalizations,

options: options.options,
defaultPermission: options.defaultPermission,
defaultMemberPermissions: options.defaultMemberPermissions,
dmPermission: options.dmPermission,
type: options.type,

@@ -292,3 +302,4 @@ nameLocalizations: options.nameLocalizations,

options: options.type === discord_js_1.ApplicationCommandType.ChatInput ? options.options ?? [] : undefined,
defaultPermission: options.defaultPermission,
defaultMemberPermissions: options.defaultMemberPermissions,
dmPermission: options.dmPermission,
type: options.type,

@@ -318,3 +329,4 @@ nameLocalizations: options.nameLocalizations,

options: options.options,
defaultPermission: options.defaultPermission,
defaultMemberPermissions: options.defaultMemberPermissions,
dmPermission: options.dmPermission,
type: options.type,

@@ -346,56 +358,65 @@ nameLocalizations: options.nameLocalizations,

}
// /**
// * updates interaction permissions
// */
// protected async updateInteractionPermissions(owners: Snowflake | Snowflake[] /* superUsers: Snowflake | Snowflake[] */) {
// const mapCom = (
// value: ApplicationCommand<{ guild: GuildResolvable }>,
// guild: Guild
// ): GuildApplicationCommandPermissionData => {
// const command = this.modules.find(mod => mod.aliases[0] === value.name);
// if (!command?.slashPermissions) {
// let allowedUsers: string[] = [];
// /* if (command.superUserOnly) allowedUsers.push(...Util.intoArray(superUsers)); */
// if (command?.ownerOnly) allowedUsers.push(...Util.intoArray(owners));
// allowedUsers = [...new Set(allowedUsers)]; // remove duplicates
// return {
// id: value.id,
// permissions: allowedUsers.map(u => ({
// id: u,
// type: ApplicationCommandPermissionType.User,
// permission: true
// }))
// };
// } else {
// return {
// id: value.id,
// permissions: typeof command.slashPermissions === "function" ? command.slashPermissions(guild) : command.slashPermissions
// };
// }
// };
// const globalCommands = (await this.client.application?.commands.fetch())?.filter(value =>
// Boolean(this.modules.find(mod => mod.aliases[0] === value.name))
// );
// const fullPermissions = globalCommands
// ?.filter(value => !value.defaultPermission)
// .filter(value => Boolean(this.modules.find(mod => mod.aliases[0] === value.name)));
// const promises = this.client.guilds.cache.map(
// /* async */ guild => {
// const perms = new Array(...((fullPermissions ?? new Collection()).map(value => mapCom(value, guild)) ?? []));
// // await guild.commands.fetch();
// if (guild.commands.cache.size)
// perms.push(...guild.commands.cache.filter(value => !value.defaultPermission).map(value => mapCom(value, guild)));
// if (guild.available)
// return guild.commands.permissions.set({
// fullPermissions: perms
// });
// // Return empty promise if guild is unavailable
// return Promise.resolve();
// }
// );
// try {
// await Promise.all(promises);
// } catch (e) {
// this.client.emit(
// "akairoDebug",
// "[updateInteractionPermissions] Error updating interaction permissions, here are the promises, globalCommands, and fullPermissions",
// promises,
// globalCommands,
// fullPermissions
// );
// throw e;
// }
// }
/**
* updates interaction permissions
*/
async updateInteractionPermissions(owners /* superUsers: Snowflake | Snowflake[] */) {
const mapCom = (value, guild) => {
const command = this.modules.find(mod => mod.aliases[0] === value.name);
if (!command?.slashPermissions) {
let allowedUsers = [];
/* if (command.superUserOnly) allowedUsers.push(...Util.intoArray(superUsers)); */
if (command?.ownerOnly)
allowedUsers.push(...Util_js_1.Util.intoArray(owners));
allowedUsers = [...new Set(allowedUsers)]; // remove duplicates
return {
id: value.id,
permissions: allowedUsers.map(u => ({
id: u,
type: discord_js_1.ApplicationCommandPermissionType.User,
permission: true
}))
};
}
else {
return {
id: value.id,
permissions: typeof command.slashPermissions === "function" ? command.slashPermissions(guild) : command.slashPermissions
};
}
};
const globalCommands = (await this.client.application?.commands.fetch())?.filter(value => Boolean(this.modules.find(mod => mod.aliases[0] === value.name)));
const fullPermissions = globalCommands
?.filter(value => !value.defaultPermission)
.filter(value => Boolean(this.modules.find(mod => mod.aliases[0] === value.name)));
const promises = this.client.guilds.cache.map(
/* async */ guild => {
const perms = new Array(...((fullPermissions ?? new discord_js_1.Collection()).map(value => mapCom(value, guild)) ?? []));
// await guild.commands.fetch();
if (guild.commands.cache.size)
perms.push(...guild.commands.cache.filter(value => !value.defaultPermission).map(value => mapCom(value, guild)));
if (guild.available)
return guild.commands.permissions.set({
fullPermissions: perms
});
// Return empty promise if guild is unavailable
return Promise.resolve();
});
try {
await Promise.all(promises);
}
catch (e) {
this.client.emit("akairoDebug", "[updateInteractionPermissions] Error updating interaction permissions, here are the promises, globalCommands, and fullPermissions", promises, globalCommands, fullPermissions);
throw e;
}
}
/**
* Registers a module.

@@ -407,4 +428,4 @@ * @param command - Module to use.

super.register(command, filepath);
if (command.slashDefaultPermission === undefined)
command.slashDefaultPermission = this.useSlashPermissions ? !command.ownerOnly : true;
// if (command.slashDefaultPermission === undefined)
// command.slashDefaultPermission = this.useSlashPermissions ? !command.ownerOnly : true;
for (let alias of command.aliases) {

@@ -411,0 +432,0 @@ const conflict = this.aliases.get(alias.toLowerCase());

@@ -1,2 +0,2 @@

import { ApplicationCommandType, LocalizationMap, type ContextMenuCommandInteraction, type Snowflake } from "discord.js";
import { ApplicationCommandType, LocalizationMap, PermissionResolvable, type ContextMenuCommandInteraction, type Snowflake } from "discord.js";
import type { Category } from "../../util/Category.js";

@@ -51,2 +51,12 @@ import type { AkairoClient } from "../AkairoClient.js";

/**
* The default bitfield used to determine whether this command be used in a guild
*/
defaultMemberPermissions?: PermissionResolvable;
/**
* Whether the command is enabled in DMs
*
* **Cannot be enabled for command that specify `guilds`**
*/
dmPermission?: boolean;
/**
* @param id - Listener ID.

@@ -78,2 +88,3 @@ * @param options - Options for the context menu command.

* Assign context menu commands to Specific guilds. This option will make the commands not register globally, but only in the chosen servers.
* @default []
*/

@@ -101,3 +112,13 @@ guilds?: Snowflake[];

nameLocalizations?: LocalizationMap;
/**
* The default bitfield used to determine whether this command be used in a guild
*/
slashDefaultMemberPermissions?: PermissionResolvable;
/**
* Whether the command is enabled in DMs
*
* **Cannot be enabled for commands that specify `guilds`**
*/
slashDmPermission?: boolean;
}
//# sourceMappingURL=ContextMenuCommand.d.ts.map

@@ -18,3 +18,3 @@ "use strict";

constructor(id, options) {
const { category, guilds, name, ownerOnly, superUserOnly, type, nameLocalizations } = options;
const { category, guilds = [], name, ownerOnly, superUserOnly, type, nameLocalizations, slashDefaultMemberPermissions, slashDmPermission } = options;
if (category !== undefined && typeof category !== "string")

@@ -32,2 +32,6 @@ throw new TypeError("options.category must be a string.");

throw new TypeError("options.nameLocalizations must be a object.");
if (slashDmPermission != null && typeof slashDmPermission !== "boolean")
throw new TypeError("options.slashDmPermission must be a boolean.");
if (slashDmPermission != null && guilds.length > 0)
throw new TypeError("You cannot set `options.slashDmPermission` with commands configured with `options.slashGuilds`.");
super(id, { category });

@@ -40,2 +44,4 @@ this.guilds = guilds;

this.nameLocalizations = nameLocalizations;
this.defaultMemberPermissions = slashDefaultMemberPermissions;
this.dmPermission = slashDmPermission;
}

@@ -42,0 +48,0 @@ /**

@@ -1,2 +0,1 @@

/// <reference types="node" />
import EventEmitter from "events";

@@ -3,0 +2,0 @@ import type { Category } from "../../util/Category.js";

@@ -1,2 +0,1 @@

/// <reference types="node" />
import { Awaitable, Collection } from "discord.js";

@@ -3,0 +2,0 @@ import type EventEmitter from "events";

@@ -1,2 +0,1 @@

/// <reference types="node" />
import EventEmitter from "events";

@@ -3,0 +2,0 @@ import type { PrefixSupplier } from "../struct/commands/CommandHandler";

{
"name": "@notenoughupdates/discord-akairo",
"version": "9.1.3-dev.1653854301.456923a",
"version": "9.1.3-dev.1655139686.c58c530",
"description": "A highly customizable bot framework for Discord.js.",

@@ -41,18 +41,18 @@ "main": "./dist/src/index.js",

"@favware/npm-deprecate": "^1.0.4",
"@types/node": "^17.0.36",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"@types/node": "^17.0.42",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"copyfiles": "^2.4.1",
"discord-api-types": "0.33.0",
"discord-api-types": "0.33.5",
"discord.js": "npm:@notenoughupdates/discord.js@dev",
"eslint": "^8.16.0",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-deprecation": "^1.3.2",
"node-fetch": "^3.2.4",
"node-fetch": "^3.2.6",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"typedoc": "^0.22.15",
"typescript": "^4.7.2"
"typedoc": "^0.22.17",
"typescript": "^4.7.3"
},
"packageManager": "yarn@3.2.1"
}
import { APIEmbed } from "discord-api-types/v10";
import {
ActivityType,
Attachment,
AttachmentBuilder,
BufferResolvable,

@@ -11,3 +11,3 @@ Collection,

Guild,
GuildChannel,
GuildBasedChannel,
GuildMember,

@@ -18,3 +18,2 @@ PermissionFlagsBits,

Snowflake,
ThreadChannel,
User

@@ -45,5 +44,6 @@ } from "discord.js";

* @param name - The filename.
* @param description - The description of the file.
*/
public attachment(file: BufferResolvable | Stream, name?: string): Attachment {
return new Attachment(file, name);
public attachment(file: BufferResolvable | Stream, name?: string, description?: string): AttachmentBuilder {
return new AttachmentBuilder(file, { name, description });
}

@@ -58,8 +58,3 @@

*/
public checkChannel<C extends ThreadChannel | GuildChannel>(
text: string,
channel: C,
caseSensitive = false,
wholeWord = false
): boolean {
public checkChannel<C extends GuildBasedChannel>(text: string, channel: C, caseSensitive = false, wholeWord = false): boolean {
if (channel.id === text) return true;

@@ -267,3 +262,3 @@

*/
public resolveChannel<C extends ThreadChannel | GuildChannel>(
public resolveChannel<C extends GuildBasedChannel>(
text: string,

@@ -284,3 +279,3 @@ channels: Collection<Snowflake, C>,

*/
public resolveChannels<C extends ThreadChannel | GuildChannel>(
public resolveChannels<C extends GuildBasedChannel>(
text: string,

@@ -287,0 +282,0 @@ channels: Collection<Snowflake, C>,

import {
CategoryChannel,
ChannelType,
Collection,

@@ -233,3 +234,3 @@ DirectoryChannel,

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isText()) return null;
if (channel?.type !== ChannelType.GuildText) return null;

@@ -245,3 +246,3 @@ return channel;

const textChannels = <Collection<string, TextChannel>>channels.filter(c => c.isText());
const textChannels = <Collection<string, TextChannel>>channels.filter(c => c.type === ChannelType.GuildText);
return textChannels.size ? textChannels : null;

@@ -254,3 +255,3 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isVoice()) return null;
if (channel?.type !== ChannelType.GuildVoice) return null;
return channel;

@@ -265,3 +266,3 @@ },

const voiceChannels = <Collection<string, VoiceChannel>>channels.filter(c => c.isVoice());
const voiceChannels = <Collection<string, VoiceChannel>>channels.filter(c => c.type === ChannelType.GuildVoice);
return voiceChannels.size ? voiceChannels : null;

@@ -274,3 +275,3 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isCategory()) return null;
if (channel?.type !== ChannelType.GuildCategory) return null;

@@ -286,3 +287,3 @@ return channel;

const categoryChannels = <Collection<string, CategoryChannel>>channels.filter(c => c.isCategory());
const categoryChannels = <Collection<string, CategoryChannel>>channels.filter(c => c.type === ChannelType.GuildCategory);
return categoryChannels.size ? categoryChannels : null;

@@ -295,3 +296,3 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isNews()) return null;
if (channel?.type !== ChannelType.GuildNews) return null;

@@ -307,3 +308,3 @@ return channel;

const newsChannels = <Collection<string, NewsChannel>>channels.filter(c => c.isNews());
const newsChannels = <Collection<string, NewsChannel>>channels.filter(c => c.type === ChannelType.GuildNews);
return newsChannels.size ? newsChannels : null;

@@ -316,3 +317,3 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isStage()) return null;
if (channel?.type !== ChannelType.GuildStageVoice) return null;

@@ -328,3 +329,3 @@ return channel;

const stageChannels = <Collection<string, StageChannel>>channels.filter(c => c.isStage());
const stageChannels = <Collection<string, StageChannel>>channels.filter(c => c.type === ChannelType.GuildStageVoice);
return stageChannels.size ? stageChannels : null;

@@ -356,3 +357,4 @@ },

const channel = this.client.util.resolveChannel(phrase, message.guild.channels.cache);
if (!channel?.isDirectory()) return null;
// @ts-expect-error
if (channel?.type !== ChannelType.GuildDirectory) return null;

@@ -368,3 +370,6 @@ return channel;

const directoryChannels = <Collection<string, DirectoryChannel>>channels.filter(c => c.isDirectory());
// @ts-expect-error
const directoryChannels = <
Collection<string, DirectoryChannel> // @ts-expect-error
>channels.filter(c => c.type === ChannelType.GuildDirectory);
return directoryChannels.size ? directoryChannels : null;

@@ -371,0 +376,0 @@ },

@@ -9,7 +9,5 @@ /* eslint-disable func-names, @typescript-eslint/no-unused-vars */

ApplicationCommandOptionType,
ApplicationCommandPermissionData,
ApplicationCommandSubCommandData,
ApplicationCommandSubGroupData,
AutocompleteInteraction,
Guild,
LocalizationMap,

@@ -74,3 +72,3 @@ Message,

*/
public declare clientPermissions?: PermissionResolvable | PermissionResolvable[] | MissingPermissionSupplier;
public declare clientPermissions?: PermissionResolvable | MissingPermissionSupplier;

@@ -130,3 +128,3 @@ /**

*/
public declare lock?: KeySupplier | "channel" | "guild" | "user";
public declare lock?: KeySupplier;

@@ -174,7 +172,12 @@ /**

/**
* The default permission to set when creating the slash command.
* The default bitfield used to determine whether this command be used in a guild
*/
public declare slashDefaultMemberPermissions?: PermissionResolvable;
/**
* Whether the command is enabled in DMs
*
* **Note:** Requires the useSlashPermissions to be enabled in the command handler
* **Cannot be enabled for commands that specify `slashGuilds`**
*/
public declare slashDefaultPermission: boolean;
public declare slashDmPermission?: boolean;

@@ -197,7 +200,2 @@ /**

/**
* The slash permissions to set in each guild for this command.
*/
public declare slashPermissions?: ApplicationCommandPermissionData[] | SlashPermissionsSupplier;
/**
* Only allows this command to be executed as a slash command.

@@ -220,3 +218,3 @@ */

*/
public declare userPermissions?: PermissionResolvable | PermissionResolvable[] | MissingPermissionSupplier;
public declare userPermissions?: PermissionResolvable | MissingPermissionSupplier;

@@ -261,3 +259,2 @@ /**

slash = false,
slashDefaultPermission,
slashEphemeral = false,

@@ -267,3 +264,2 @@ slashGuilds = [],

slashOptions,
slashPermissions,
superUserOnly = false,

@@ -274,2 +270,8 @@ typing = false,

// ts doesn't like it when I reference other properties when using destructuring syntax
const {
slashDefaultMemberPermissions = userPermissions && typeof userPermissions !== "function" ? userPermissions : undefined,
slashDmPermission = slashGuilds.length > 0 ? channel === null || channel === "dm" : undefined
} = options ?? {};
if (!Util.isArrayOf(aliases, "string")) throw new TypeError("options.aliases must be an array of strings.");

@@ -304,4 +306,6 @@ if (typeof args !== "function" && !Util.isArrayOf(args, "object"))

if (typeof slash !== "boolean") throw new TypeError("options.slash must be a boolean.");
if (slashDefaultPermission && typeof slashDefaultPermission !== "boolean")
throw new TypeError("options.slashDefaultPermission must be a boolean.");
if (slashDmPermission !== undefined && typeof slashDmPermission !== "boolean")
throw new TypeError("options.slashDmPermission must be a boolean.");
if (typeof slashDmPermission !== "boolean" && slashGuilds.length > 0)
throw new TypeError("You cannot set `options.slashDmPermission` with commands configured with `options.slashGuilds`.");
if (typeof slashEphemeral !== "boolean") throw new TypeError("options.slashEphemeral must be a boolean.");

@@ -312,4 +316,2 @@ if (!Util.isArrayOf(slashGuilds, "string")) throw new TypeError("options.slashGuilds must be an array of strings.");

throw new TypeError("options.slashOptions must be an array of objects.");
if (slashPermissions !== undefined && typeof slashPermissions !== "function" && !Util.isArrayOf(slashPermissions, "object"))
throw new TypeError("options.slashPermissions must be an array of objects or a function.");
if (typeof superUserOnly !== "boolean") throw new TypeError("options.superUserOnly must be a boolean.");

@@ -340,3 +342,2 @@ if (typeof typing !== "boolean") throw new TypeError("options.typing must be a boolean.");

this.editable = Boolean(editable);
this.lock = lock;
this.localization = <CommandLocalization>localization;

@@ -351,9 +352,10 @@ this.onlyNsfw = Boolean(onlyNsfw);

this.userPermissions = typeof userPermissions === "function" ? userPermissions.bind(this) : userPermissions;
if (typeof lock === "string") {
this.lock = {
guild: (message: Message | AkairoMessage): string => message.guild! && message.guild.id!,
channel: (message: Message | AkairoMessage): string => message.channel!.id,
user: (message: Message | AkairoMessage): string => message.author.id
}[lock];
}
this.lock =
typeof lock === "string"
? {
guild: (message: Message | AkairoMessage): string => message.guild! && message.guild.id!,
channel: (message: Message | AkairoMessage): string => message.channel!.id,
user: (message: Message | AkairoMessage): string => message.author.id
}[lock]
: lock;
if (this.lock) this.locker = new Set();

@@ -363,3 +365,4 @@ this.ignoreCooldown = typeof ignoreCooldown === "function" ? ignoreCooldown.bind(this) : ignoreCooldown;

this.slash = slash;
this.slashDefaultPermission = slashDefaultPermission!;
this.slashDefaultMemberPermissions = slashDefaultMemberPermissions;
this.slashDmPermission = slashDmPermission;
this.slashEphemeral = slashEphemeral;

@@ -369,3 +372,2 @@ this.slashGuilds = slashGuilds;

this.slashOptions = slashOptions;
this.slashPermissions = typeof slashPermissions === "function" ? slashPermissions.bind(this) : slashPermissions;
}

@@ -485,3 +487,3 @@

*/
clientPermissions?: PermissionResolvable | PermissionResolvable[] | MissingPermissionSupplier;
clientPermissions?: PermissionResolvable | MissingPermissionSupplier;

@@ -592,8 +594,15 @@ /**

/**
* The default permission to set when creating the slash command.
* The default bitfield used to determine whether this command be used in a guild
* @default typeof this.userPermissions !== "function" ? this.userPermissions : undefined
*/
slashDefaultMemberPermissions?: PermissionResolvable;
/**
* Whether the command is enabled in DMs
*
* **Note:** Requires `useSlashPermissions` to be enabled in the command handler
* @default this.handler.useSlashPermissions ? !this.ownerOnly : true
* **Cannot be enabled for commands that specify `slashGuilds`**
*
* @default this.channel === 'dm'
*/
slashDefaultPermission?: boolean;
slashDmPermission?: boolean;

@@ -618,7 +627,2 @@ /**

/**
* The slash permissions to set in each guild for this command.
*/
slashPermissions?: ApplicationCommandPermissionData[] | SlashPermissionsSupplier;
/**
* Only allow this command to be used as a slash command. Also makes `slash` `true`

@@ -644,3 +648,3 @@ */

*/
userPermissions?: PermissionResolvable | PermissionResolvable[] | MissingPermissionSupplier;
userPermissions?: PermissionResolvable | MissingPermissionSupplier;
}

@@ -675,8 +679,2 @@

/**
* A function used to create slash permissions depending on the guild.
* @param guild The guild to create slash permissions for.
*/
export type SlashPermissionsSupplier = (guild: Guild) => ApplicationCommandPermissionData[];
/**
* A function used to return a regular expression.

@@ -683,0 +681,0 @@ * @param message - Message to get regex for.

import {
ApplicationCommand,
ApplicationCommandData,
ApplicationCommandOptionData,
ApplicationCommandOptionType,
ApplicationCommandPermissionType,
ApplicationCommandType,

@@ -16,4 +14,3 @@ AutocompleteInteraction,

Guild,
GuildApplicationCommandPermissionData,
GuildResolvable,
InteractionType,
Message,

@@ -217,8 +214,8 @@ Snowflake,

/**
* Use slash command permissions for owner only commands
*
* Warning: this is experimental
*/
public declare useSlashPermissions: boolean;
// /**
// * Use slash command permissions for owner only commands
// *
// * Warning: this is experimental
// */
// public declare useSlashPermissions: boolean;

@@ -256,4 +253,4 @@ /**

execSlash = false,
skipBuiltInPostInhibitors = false,
useSlashPermissions = false
skipBuiltInPostInhibitors = false
// useSlashPermissions = false
} = options ?? {};

@@ -291,3 +288,3 @@

throw new TypeError("options.skipBuiltInPostInhibitors must be a boolean.");
if (typeof useSlashPermissions !== "boolean") throw new TypeError("options.useSlashPermissions must be a boolean.");
// if (typeof useSlashPermissions !== "boolean") throw new TypeError("options.useSlashPermissions must be a boolean.");

@@ -350,4 +347,4 @@ super(client, {

this.execSlash = Boolean(execSlash);
this.skipBuiltInPostInhibitors = Boolean(skipBuiltInPostInhibitors);
this.useSlashPermissions = Boolean(useSlashPermissions);
// this.skipBuiltInPostInhibitors = Boolean(skipBuiltInPostInhibitors);
// this.useSlashPermissions = Boolean(useSlashPermissions);
this.setup();

@@ -361,6 +358,6 @@ }

this.client.once("ready", () => {
if (this.autoRegisterSlashCommands)
this.registerInteractionCommands().then(() => {
if (this.useSlashPermissions) this.updateInteractionPermissions(this.client.ownerID /* this.client.superUserID */);
});
// if (this.autoRegisterSlashCommands)
// this.registerInteractionCommands().then(() => {
// if (this.useSlashPermissions) this.updateInteractionPermissions(this.client.ownerID /* this.client.superUserID */);
// });

@@ -387,3 +384,3 @@ this.client.on("messageCreate", async m => {

if (i.isChatInputCommand()) this.handleSlash(i);
if (i.isAutocomplete()) this.handleAutocomplete(i);
if (i.type === InteractionType.ApplicationCommandAutocomplete) this.handleAutocomplete(i);
});

@@ -426,3 +423,4 @@ });

guilds: data.slashGuilds ?? [],
defaultPermission: data.slashDefaultPermission,
defaultMemberPermissions: data.slashDefaultMemberPermissions,
dmPermission: data.slashDmPermission,
type: ApplicationCommandType.ChatInput,

@@ -446,3 +444,4 @@ nameLocalizations: data.localization.nameLocalizations,

guilds: data.guilds ?? [],
defaultPermission: this.useSlashPermissions ? !(data.ownerOnly || /* data.superUserOnly || */ false) : true,
defaultMemberPermissions: data.defaultMemberPermissions,
dmPermission: data.dmPermission,
type: data.type,

@@ -461,3 +460,4 @@ nameLocalizations: data.nameLocalizations

options: options.type === ApplicationCommandType.ChatInput ? options.options ?? [] : undefined,
defaultPermission: options.defaultPermission,
defaultMemberPermissions: options.defaultMemberPermissions,
dmPermission: options.dmPermission,
type: options.type,

@@ -477,3 +477,4 @@ nameLocalizations: options.nameLocalizations,

options: options.options,
defaultPermission: options.defaultPermission,
defaultMemberPermissions: options.defaultMemberPermissions,
dmPermission: options.dmPermission,
type: options.type,

@@ -508,3 +509,4 @@ nameLocalizations: options.nameLocalizations,

options: options.type === ApplicationCommandType.ChatInput ? options.options ?? [] : undefined,
defaultPermission: options.defaultPermission,
defaultMemberPermissions: options.defaultMemberPermissions,
dmPermission: options.dmPermission,
type: options.type,

@@ -535,3 +537,4 @@ nameLocalizations: options.nameLocalizations,

options: options.options,
defaultPermission: options.defaultPermission,
defaultMemberPermissions: options.defaultMemberPermissions,
dmPermission: options.dmPermission,
type: options.type,

@@ -566,68 +569,68 @@ nameLocalizations: options.nameLocalizations,

/**
* updates interaction permissions
*/
protected async updateInteractionPermissions(owners: Snowflake | Snowflake[] /* superUsers: Snowflake | Snowflake[] */) {
const mapCom = (
value: ApplicationCommand<{ guild: GuildResolvable }>,
guild: Guild
): GuildApplicationCommandPermissionData => {
const command = this.modules.find(mod => mod.aliases[0] === value.name);
// /**
// * updates interaction permissions
// */
// protected async updateInteractionPermissions(owners: Snowflake | Snowflake[] /* superUsers: Snowflake | Snowflake[] */) {
// const mapCom = (
// value: ApplicationCommand<{ guild: GuildResolvable }>,
// guild: Guild
// ): GuildApplicationCommandPermissionData => {
// const command = this.modules.find(mod => mod.aliases[0] === value.name);
if (!command?.slashPermissions) {
let allowedUsers: string[] = [];
/* if (command.superUserOnly) allowedUsers.push(...Util.intoArray(superUsers)); */
if (command?.ownerOnly) allowedUsers.push(...Util.intoArray(owners));
allowedUsers = [...new Set(allowedUsers)]; // remove duplicates
// if (!command?.slashPermissions) {
// let allowedUsers: string[] = [];
// /* if (command.superUserOnly) allowedUsers.push(...Util.intoArray(superUsers)); */
// if (command?.ownerOnly) allowedUsers.push(...Util.intoArray(owners));
// allowedUsers = [...new Set(allowedUsers)]; // remove duplicates
return {
id: value.id,
permissions: allowedUsers.map(u => ({
id: u,
type: ApplicationCommandPermissionType.User,
permission: true
}))
};
} else {
return {
id: value.id,
permissions: typeof command.slashPermissions === "function" ? command.slashPermissions(guild) : command.slashPermissions
};
}
};
// return {
// id: value.id,
// permissions: allowedUsers.map(u => ({
// id: u,
// type: ApplicationCommandPermissionType.User,
// permission: true
// }))
// };
// } else {
// return {
// id: value.id,
// permissions: typeof command.slashPermissions === "function" ? command.slashPermissions(guild) : command.slashPermissions
// };
// }
// };
const globalCommands = (await this.client.application?.commands.fetch())?.filter(value =>
Boolean(this.modules.find(mod => mod.aliases[0] === value.name))
);
const fullPermissions = globalCommands
?.filter(value => !value.defaultPermission)
.filter(value => Boolean(this.modules.find(mod => mod.aliases[0] === value.name)));
// const globalCommands = (await this.client.application?.commands.fetch())?.filter(value =>
// Boolean(this.modules.find(mod => mod.aliases[0] === value.name))
// );
// const fullPermissions = globalCommands
// ?.filter(value => !value.defaultPermission)
// .filter(value => Boolean(this.modules.find(mod => mod.aliases[0] === value.name)));
const promises = this.client.guilds.cache.map(
/* async */ guild => {
const perms = new Array(...((fullPermissions ?? new Collection()).map(value => mapCom(value, guild)) ?? []));
// await guild.commands.fetch();
if (guild.commands.cache.size)
perms.push(...guild.commands.cache.filter(value => !value.defaultPermission).map(value => mapCom(value, guild)));
if (guild.available)
return guild.commands.permissions.set({
fullPermissions: perms
});
// Return empty promise if guild is unavailable
return Promise.resolve();
}
);
try {
await Promise.all(promises);
} catch (e) {
this.client.emit(
"akairoDebug",
"[updateInteractionPermissions] Error updating interaction permissions, here are the promises, globalCommands, and fullPermissions",
promises,
globalCommands,
fullPermissions
);
throw e;
}
}
// const promises = this.client.guilds.cache.map(
// /* async */ guild => {
// const perms = new Array(...((fullPermissions ?? new Collection()).map(value => mapCom(value, guild)) ?? []));
// // await guild.commands.fetch();
// if (guild.commands.cache.size)
// perms.push(...guild.commands.cache.filter(value => !value.defaultPermission).map(value => mapCom(value, guild)));
// if (guild.available)
// return guild.commands.permissions.set({
// fullPermissions: perms
// });
// // Return empty promise if guild is unavailable
// return Promise.resolve();
// }
// );
// try {
// await Promise.all(promises);
// } catch (e) {
// this.client.emit(
// "akairoDebug",
// "[updateInteractionPermissions] Error updating interaction permissions, here are the promises, globalCommands, and fullPermissions",
// promises,
// globalCommands,
// fullPermissions
// );
// throw e;
// }
// }

@@ -642,4 +645,4 @@ /**

if (command.slashDefaultPermission === undefined)
command.slashDefaultPermission = this.useSlashPermissions ? !command.ownerOnly : true;
// if (command.slashDefaultPermission === undefined)
// command.slashDefaultPermission = this.useSlashPermissions ? !command.ownerOnly : true;

@@ -1824,9 +1827,9 @@ for (let alias of command.aliases) {

/**
* Use slash command permissions for owner only commands
*
* Warning: this is experimental
* @default false
*/
useSlashPermissions?: boolean;
// /**
// * Use slash command permissions for owner only commands
// *
// * Warning: this is experimental
// * @default false
// */
// useSlashPermissions?: boolean;
}

@@ -1833,0 +1836,0 @@

/* eslint-disable func-names, @typescript-eslint/no-unused-vars */
import { ApplicationCommandType, LocalizationMap, type ContextMenuCommandInteraction, type Snowflake } from "discord.js";
import {
ApplicationCommandType,
LocalizationMap,
PermissionResolvable,
type ContextMenuCommandInteraction,
type Snowflake
} from "discord.js";
import { AkairoError } from "../../util/AkairoError.js";

@@ -65,2 +71,14 @@ import type { Category } from "../../util/Category.js";

/**
* The default bitfield used to determine whether this command be used in a guild
*/
public declare defaultMemberPermissions?: PermissionResolvable;
/**
* Whether the command is enabled in DMs
*
* **Cannot be enabled for command that specify `guilds`**
*/
public declare dmPermission?: boolean;
/**
* @param id - Listener ID.

@@ -70,3 +88,13 @@ * @param options - Options for the context menu command.

public constructor(id: string, options: ContextMenuCommandOptions) {
const { category, guilds, name, ownerOnly, superUserOnly, type, nameLocalizations } = options;
const {
category,
guilds = [],
name,
ownerOnly,
superUserOnly,
type,
nameLocalizations,
slashDefaultMemberPermissions,
slashDmPermission
} = options;

@@ -82,2 +110,6 @@ if (category !== undefined && typeof category !== "string") throw new TypeError("options.category must be a string.");

throw new TypeError("options.nameLocalizations must be a object.");
if (slashDmPermission != null && typeof slashDmPermission !== "boolean")
throw new TypeError("options.slashDmPermission must be a boolean.");
if (slashDmPermission != null && guilds.length > 0)
throw new TypeError("You cannot set `options.slashDmPermission` with commands configured with `options.slashGuilds`.");

@@ -92,2 +124,4 @@ super(id, { category });

this.nameLocalizations = nameLocalizations;
this.defaultMemberPermissions = slashDefaultMemberPermissions;
this.dmPermission = slashDmPermission;
}

@@ -122,2 +156,3 @@

* Assign context menu commands to Specific guilds. This option will make the commands not register globally, but only in the chosen servers.
* @default []
*/

@@ -150,2 +185,14 @@ guilds?: Snowflake[];

nameLocalizations?: LocalizationMap;
/**
* The default bitfield used to determine whether this command be used in a guild
*/
slashDefaultMemberPermissions?: PermissionResolvable;
/**
* Whether the command is enabled in DMs
*
* **Cannot be enabled for commands that specify `guilds`**
*/
slashDmPermission?: boolean;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc