Socket
Socket
Sign inDemoInstall

@notenoughupdates/discord-akairo

Package Overview
Dependencies
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@notenoughupdates/discord-akairo - npm Package Compare versions

Comparing version 9.0.10-dev.1642944146.e9691f7 to 9.0.10-dev.1643166025.36345a6

2

dist/package.json
{
"name": "@notenoughupdates/discord-akairo",
"version": "9.0.10-dev.1642944146.e9691f7",
"version": "9.0.10-dev.1643166025.36345a6",
"description": "A highly customizable bot framework for Discord.js.",

@@ -5,0 +5,0 @@ "main": "./dist/src/index.js",

@@ -9,3 +9,3 @@ import "source-map-support/register";

import TypeResolver from "./struct/commands/arguments/TypeResolver";
import Command, { AkairoApplicationCommandAutocompleteOption, AkairoApplicationCommandChannelOptionData, AkairoApplicationCommandChoicesData, AkairoApplicationCommandNonOptionsData, AkairoApplicationCommandNumericOptionData, AkairoApplicationCommandOptionData, AkairoApplicationCommandSubCommandData, AkairoApplicationCommandSubGroupData, ArgumentGenerator, BeforeAction, CommandOptions, ExecutionPredicate, KeySupplier, MissingPermissionSupplier, RegexSupplier, SlashOption, SlashPermissionsSupplier } from "./struct/commands/Command";
import Command, { AkairoApplicationCommandAutocompleteOption, AkairoApplicationCommandChannelOptionData, AkairoApplicationCommandChoicesData, AkairoApplicationCommandNonOptionsData, AkairoApplicationCommandNumericOptionData, AkairoApplicationCommandOptionData, AkairoApplicationCommandSubCommandData, AkairoApplicationCommandSubGroupData, ArgumentGenerator, ArgumentGeneratorReturn, BeforeAction, CommandOptions, ExecutionPredicate, KeySupplier, MissingPermissionSupplier, RegexSupplier, SlashOption, SlashPermissionsSupplier } from "./struct/commands/Command";
import CommandHandler, { CommandHandlerOptions, CooldownData, IgnoreCheckPredicate, MentionPrefixPredicate, ParsedComponentData, PrefixSupplier, RegisterInteractionCommandError, SlashResolveType } from "./struct/commands/CommandHandler";

@@ -42,3 +42,3 @@ import CommandUtil from "./struct/commands/CommandUtil";

export { AkairoClient, AkairoError, AkairoHandler, AkairoMessage, AkairoModule, Argument, ArgumentRunner, ArgumentRunnerState, Category, ClientUtil, Command, CommandHandler, CommandUtil, Constants, ContentParser, ContentParserResult, ContextMenuCommand, ContextMenuCommandHandler, Flag, Inhibitor, InhibitorHandler, Listener, ListenerHandler, PromptContentModifier, RegisterInteractionCommandError, Task, TaskHandler, TypeResolver, Util, version };
export type { AkairoApplicationCommandAutocompleteOption, AkairoApplicationCommandChannelOptionData, AkairoApplicationCommandChoicesData, AkairoApplicationCommandNonOptionsData, AkairoApplicationCommandNumericOptionData, AkairoApplicationCommandOptionData, AkairoApplicationCommandSubCommandData, AkairoApplicationCommandSubGroupData, AkairoClientEvents, AkairoHandlerEvents, AkairoHandlerOptions, AkairoModuleOptions, AkairoOptions, ArgumentGenerator, ArgumentMatch, ArgumentOptions, ArgumentPromptData, ArgumentPromptOptions, ArgumentType, ArgumentTypeCaster, BaseArgumentType, BeforeAction, CommandHandlerEvents, CommandHandlerOptions, CommandOptions, ContentParserOptions, ContextMenuCommandHandlerEvents, ContextMenuCommandOptions, CooldownData, DefaultArgumentOptions, DefaultValueSupplier, ExecutionPredicate, ExtractedFlags, FailureData, IgnoreCheckPredicate, InhibitorHandlerEvents, InhibitorOptions, KeySupplier, ListenerHandlerEvents, ListenerOptions, ListenerType, LoadPredicate, MentionPrefixPredicate, MissingPermissionSupplier, OtherwiseContentModifier, OtherwiseContentSupplier, ParsedComponentData, ParsedValuePredicate, PrefixSupplier, PromptContentSupplier, RegexSupplier, SlashOption, SlashPermissionsSupplier, SlashResolveType as SlashResolveTypes, StringData, TaskHandlerEvents, TaskOptions };
export type { AkairoApplicationCommandAutocompleteOption, AkairoApplicationCommandChannelOptionData, AkairoApplicationCommandChoicesData, AkairoApplicationCommandNonOptionsData, AkairoApplicationCommandNumericOptionData, AkairoApplicationCommandOptionData, AkairoApplicationCommandSubCommandData, AkairoApplicationCommandSubGroupData, AkairoClientEvents, AkairoHandlerEvents, AkairoHandlerOptions, AkairoModuleOptions, AkairoOptions, ArgumentGenerator, ArgumentGeneratorReturn, ArgumentMatch, ArgumentOptions, ArgumentPromptData, ArgumentPromptOptions, ArgumentType, ArgumentTypeCaster, BaseArgumentType, BeforeAction, CommandHandlerEvents, CommandHandlerOptions, CommandOptions, ContentParserOptions, ContextMenuCommandHandlerEvents, ContextMenuCommandOptions, CooldownData, DefaultArgumentOptions, DefaultValueSupplier, ExecutionPredicate, ExtractedFlags, FailureData, IgnoreCheckPredicate, InhibitorHandlerEvents, InhibitorOptions, KeySupplier, ListenerHandlerEvents, ListenerOptions, ListenerType, LoadPredicate, MentionPrefixPredicate, MissingPermissionSupplier, OtherwiseContentModifier, OtherwiseContentSupplier, ParsedComponentData, ParsedValuePredicate, PrefixSupplier, PromptContentSupplier, RegexSupplier, SlashOption, SlashPermissionsSupplier, SlashResolveType as SlashResolveTypes, StringData, TaskHandlerEvents, TaskOptions };
//# sourceMappingURL=index.d.ts.map
/// <reference types="node" />
import { BufferResolvable, Collection, Emoji, Guild, GuildChannel, GuildMember, MessageAttachment, MessageEmbed, MessageEmbedOptions, PermissionString, Role, Snowflake, ThreadChannel, User } from "discord.js";
import { APIEmbed } from "discord-api-types";
import { BufferResolvable, Collection, Embed, Emoji, Guild, GuildChannel, GuildMember, MessageAttachment, PermissionString, Role, Snowflake, ThreadChannel, User } from "discord.js";
import type { Stream } from "stream";

@@ -84,6 +85,6 @@ import type AkairoClient from "./AkairoClient.js";

/**
* Makes a MessageEmbed.
* Makes a Embed.
* @param data - Embed data.
*/
embed(data?: MessageEmbed | MessageEmbedOptions): MessageEmbed;
embed(data?: Embed | APIEmbed): Embed;
/**

@@ -90,0 +91,0 @@ * Combination of `<Client>.fetchUser()` and `<Guild>.fetchMember()`.

@@ -176,7 +176,7 @@ "use strict";

/**
* Makes a MessageEmbed.
* Makes a Embed.
* @param data - Embed data.
*/
embed(data) {
return new discord_js_1.MessageEmbed(data);
return new discord_js_1.Embed(data);
}

@@ -183,0 +183,0 @@ /**

@@ -11,3 +11,3 @@ /// <reference types="node" />

import type CommandHandler from "../CommandHandler.js";
import Flag from "../Flag.js";
import Flag, { FlagType } from "../Flag.js";
import type TypeResolver from "./TypeResolver.js";

@@ -160,5 +160,3 @@ /** ```ts

*/
static isFailure(value: any): value is null | undefined | (Flag & {
value: any;
});
static isFailure(value: unknown): value is null | undefined | Flag<FlagType.Fail>;
/**

@@ -251,7 +249,7 @@ * Creates a type from multiple types (product type).

*/
flag?: string | string[];
flag?: string | string[] | null;
/**
* ID of the argument for use in the args object. This does nothing inside an ArgumentGenerator.
*/
id?: string;
id?: string | null;
/**

@@ -261,3 +259,3 @@ * Index of phrase to start from. Applicable to phrase, text, content, rest, or separate match only.

*/
index?: number;
index?: number | null;
/**

@@ -268,3 +266,3 @@ * Amount of phrases to match when matching more than one.

*/
limit?: number;
limit?: number | null;
/**

@@ -274,7 +272,7 @@ * Method to match text. Defaults to 'phrase'.

*/
match?: ArgumentMatch;
match?: ArgumentMatch | null;
/**
* Function to modify otherwise content.
*/
modifyOtherwise?: OtherwiseContentModifier;
modifyOtherwise?: OtherwiseContentModifier | null;
/**

@@ -286,11 +284,11 @@ * Whether or not to have flags process multiple inputs.

*/
multipleFlags?: boolean;
multipleFlags?: boolean | null;
/**
* Text sent if argument parsing fails. This overrides the `default` option and all prompt options.
*/
otherwise?: string | MessagePayload | MessageOptions | OtherwiseContentSupplier;
otherwise?: string | MessagePayload | MessageOptions | OtherwiseContentSupplier | null;
/**
* Prompt options for when user does not provide input.
*/
prompt?: ArgumentPromptOptions | boolean;
prompt?: ArgumentPromptOptions | boolean | null;
/**

@@ -300,3 +298,3 @@ * Type to cast to.

*/
type?: ArgumentType | ArgumentTypeCaster;
type?: ArgumentType | ArgumentTypeCaster | null;
/**

@@ -312,3 +310,3 @@ * Marks the argument as unordered.

*/
unordered?: boolean | number | number[];
unordered?: boolean | number | number[] | null;
}

@@ -338,5 +336,3 @@ /**

*/
failure: null | (Flag & {
value: any;
});
failure: null | Flag<FlagType.Fail>;
}

@@ -586,5 +582,3 @@ /**

*/
failure: void | (Flag & {
value: any;
});
failure: null | Flag<FlagType.Fail>;
}

@@ -591,0 +585,0 @@ /**

@@ -21,9 +21,6 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Constants_js_1 = require("../../../util/Constants.js");
const Util_js_1 = __importStar(require("../../../util/Util.js"));
const Flag_js_1 = __importDefault(require("../Flag.js"));
const Flag_js_1 = __importStar(require("../Flag.js"));
/**

@@ -37,4 +34,6 @@ * Represents an argument for a command.

*/
// eslint-disable-next-line complexity
constructor(command, options = {}) {
const { match = Constants_js_1.ArgumentMatches.PHRASE, type = Constants_js_1.ArgumentTypes.STRING, flag = null, multipleFlags = false, index = null, unordered = false, limit = Infinity, prompt = null, default: defaultValue = null, otherwise = null, modifyOtherwise = null } = options;
// doing this instead of object deconstruction so its valid to pass null values
const match = options.match ?? Constants_js_1.ArgumentMatches.PHRASE, type = options.type ?? Constants_js_1.ArgumentTypes.STRING, flag = options.flag ?? null, multipleFlags = options.multipleFlags ?? false, index = options.index ?? null, unordered = options.unordered ?? false, limit = options.limit ?? Infinity, prompt = options.prompt ?? null, defaultValue = options.default ?? null, otherwise = options.otherwise ?? null, modifyOtherwise = options.modifyOtherwise ?? null;
if (!Object.values(Constants_js_1.ArgumentMatches).includes(match))

@@ -251,3 +250,3 @@ throw new TypeError(`options.match must one of ${Object.values(Constants_js_1.ArgumentMatches)

phrase,
failure: failure
failure: failure ?? null
});

@@ -356,3 +355,3 @@ if (Array.isArray(text)) {

static isFailure(value) {
return value == null || Flag_js_1.default.is(value, "fail");
return value == null || Flag_js_1.default.is(value, Flag_js_1.FlagType.Fail);
}

@@ -359,0 +358,0 @@ static product(...types) {

import type { Message } from "discord.js";
import Command, { ArgumentGenerator } from "../Command.js";
import Command, { ArgumentGenerator, ArgumentGeneratorReturn } from "../Command.js";
import type { ContentParserResult } from "../ContentParser.js";
import Flag from "../Flag.js";
import Flag, { FlagType } from "../Flag.js";
import Argument from "./Argument.js";

@@ -32,3 +32,5 @@ /**

*/
run(message: Message, parsed: ContentParserResult, generator: ArgumentGenerator): Promise<Flag | any>;
run(message: Message, parsed: ContentParserResult, generator: ArgumentGenerator): Promise<Flag | {
[args: string]: unknown;
}>;
/**

@@ -125,3 +127,3 @@ * Runs one argument.

*/
static isShortCircuit(value: any): boolean;
static isShortCircuit(value: unknown): value is Flag<FlagType.Cancel> | Flag<FlagType.Retry> | Flag<FlagType.Continue>;
/**

@@ -131,5 +133,3 @@ * Creates an argument generator from argument options.

*/
static fromArguments(args: [id: string, argument: Argument][]): () => Generator<Argument, {
[x: string]: any;
}, Argument>;
static fromArguments(args: [id: string, argument: Argument][]): () => ArgumentGeneratorReturn;
}

@@ -136,0 +136,0 @@ /**

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -8,3 +27,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const Constants_js_1 = require("../../../util/Constants.js");
const Flag_js_1 = __importDefault(require("../Flag.js"));
const Flag_js_1 = __importStar(require("../Flag.js"));
const Argument_js_1 = __importDefault(require("./Argument.js"));

@@ -46,3 +65,3 @@ /**

const augmentRest = (val) => {
if (Flag_js_1.default.is(val, "continue")) {
if (Flag_js_1.default.is(val, Flag_js_1.FlagType.Continue)) {
val.rest = parsed.all

@@ -173,3 +192,3 @@ .slice(state.index)

const response = await arg.process(message, phrase.value);
if (Flag_js_1.default.is(response, "cancel")) {
if (Flag_js_1.default.is(response, Flag_js_1.FlagType.Cancel)) {
return response;

@@ -305,3 +324,3 @@ }

static isShortCircuit(value) {
return Flag_js_1.default.is(value, "cancel") || Flag_js_1.default.is(value, "retry") || Flag_js_1.default.is(value, "continue");
return Flag_js_1.default.is(value, Flag_js_1.FlagType.Cancel) || Flag_js_1.default.is(value, Flag_js_1.FlagType.Retry) || Flag_js_1.default.is(value, Flag_js_1.FlagType.Continue);
}

@@ -308,0 +327,0 @@ /**

@@ -6,7 +6,7 @@ import { ApplicationCommandAutocompleteOption, ApplicationCommandChannelOptionData, ApplicationCommandChoicesData, ApplicationCommandNonOptionsData, ApplicationCommandNumericOptionData, ApplicationCommandPermissionData, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, AutocompleteInteraction, Guild, Message, PermissionResolvable, Snowflake } from "discord.js";

import AkairoModule, { AkairoModuleOptions } from "../AkairoModule.js";
import { ArgumentOptions, DefaultArgumentOptions } from "./arguments/Argument.js";
import Argument, { ArgumentOptions, ArgumentTypeCasterReturn, DefaultArgumentOptions } from "./arguments/Argument.js";
import ArgumentRunner, { ArgumentRunnerState } from "./arguments/ArgumentRunner.js";
import CommandHandler, { IgnoreCheckPredicate, PrefixSupplier, SlashResolveType } from "./CommandHandler.js";
import ContentParser, { ContentParserResult } from "./ContentParser.js";
import type Flag from "./Flag.js";
import { type default as Flag } from "./Flag.js";
/**

@@ -175,3 +175,3 @@ * Represents a command.

*/
args(message: Message, parsed: ContentParserResult, state: ArgumentRunnerState): IterableIterator<ArgumentOptions | Flag>;
args(message: Message, parsed: ContentParserResult, state: ArgumentRunnerState): ArgumentGeneratorReturn;
/**

@@ -422,3 +422,6 @@ * Runs before argument parsing and execution.

*/
export declare type ArgumentGenerator = (message: Message, parsed: ContentParserResult, state: ArgumentRunnerState) => IterableIterator<ArgumentOptions | Flag>;
export declare type ArgumentGenerator = (message: Message, parsed: ContentParserResult, state: ArgumentRunnerState) => ArgumentGeneratorReturn;
export declare type ArgumentGeneratorReturn = Generator<ArgumentOptions | Argument | Flag, {
[args: string]: ArgumentTypeCasterReturn<unknown>;
} | Flag, Flag | any>;
export interface AkairoApplicationCommandSubGroupData extends ApplicationCommandSubGroupData {

@@ -425,0 +428,0 @@ options?: AkairoApplicationCommandSubCommandData[];

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

this.argumentRunner = new ArgumentRunner_js_1.default(this);
this.argumentGenerator = (Array.isArray(args) ? ArgumentRunner_js_1.default.fromArguments(args.map(arg => [arg.id, new Argument_js_1.default(this, arg)])) : args.bind(this));
this.argumentGenerator = Array.isArray(args)
? ArgumentRunner_js_1.default.fromArguments(args.map(arg => [arg.id, new Argument_js_1.default(this, arg)]))
: args.bind(this);
this.argumentDefaults = argumentDefaults;

@@ -158,2 +160,3 @@ this.before = before.bind(this);

*/
// @ts-expect-error
*args(message, parsed, state) { }

@@ -160,0 +163,0 @@ /**

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

const CommandUtil_js_1 = __importDefault(require("./CommandUtil.js"));
const Flag_js_1 = __importDefault(require("./Flag.js"));
const Flag_js_1 = __importStar(require("./Flag.js"));
/**

@@ -621,4 +621,3 @@ * Loads commands and handles messages.

}
if (usedSubcommandOrGroup.type === 1 /* Subcommand */ ||
usedSubcommandOrGroup.type === "Subcommand") {
if (usedSubcommandOrGroup.type === 1 /* Subcommand */) {
if (!usedSubcommandOrGroup.options) {

@@ -630,4 +629,3 @@ this.client.emit("akairoDebug", "[handleSlash] Unable to find subcommand options");

}
else if (usedSubcommandOrGroup.type === 2 /* SubcommandGroup */ ||
usedSubcommandOrGroup.type === "SubcommandGroup") {
else if (usedSubcommandOrGroup.type === 2 /* SubcommandGroup */) {
const usedSubCommand = usedSubcommandOrGroup.options?.find(subcommand => subcommand.name === convertedOptions.subcommand);

@@ -747,11 +745,11 @@ if (!usedSubCommand) {

const args = await command.parse(message, content);
if (Flag_js_1.default.is(args, "cancel")) {
if (Flag_js_1.default.is(args, Flag_js_1.FlagType.Cancel)) {
this.emit(Constants_js_1.CommandHandlerEvents.COMMAND_CANCELLED, message, command);
return true;
}
else if (Flag_js_1.default.is(args, "retry")) {
else if (Flag_js_1.default.is(args, Flag_js_1.FlagType.Retry)) {
this.emit(Constants_js_1.CommandHandlerEvents.COMMAND_BREAKOUT, message, command, args.message);
return this.handle(args.message);
}
else if (Flag_js_1.default.is(args, "continue")) {
else if (Flag_js_1.default.is(args, Flag_js_1.FlagType.Continue)) {
const continueCommand = this.modules.get(args.command);

@@ -758,0 +756,0 @@ return this.handleDirectCommand(message, args.rest, continueCommand, args.ignore);

@@ -5,16 +5,49 @@ import type { Message } from "discord.js";

*/
export default class Flag {
export default class Flag<T extends FlagType = FlagType> {
/**
* The type of flag.
*/
type: string;
type: T;
/**
* Message to handle.
*
* Only exists if {@link type} is {@link FlagType.Retry}.
*/
message: T extends FlagType.Retry ? Message : unknown;
/**
* The extra data for the failure.
*
* Only exists if {@link type} is {@link FlagType.Fail}.
*/
value: T extends FlagType.Fail ? any : unknown;
/**
* Command ID.
*
* Only exists if {@link type} is {@link FlagType.Continue}.
*/
command: T extends FlagType.Continue ? string : never;
/**
* Whether or not to ignore permission checks.
*
* Only exists if {@link type} is {@link FlagType.Continue}.
*/
ignore: T extends FlagType.Continue ? boolean : never;
/**
* The rest of the arguments. If this is not set, the argument handler will automatically use the rest of the content.
*
* Only exists if {@link type} is {@link FlagType.Continue}.
*/
rest: T extends FlagType.Continue ? string | null : never;
/**
* @param type - Type of flag.
* @param data - Extra data.
*/
constructor(type: string, data?: any);
private constructor();
private constructor();
private constructor();
private constructor();
/**
* Creates a flag that cancels the command.
*/
static cancel(): Flag;
static cancel(): Flag<FlagType.Cancel>;
/**

@@ -24,3 +57,3 @@ * Creates a flag that retries with another input.

*/
static retry(message: Message): Flag;
static retry(message: Message): Flag<FlagType.Retry>;
/**

@@ -30,3 +63,3 @@ * Creates a flag that acts as argument cast failure with extra data.

*/
static fail(value: any): Flag;
static fail(value: any): Flag<FlagType.Fail>;
/**

@@ -38,3 +71,3 @@ * Creates a flag that runs another command with the rest of the arguments.

*/
static continue(command: string, ignore?: boolean, rest?: string | null): Flag;
static continue(command: string, ignore?: boolean, rest?: string | null): Flag<FlagType.Continue>;
/**

@@ -45,4 +78,13 @@ * Checks if a value is a flag and of some type.

*/
static is(value: any, type: string): boolean;
static is(value: unknown, type: FlagType.Cancel): value is Flag<FlagType.Cancel>;
static is(value: unknown, type: FlagType.Continue): value is Flag<FlagType.Continue>;
static is(value: unknown, type: FlagType.Fail): value is Flag<FlagType.Fail>;
static is(value: unknown, type: FlagType.Retry): value is Flag<FlagType.Retry>;
}
export declare enum FlagType {
Cancel = "cancel",
Retry = "retry",
Fail = "fail",
Continue = "continue"
}
//# sourceMappingURL=Flag.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlagType = void 0;
/**

@@ -7,6 +8,2 @@ * Represents a special return value during command execution or argument parsing.

class Flag {
/**
* @param type - Type of flag.
* @param data - Extra data.
*/
constructor(type, data = {}) {

@@ -20,3 +17,3 @@ this.type = type;

static cancel() {
return new Flag("cancel");
return new Flag(FlagType.Cancel);
}

@@ -28,3 +25,3 @@ /**

static retry(message) {
return new Flag("retry", { message });
return new Flag(FlagType.Retry, { message });
}

@@ -36,3 +33,3 @@ /**

static fail(value) {
return new Flag("fail", { value });
return new Flag(FlagType.Fail, { value });
}

@@ -46,9 +43,4 @@ /**

static continue(command, ignore = false, rest = null) {
return new Flag("continue", { command, ignore, rest });
return new Flag(FlagType.Continue, { command, ignore, rest });
}
/**
* Checks if a value is a flag and of some type.
* @param value - Value to check.
* @param type - Type of flag.
*/
static is(value, type) {

@@ -59,2 +51,9 @@ return value instanceof Flag && value.type === type;

exports.default = Flag;
var FlagType;
(function (FlagType) {
FlagType["Cancel"] = "cancel";
FlagType["Retry"] = "retry";
FlagType["Fail"] = "fail";
FlagType["Continue"] = "continue";
})(FlagType = exports.FlagType || (exports.FlagType = {}));
//# sourceMappingURL=Flag.js.map
{
"name": "@notenoughupdates/discord-akairo",
"version": "9.0.10-dev.1642944146.e9691f7",
"version": "9.0.10-dev.1643166025.36345a6",
"description": "A highly customizable bot framework for Discord.js.",

@@ -5,0 +5,0 @@ "main": "./dist/src/index.js",

@@ -36,2 +36,3 @@ import "source-map-support/register";

ArgumentGenerator,
ArgumentGeneratorReturn,
BeforeAction,

@@ -149,2 +150,3 @@ CommandOptions,

ArgumentGenerator,
ArgumentGeneratorReturn,
ArgumentMatch,

@@ -151,0 +153,0 @@ ArgumentOptions,

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

import { APIEmbed } from "discord-api-types";
import {

@@ -5,2 +6,3 @@ ActivityType,

Collection,
Embed,
Emoji,

@@ -11,4 +13,2 @@ Guild,

MessageAttachment,
MessageEmbed,
MessageEmbedOptions,
Permissions,

@@ -232,7 +232,7 @@ PermissionString,

/**
* Makes a MessageEmbed.
* Makes a Embed.
* @param data - Embed data.
*/
public embed(data?: MessageEmbed | MessageEmbedOptions): MessageEmbed {
return new MessageEmbed(data);
public embed(data?: Embed | APIEmbed): Embed {
return new Embed(data);
}

@@ -239,0 +239,0 @@

@@ -34,3 +34,3 @@ import type {

import type CommandHandler from "../CommandHandler.js";
import Flag from "../Flag.js";
import Flag, { FlagType } from "../Flag.js";
import type TypeResolver from "./TypeResolver.js";

@@ -141,16 +141,16 @@

*/
// eslint-disable-next-line complexity
public constructor(command: Command, options: ArgumentOptions = {}) {
const {
match = ArgumentMatches.PHRASE,
type = ArgumentTypes.STRING,
flag = null,
multipleFlags = false,
index = null,
unordered = false,
limit = Infinity,
prompt = null,
default: defaultValue = null,
otherwise = null,
modifyOtherwise = null
} = options;
// doing this instead of object deconstruction so its valid to pass null values
const match = options.match ?? ArgumentMatches.PHRASE,
type = options.type ?? ArgumentTypes.STRING,
flag = options.flag ?? null,
multipleFlags = options.multipleFlags ?? false,
index = options.index ?? null,
unordered = options.unordered ?? false,
limit = options.limit ?? Infinity,
prompt = options.prompt ?? null,
defaultValue = options.default ?? null,
otherwise = options.otherwise ?? null,
modifyOtherwise = options.modifyOtherwise ?? null;

@@ -211,3 +211,3 @@ if (!Object.values(ArgumentMatches).includes(match))

public cast(message: Message, phrase: string): Promise<any> {
return Argument.cast(this.type as any, this.handler.resolver, message, phrase);
return Argument.cast(this.type, this.handler.resolver, message, phrase);
}

@@ -392,3 +392,3 @@

const doOtherwise = async (failure: (Flag & { value: any }) | null | undefined) => {
const doOtherwise = async (failure: Flag<FlagType.Fail> | null | undefined) => {
const otherwise = this.otherwise ?? commandDefs.otherwise ?? handlerDefs.otherwise ?? null;

@@ -409,3 +409,3 @@

phrase,
failure: failure as Flag & { value: any }
failure: failure ?? null
});

@@ -483,3 +483,3 @@ if (Array.isArray(text)) {

if ((type as any) instanceof RegExp) {
if (type instanceof RegExp) {
const match = phrase.match(type);

@@ -490,6 +490,6 @@ if (!match) return null;

if ((type as any).global) {
if (type.global) {
let matched;
while ((matched = (type as any).exec(phrase)) != null) {
while ((matched = type.exec(phrase)) != null) {
matches.push(matched);

@@ -502,4 +502,4 @@ }

if (resolver.type(type as any)) {
let res = resolver.type(type as any)?.call(this, message, phrase);
if (resolver.type(type)) {
let res = resolver.type(type)?.call(this, message, phrase);
if (Util.isPromise(res)) res = await res;

@@ -525,3 +525,3 @@ return res;

if (typeof entry === "function") entry = entry.bind(this);
acc = await Argument.cast(entry as any, this.handler.resolver, message, acc);
acc = await Argument.cast(entry, this.handler.resolver, message, acc);
if (Argument.isFailure(acc)) return acc;

@@ -547,3 +547,3 @@ }

if (typeof entry === "function") entry = entry.bind(this);
acc = await Argument.cast(entry as any, this.handler.resolver, message, acc);
acc = await Argument.cast(entry, this.handler.resolver, message, acc);
}

@@ -559,4 +559,4 @@

*/
public static isFailure(value: any): value is null | undefined | (Flag & { value: any }) {
return value == null || Flag.is(value, "fail");
public static isFailure(value: unknown): value is null | undefined | Flag<FlagType.Fail> {
return value == null || Flag.is(value, FlagType.Fail);
}

@@ -577,3 +577,3 @@

if (typeof entry === "function") entry = entry.bind(this);
const res = await Argument.cast(entry as any, this.handler.resolver, message, phrase);
const res = await Argument.cast(entry, this.handler.resolver, message, phrase);
if (Argument.isFailure(res)) return res;

@@ -598,3 +598,3 @@ results.push(res);

public static range(type: AT | ATC, min: number, max: number, inclusive = false): ATC {
return Argument.validate(type as any, (msg, p, x) => {
return Argument.validate(type, (msg, p, x) => {
const o = typeof x === "number" || typeof x === "bigint" ? x : x.length != null ? x.length : x.size != null ? x.size : x;

@@ -618,3 +618,3 @@

if (typeof type === "function") type = type.bind(this);
const res = await Argument.cast(type as any, this.handler.resolver, message, phrase);
const res = await Argument.cast(type, this.handler.resolver, message, phrase);
if (Argument.isFailure(res)) {

@@ -640,3 +640,3 @@ return Flag.fail({ tag, value: res });

for (let entry of types) {
entry = Argument.tagged(entry as any);
entry = Argument.tagged(entry);
const res = await Argument.cast(entry, this.handler.resolver, message, phrase);

@@ -662,3 +662,3 @@ if (!Argument.isFailure(res)) return res;

if (typeof type === "function") type = type.bind(this);
const res = await Argument.cast(type as any, this.handler.resolver, message, phrase);
const res = await Argument.cast(type, this.handler.resolver, message, phrase);
if (Argument.isFailure(res)) {

@@ -684,3 +684,3 @@ return Flag.fail({ tag, input: phrase, value: res });

if (typeof entry === "function") entry = entry.bind(this);
const res = await Argument.cast(entry as any, this.handler.resolver, message, phrase);
const res = await Argument.cast(entry, this.handler.resolver, message, phrase);
if (!Argument.isFailure(res)) return res;

@@ -705,3 +705,3 @@ }

if (typeof type === "function") type = type.bind(this);
const res = await Argument.cast(type as any, this.handler.resolver, message, phrase);
const res = await Argument.cast(type, this.handler.resolver, message, phrase);
if (Argument.isFailure(res)) return res;

@@ -724,3 +724,3 @@ if (!predicate.call(this, message, phrase, res)) return null;

if (typeof type === "function") type = type.bind(this);
const res = await Argument.cast(type as any, this.handler.resolver, message, phrase);
const res = await Argument.cast(type, this.handler.resolver, message, phrase);
if (Argument.isFailure(res)) {

@@ -753,3 +753,3 @@ return Flag.fail({ input: phrase, value: res });

*/
flag?: string | string[];
flag?: string | string[] | null;

@@ -759,3 +759,3 @@ /**

*/
id?: string;
id?: string | null;

@@ -766,3 +766,3 @@ /**

*/
index?: number;
index?: number | null;

@@ -774,3 +774,3 @@ /**

*/
limit?: number;
limit?: number | null;

@@ -781,3 +781,3 @@ /**

*/
match?: ArgumentMatch;
match?: ArgumentMatch | null;

@@ -787,3 +787,3 @@ /**

*/
modifyOtherwise?: OtherwiseContentModifier;
modifyOtherwise?: OtherwiseContentModifier | null;

@@ -796,3 +796,3 @@ /**

*/
multipleFlags?: boolean;
multipleFlags?: boolean | null;

@@ -802,3 +802,3 @@ /**

*/
otherwise?: string | MessagePayload | MessageOptions | OtherwiseContentSupplier;
otherwise?: string | MessagePayload | MessageOptions | OtherwiseContentSupplier | null;

@@ -808,3 +808,3 @@ /**

*/
prompt?: ArgumentPromptOptions | boolean;
prompt?: ArgumentPromptOptions | boolean | null;

@@ -815,3 +815,3 @@ /**

*/
type?: ArgumentType | ArgumentTypeCaster;
type?: ArgumentType | ArgumentTypeCaster | null;

@@ -828,3 +828,3 @@ /**

*/
unordered?: boolean | number | number[];
unordered?: boolean | number | number[] | null;
}

@@ -859,3 +859,3 @@

*/
failure: null | (Flag & { value: any });
failure: null | Flag<FlagType.Fail>;
}

@@ -1132,3 +1132,3 @@

*/
failure: void | (Flag & { value: any });
failure: null | Flag<FlagType.Fail>;
}

@@ -1135,0 +1135,0 @@

import type { Message } from "discord.js";
import AkairoError from "../../../util/AkairoError.js";
import { ArgumentMatches } from "../../../util/Constants.js";
import Command, { ArgumentGenerator } from "../Command.js";
import Command, { ArgumentGenerator, ArgumentGeneratorReturn } from "../Command.js";
import type { ContentParserResult } from "../ContentParser.js";
import Flag from "../Flag.js";
import Argument, { ArgumentOptions } from "./Argument.js";
import Flag, { FlagType } from "../Flag.js";
import Argument, { ArgumentOptions, ArgumentTypeCasterReturn } from "./Argument.js";

@@ -45,3 +45,12 @@ /**

*/
public async run(message: Message, parsed: ContentParserResult, generator: ArgumentGenerator): Promise<Flag | any> {
public async run(
message: Message,
parsed: ContentParserResult,
generator: ArgumentGenerator
): Promise<
| Flag
| {
[args: string]: unknown;
}
> {
const state = {

@@ -54,4 +63,4 @@ usedIndices: new Set<number>(),

const augmentRest = (val: Flag | ArgumentOptions) => {
if (Flag.is(val, "continue")) {
(val as any).rest = parsed.all
if (Flag.is(val, FlagType.Continue)) {
val.rest = parsed.all
.slice(state.index)

@@ -216,3 +225,3 @@ .map(x => x.raw)

if (Flag.is(response, "cancel")) {
if (Flag.is(response, FlagType.Cancel)) {
return response;

@@ -381,4 +390,4 @@ }

*/
public static isShortCircuit(value: any): boolean {
return Flag.is(value, "cancel") || Flag.is(value, "retry") || Flag.is(value, "continue");
public static isShortCircuit(value: unknown): value is Flag<FlagType.Cancel> | Flag<FlagType.Retry> | Flag<FlagType.Continue> {
return Flag.is(value, FlagType.Cancel) || Flag.is(value, FlagType.Retry) || Flag.is(value, FlagType.Continue);
}

@@ -391,4 +400,4 @@

public static fromArguments(args: [id: string, argument: Argument][]) {
return function* generate(): Generator<Argument, { [x: string]: any }, Argument> {
const res: { [key: string]: any } = {};
return function* generate(): ArgumentGeneratorReturn {
const res: { [args: string]: ArgumentTypeCasterReturn<unknown> } = {};
for (const [id, arg] of args) {

@@ -395,0 +404,0 @@ res[id] = yield arg;

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

import AkairoModule, { AkairoModuleOptions } from "../AkairoModule.js";
import Argument, { ArgumentOptions, DefaultArgumentOptions } from "./arguments/Argument.js";
import Argument, { ArgumentOptions, ArgumentTypeCasterReturn, DefaultArgumentOptions } from "./arguments/Argument.js";
import ArgumentRunner, { ArgumentRunnerState } from "./arguments/ArgumentRunner.js";
import CommandHandler, { IgnoreCheckPredicate, PrefixSupplier, SlashResolveType } from "./CommandHandler.js";
import ContentParser, { ContentParserResult } from "./ContentParser.js";
import type Flag from "./Flag.js";
import { type default as Flag } from "./Flag.js";

@@ -311,5 +311,5 @@ /**

this.argumentRunner = new ArgumentRunner(this);
this.argumentGenerator = (
Array.isArray(args) ? ArgumentRunner.fromArguments(args.map(arg => [arg.id!, new Argument(this, arg)])) : args.bind(this)
) as ArgumentGenerator;
this.argumentGenerator = Array.isArray(args)
? ArgumentRunner.fromArguments(args.map(arg => [arg.id!, new Argument(this, arg)]))
: args.bind(this);
this.argumentDefaults = argumentDefaults;

@@ -359,7 +359,4 @@ this.before = before.bind(this);

*/
public *args(
message: Message,
parsed: ContentParserResult,
state: ArgumentRunnerState
): IterableIterator<ArgumentOptions | Flag> {}
// @ts-expect-error
public *args(message: Message, parsed: ContentParserResult, state: ArgumentRunnerState): ArgumentGeneratorReturn {}

@@ -671,4 +668,10 @@ /**

state: ArgumentRunnerState
) => IterableIterator<ArgumentOptions | Flag>;
) => ArgumentGeneratorReturn;
export type ArgumentGeneratorReturn = Generator<
ArgumentOptions | Argument | Flag,
{ [args: string]: ArgumentTypeCasterReturn<unknown> } | Flag,
Flag | any
>;
export interface AkairoApplicationCommandSubGroupData extends ApplicationCommandSubGroupData {

@@ -675,0 +678,0 @@ options?: AkairoApplicationCommandSubCommandData[];

@@ -49,3 +49,3 @@ import {

import CommandUtil from "./CommandUtil.js";
import Flag from "./Flag.js";
import Flag, { FlagType } from "./Flag.js";

@@ -865,6 +865,3 @@ /**

}
if (
usedSubcommandOrGroup.type === ApplicationCommandOptionType.Subcommand ||
usedSubcommandOrGroup.type === "Subcommand"
) {
if (usedSubcommandOrGroup.type === ApplicationCommandOptionType.Subcommand) {
if (!(<SubCommand>usedSubcommandOrGroup).options) {

@@ -875,6 +872,3 @@ this.client.emit("akairoDebug", "[handleSlash] Unable to find subcommand options");

handleOptions((<SubCommand>usedSubcommandOrGroup).options!);
} else if (
usedSubcommandOrGroup.type === ApplicationCommandOptionType.SubcommandGroup ||
usedSubcommandOrGroup.type === "SubcommandGroup"
) {
} else if (usedSubcommandOrGroup.type === ApplicationCommandOptionType.SubcommandGroup) {
const usedSubCommand = (<SubCommandGroup>usedSubcommandOrGroup).options?.find(

@@ -999,11 +993,11 @@ subcommand => subcommand.name === convertedOptions.subcommand

const args = await command.parse(message, content);
if (Flag.is(args, "cancel")) {
if (Flag.is(args, FlagType.Cancel)) {
this.emit(CommandHandlerEvents.COMMAND_CANCELLED, message, command);
return true;
} else if (Flag.is(args, "retry")) {
} else if (Flag.is(args, FlagType.Retry)) {
this.emit(CommandHandlerEvents.COMMAND_BREAKOUT, message, command, args.message);
return this.handle(args.message);
} else if (Flag.is(args, "continue")) {
} else if (Flag.is(args, FlagType.Continue)) {
const continueCommand = this.modules.get(args.command)!;
return this.handleDirectCommand(message, args.rest, continueCommand, args.ignore);
return this.handleDirectCommand(message, args.rest!, continueCommand, args.ignore);
}

@@ -1010,0 +1004,0 @@

@@ -166,5 +166,5 @@ /* eslint-disable require-await */

) {
return this.lastResponse!.edit(newOptions);
return this.lastResponse!.edit(newOptions as MessageEditOptions);
}
const sent = await this.message.channel?.send(newOptions);
const sent = await this.message.channel?.send(newOptions as MessageOptions);

@@ -200,3 +200,3 @@ const lastSent = this.setLastResponse(sent!);

if (!this.isSlashMessage(this.message)) {
const sent = await this.message.channel?.send(options);
const sent = await this.message.channel?.send(options as string | MessagePayload | MessageOptions);
const lastSent = this.setLastResponse(sent!);

@@ -206,3 +206,5 @@ this.setEditable(!lastSent.attachments.size);

} else {
const sent = (await this.message.interaction.followUp(options)) as Message;
const sent = (await this.message.interaction.followUp(
options as string | MessagePayload | InteractionReplyOptions
)) as Message;
this.setLastResponse(sent);

@@ -209,0 +211,0 @@ return sent;

@@ -6,13 +6,52 @@ import type { Message } from "discord.js";

*/
export default class Flag {
export default class Flag<T extends FlagType = FlagType> {
/**
* The type of flag.
*/
public declare type: string;
public declare type: T;
/**
* Message to handle.
*
* Only exists if {@link type} is {@link FlagType.Retry}.
*/
public declare message: T extends FlagType.Retry ? Message : unknown;
/**
* The extra data for the failure.
*
* Only exists if {@link type} is {@link FlagType.Fail}.
*/
public declare value: T extends FlagType.Fail ? any : unknown;
/**
* Command ID.
*
* Only exists if {@link type} is {@link FlagType.Continue}.
*/
public declare command: T extends FlagType.Continue ? string : never;
/**
* Whether or not to ignore permission checks.
*
* Only exists if {@link type} is {@link FlagType.Continue}.
*/
public declare ignore: T extends FlagType.Continue ? boolean : never;
/**
* The rest of the arguments. If this is not set, the argument handler will automatically use the rest of the content.
*
* Only exists if {@link type} is {@link FlagType.Continue}.
*/
public declare rest: T extends FlagType.Continue ? string | null : never;
/**
* @param type - Type of flag.
* @param data - Extra data.
*/
constructor(type: string, data: any = {}) {
private constructor(type: T & FlagType.Cancel);
private constructor(type: T & FlagType.Retry, data?: FlagRetryData);
private constructor(type: T & FlagType.Fail, data?: FlagFailData);
private constructor(type: T & FlagType.Continue, data?: FlagContinueData);
private constructor(type: T, data: Record<string, never> | FlagRetryData | FlagFailData | FlagContinueData = {}) {
this.type = type;

@@ -25,4 +64,4 @@ Object.assign(this, data);

*/
public static cancel(): Flag {
return new Flag("cancel");
public static cancel(): Flag<FlagType.Cancel> {
return new Flag(FlagType.Cancel);
}

@@ -34,4 +73,4 @@

*/
public static retry(message: Message): Flag {
return new Flag("retry", { message });
public static retry(message: Message): Flag<FlagType.Retry> {
return new Flag(FlagType.Retry, { message });
}

@@ -43,4 +82,4 @@

*/
public static fail(value: any): Flag {
return new Flag("fail", { value });
public static fail(value: any): Flag<FlagType.Fail> {
return new Flag(FlagType.Fail, { value });
}

@@ -54,4 +93,4 @@

*/
public static continue(command: string, ignore: boolean = false, rest: string | null = null): Flag {
return new Flag("continue", { command, ignore, rest });
public static continue(command: string, ignore: boolean = false, rest: string | null = null): Flag<FlagType.Continue> {
return new Flag(FlagType.Continue, { command, ignore, rest });
}

@@ -64,5 +103,30 @@

*/
public static is(value: any, type: string): boolean {
public static is(value: unknown, type: FlagType.Cancel): value is Flag<FlagType.Cancel>;
public static is(value: unknown, type: FlagType.Continue): value is Flag<FlagType.Continue>;
public static is(value: unknown, type: FlagType.Fail): value is Flag<FlagType.Fail>;
public static is(value: unknown, type: FlagType.Retry): value is Flag<FlagType.Retry>;
public static is(value: unknown, type: FlagType): value is Flag<typeof type> {
return value instanceof Flag && value.type === type;
}
}
export enum FlagType {
Cancel = "cancel",
Retry = "retry",
Fail = "fail",
Continue = "continue"
}
interface FlagRetryData {
message: Message;
}
interface FlagFailData {
value: any;
}
interface FlagContinueData {
command: string;
ignore: boolean;
rest: string | null;
}

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc