@sapphire/framework
Advanced tools
Comparing version 1.0.0-alpha.6 to 1.0.0-alpha.7
@@ -5,2 +5,60 @@ # Changelog | ||
## [1.0.0-alpha.7](https://github.com/sapphire-project/framework/compare/v1.0.0-alpha.6...v1.0.0-alpha.7) (2021-02-06) | ||
### β BREAKING CHANGES | ||
- **errors:** Changed UserError identifier from `'ArgumentBooleanInvalidBoolean'` to `Identifiers.ArgumentBoolean`. | ||
- **errors:** Changed UserError identifier from `'ArgumentCategoryChannelInvalidChannel'` to `Identifiers.ArgumentCategoryChannel`. | ||
- **errors:** Changed UserError identifier from `'ArgumentChannelMissingChannel'` to `Identifiers.ArgumentChannel`. | ||
- **errors:** Changed UserError identifier from `'ArgumentDateInvalidNumber'` to `Identifiers.ArgumentDate`. | ||
- **errors:** Changed UserError identifier from `'ArgumentDateTooSmall'` to `Identifiers.ArgumentDateTooSmall`. | ||
- **errors:** Changed UserError identifier from `'ArgumentDateTooBig'` to `Identifiers.ArgumentDateTooBig`. | ||
- **errors:** Changed UserError identifier from `'ArgumentDMChannelInvalidChannel'` to `Identifiers.ArgumentDMChannel`. | ||
- **errors:** Changed UserError identifier from `'ArgumentFloatInvalidFloat'` to `Identifiers.ArgumentFloat`. | ||
- **errors:** Changed UserError identifier from `'ArgumentFloatTooSmall'` to `Identifiers.ArgumentFloatTooSmall`. | ||
- **errors:** Changed UserError identifier from `'ArgumentFloatTooBig'` to `Identifiers.ArgumentFloatTooBig`. | ||
- **errors:** Changed UserError identifier from `'ArgumentGuildChannelMissingGuild'` to `Identifiers.ArgumentGuildChannelMissingGuild`. | ||
- **errors:** Changed UserError identifier from `'ArgumentGuildChannelUnknownChannel'` to `Identifiers.ArgumentGuildChannel`. | ||
- **errors:** Changed UserError identifier from `'ArgumentHyperlinkInvalidURL'` to `Identifiers.ArgumentHyperlink`. | ||
- **errors:** Changed UserError identifier from `'ArgumentIntegerInvalidNumber'` to `Identifiers.ArgumentInteger`. | ||
- **errors:** Changed UserError identifier from `'ArgumentIntegerTooSmall'` to `Identifiers.ArgumentIntegerTooSmall`. | ||
- **errors:** Changed UserError identifier from `'ArgumentIntegerTooBig'` to `Identifiers.ArgumentIntegerTooBig`. | ||
- **errors:** Changed UserError identifier from `'ArgumentMemberMissingGuild'` to `Identifiers.ArgumentMemberMissingGuild`. | ||
- **errors:** Changed UserError identifier from `'ArgumentMemberUnknownMember'` to `Identifiers.ArgumentMember`. | ||
- **errors:** Changed UserError identifier from `'ArgumentMessageUnknownMessage'` to `Identifiers.Message`. | ||
- **errors:** Changed UserError identifier from `'ArgumentNewsChannelInvalidChannel'` to `Identifiers.NewsChannel`. | ||
- **errors:** Changed UserError identifier from `'ArgumentNumberInvalidNumber'` to `Identifiers.Number`. | ||
- **errors:** Changed UserError identifier from `'ArgumentNumberTooSmall'` to `Identifiers.ArgumentNumberTooSmall`. | ||
- **errors:** Changed UserError identifier from `'ArgumentNumberTooBig'` to `Identifiers.ArgumentNumberTooBig`. | ||
- **errors:** Changed UserError identifier from `'ArgumentRoleMissingGuild'` to `Identifiers.ArgumentRoleMissingGuild`. | ||
- **errors:** Changed UserError identifier from `'ArgumentRoleUnknownRole'` to `Identifiers.Role`. | ||
- **errors:** Changed UserError identifier from `'ArgumentStringTooShort'` to `Identifiers.ArgumentStringTooShort`. | ||
- **errors:** Changed UserError identifier from `'ArgumentStringTooLong'` to `Identifiers.ArgumentStringTooLong`. | ||
- **errors:** Changed UserError identifier from `'ArgumentTextChannelInvalidChannel'` to `Identifiers.TextChannel`. | ||
- **errors:** Changed UserError identifier from `'ArgumentUserUnknownUser'` to `Identifiers.User`. | ||
- **errors:** Changed UserError identifier from `'ArgumentVoiceChannelInvalidChannel'` to `Identifiers.VoiceChannel`. | ||
- **errors:** Changed UserError identifier from `'CommandDisabled'` to `Identifiers.CommandDisabled`. | ||
- **errors:** Changed UserError identifier from `'UnavailableArgument'` to `Identifiers.ArgsUnavailable`. | ||
- **errors:** Changed UserError identifier from `'MissingArguments'` to `Identifiers.ArgsMissing`. | ||
- **errors:** Changed UserError identifier from `'Cooldown'` to `Identifiers.PreconditionCooldown`. | ||
- **errors:** Changed UserError identifier from `'DMOnly'` to `Identifiers.PreconditionDMOnly`. | ||
- **errors:** Changed UserError identifier from `'GuildOnly'` to `Identifiers.PreconditionGuildOnly`. | ||
- **errors:** Changed UserError identifier from `'NSFW'` to `Identifiers.PreconditionNSFW`. | ||
- **errors:** Changed UserError identifier from `'Permissions'` to `Identifiers.PreconditionPermissions`. | ||
- **preconditions:** Added `PreconditionContext` as third parameter to `IPreconditionContainer#run`. | ||
- **preconditions:** Changed `PermissionsPrecondition#context` from `PreconditionContext` to `Record<PropertyKey, unknown>`. | ||
- **preconditions:** Changed `PreconditionContainerSingle#context` from `PreconditionContext` to `Record<PropertyKey, unknown>`. | ||
- **preconditions:** Changed `PreconditionSingleResolvableDetails#context` from `PreconditionContext` to `Record<PropertyKey, unknown>`. | ||
- **preconditions:** Added `PreconditionContext` as third parameter to `IPreconditionCondition#run`. | ||
- **args:** changed `Args.err` to return `Err<ArgumentError<T>>` instead of `ArgumentError<T>` | ||
### Features | ||
- **args:** add Args#ok, refactored Args#error to return Err<ArgumentError<T>> ([#159](https://github.com/sapphire-project/framework/issues/159)) ([65316a6](https://github.com/sapphire-project/framework/commit/65316a6f13533b90b0ba84ff214ebf8bb54cc5ee)) | ||
- **args:** change visibility of parser from private to protected ([#160](https://github.com/sapphire-project/framework/issues/160)) ([3ad6f85](https://github.com/sapphire-project/framework/commit/3ad6f85db92287c0c073dcbc21df13d52c629abb)) | ||
- **command:** add CommandContext#commandPrefix ([#157](https://github.com/sapphire-project/framework/issues/157)) ([c8c7417](https://github.com/sapphire-project/framework/commit/c8c741768e78a5f3c75282cc8461368bd9609016)) | ||
- **command-events:** pass more context ([#162](https://github.com/sapphire-project/framework/issues/162)) ([11a6274](https://github.com/sapphire-project/framework/commit/11a6274613536fcc7fa2bcbb936b6332740978a4)) | ||
- **errors:** expose all identifiers in an enum ([#161](https://github.com/sapphire-project/framework/issues/161)) ([3371f35](https://github.com/sapphire-project/framework/commit/3371f35c2ad9fabdacca5b1ae614e5a5c9530dbc)) | ||
- **preconditions:** add context to Container and Condition ([#158](https://github.com/sapphire-project/framework/issues/158)) ([de6bc03](https://github.com/sapphire-project/framework/commit/de6bc035f737ddc269a1b7e44ad34c175cfa35dd)) | ||
## [1.0.0-alpha.6](https://github.com/sapphire-project/framework/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2021-02-04) | ||
@@ -7,0 +65,0 @@ |
@@ -17,3 +17,3 @@ "use strict"; | ||
return this.ok(false); | ||
return this.error({ parameter, identifier: 'ArgumentBooleanInvalidBoolean', message: 'The argument did not resolve to a boolean.', context }); | ||
return this.error({ parameter, message: 'The argument did not resolve to a boolean.', context }); | ||
} | ||
@@ -20,0 +20,0 @@ } |
@@ -16,8 +16,3 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ | ||
parameter: context.parameter, | ||
identifier: 'ArgumentCategoryChannelInvalidChannel', | ||
message: 'The argument did not resolve to a category channel.', | ||
context | ||
}); | ||
: this.error({ parameter: context.parameter, message: 'The argument did not resolve to a category channel.', context }); | ||
} | ||
@@ -24,0 +19,0 @@ } |
@@ -11,11 +11,3 @@ "use strict"; | ||
const channel = (context.message.guild ? context.message.guild.channels : this.context.client.channels).cache.get(parameter); | ||
if (!channel) { | ||
return this.error({ | ||
parameter, | ||
identifier: 'ArgumentChannelMissingChannel', | ||
message: 'The argument did not resolve to a channel.', | ||
context | ||
}); | ||
} | ||
return this.ok(channel); | ||
return channel ? this.ok(channel) : this.error({ parameter, message: 'The argument did not resolve to a channel.', context }); | ||
} | ||
@@ -22,0 +14,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreArgument = void 0; | ||
require("../lib/errors/Identifiers"); | ||
const Argument_1 = require("../lib/structures/Argument"); | ||
@@ -15,3 +16,2 @@ class CoreArgument extends Argument_1.Argument { | ||
parameter, | ||
identifier: 'ArgumentDateInvalidNumber', | ||
message: 'The argument did not resolve to a valid date.', | ||
@@ -22,6 +22,6 @@ context | ||
if (typeof context.minimum === 'number' && time < context.minimum) { | ||
return this.error({ parameter, identifier: 'ArgumentDateTooSmall', message: 'The argument is too small.', context }); | ||
return this.error({ parameter, identifier: "dateTooSmall" /* ArgumentDateTooSmall */, message: 'The argument is too small.', context }); | ||
} | ||
if (typeof context.maximum === 'number' && time > context.maximum) { | ||
return this.error({ parameter, identifier: 'ArgumentDateTooBig', message: 'The argument is too big.', context }); | ||
return this.error({ parameter, identifier: "dateTooBig" /* ArgumentDateTooBig */, message: 'The argument is too big.', context }); | ||
} | ||
@@ -28,0 +28,0 @@ return this.ok(parsed); |
@@ -13,8 +13,3 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ | ||
parameter: context.parameter, | ||
identifier: 'ArgumentDMChannelInvalidChannel', | ||
message: 'The argument did not resolve to a DM channel.', | ||
context | ||
}); | ||
: this.error({ parameter: context.parameter, message: 'The argument did not resolve to a DM channel.', context }); | ||
} | ||
@@ -21,0 +16,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreArgument = void 0; | ||
require("../lib/errors/Identifiers"); | ||
const Argument_1 = require("../lib/structures/Argument"); | ||
@@ -12,8 +13,3 @@ class CoreArgument extends Argument_1.Argument { | ||
if (Number.isNaN(parsed)) { | ||
return this.error({ | ||
parameter, | ||
identifier: 'ArgumentFloatInvalidFloat', | ||
message: 'The argument did not resolve to a valid floating point number.', | ||
context | ||
}); | ||
return this.error({ parameter, message: 'The argument did not resolve to a valid floating point number.', context }); | ||
} | ||
@@ -23,3 +19,3 @@ if (typeof context.minimum === 'number' && parsed < context.minimum) { | ||
parameter, | ||
identifier: 'ArgumentFloatTooSmall', | ||
identifier: "floatTooSmall" /* ArgumentFloatTooSmall */, | ||
message: `The argument must be greater than ${context.minimum}.`, | ||
@@ -32,3 +28,3 @@ context | ||
parameter, | ||
identifier: 'ArgumentFloatTooBig', | ||
identifier: "floatTooBig" /* ArgumentFloatTooBig */, | ||
message: `The argument must be less than ${context.maximum}.`, | ||
@@ -35,0 +31,0 @@ context |
@@ -5,2 +5,3 @@ "use strict"; | ||
const discord_utilities_1 = require("@sapphire/discord-utilities"); | ||
require("../lib/errors/Identifiers"); | ||
const Argument_1 = require("../lib/structures/Argument"); | ||
@@ -17,3 +18,3 @@ class CoreArgument extends Argument_1.Argument { | ||
parameter, | ||
identifier: 'ArgumentGuildChannelMissingGuild', | ||
identifier: "guildChannelMissingGuild" /* ArgumentGuildChannelMissingGuild */, | ||
message: 'The argument must be run in a guild.', | ||
@@ -24,10 +25,3 @@ context | ||
const channel = (_a = this.resolveByID(parameter, guild)) !== null && _a !== void 0 ? _a : this.resolveByQuery(parameter, guild); | ||
return channel | ||
? this.ok(channel) | ||
: this.error({ | ||
parameter, | ||
identifier: 'ArgumentGuildChannelUnknownChannel', | ||
message: 'The argument did not resolve to a guild channel.', | ||
context | ||
}); | ||
return channel ? this.ok(channel) : this.error({ parameter, message: 'The argument did not resolve to a guild channel.', context }); | ||
} | ||
@@ -34,0 +28,0 @@ resolveByID(argument, guild) { |
@@ -15,8 +15,3 @@ "use strict"; | ||
catch { | ||
return this.error({ | ||
parameter, | ||
identifier: 'ArgumentHyperlinkInvalidURL', | ||
message: 'The argument did not resolve to a valid URL.', | ||
context | ||
}); | ||
return this.error({ parameter, message: 'The argument did not resolve to a valid URL.', context }); | ||
} | ||
@@ -23,0 +18,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreArgument = void 0; | ||
require("../lib/errors/Identifiers"); | ||
const Argument_1 = require("../lib/structures/Argument"); | ||
@@ -14,3 +15,2 @@ class CoreArgument extends Argument_1.Argument { | ||
parameter, | ||
identifier: 'ArgumentIntegerInvalidNumber', | ||
message: 'The argument did not resolve to an integer.', | ||
@@ -23,3 +23,3 @@ context | ||
parameter, | ||
identifier: 'ArgumentIntegerTooSmall', | ||
identifier: "integerTooSmall" /* ArgumentIntegerTooSmall */, | ||
message: `The argument must be greater than ${context.minimum}.`, | ||
@@ -32,3 +32,3 @@ context | ||
parameter, | ||
identifier: 'ArgumentIntegerTooBig', | ||
identifier: "integerTooBig" /* ArgumentIntegerTooBig */, | ||
message: `The argument must be less than ${context.maximum}.`, | ||
@@ -35,0 +35,0 @@ context |
@@ -5,2 +5,3 @@ "use strict"; | ||
const discord_utilities_1 = require("@sapphire/discord-utilities"); | ||
require("../lib/errors/Identifiers"); | ||
const Argument_1 = require("../lib/structures/Argument"); | ||
@@ -15,8 +16,11 @@ class CoreArgument extends Argument_1.Argument { | ||
if (!guild) { | ||
return this.error({ parameter, identifier: 'ArgumentMemberMissingGuild', message: 'The argument must be run on a guild.', context }); | ||
return this.error({ | ||
parameter, | ||
identifier: "memberMissingGuild" /* ArgumentMemberMissingGuild */, | ||
message: 'The argument must be run on a guild.', | ||
context | ||
}); | ||
} | ||
const member = (_a = (await this.resolveByID(parameter, guild))) !== null && _a !== void 0 ? _a : (await this.resolveByQuery(parameter, guild)); | ||
return member | ||
? this.ok(member) | ||
: this.error({ parameter, identifier: 'ArgumentMemberUnknownMember', message: 'The argument did not resolve to a member.', context }); | ||
return member ? this.ok(member) : this.error({ parameter, message: 'The argument did not resolve to a member.', context }); | ||
} | ||
@@ -23,0 +27,0 @@ async resolveByID(argument, guild) { |
@@ -14,5 +14,3 @@ "use strict"; | ||
const message = (_a = (await this.resolveByID(parameter, context))) !== null && _a !== void 0 ? _a : (await this.resolveByLink(parameter, context)); | ||
return message | ||
? this.ok(message) | ||
: this.error({ parameter, identifier: 'ArgumentMessageUnknownMessage', message: 'The argument did not resolve to a message.', context }); | ||
return message ? this.ok(message) : this.error({ parameter, message: 'The argument did not resolve to a message.', context }); | ||
} | ||
@@ -19,0 +17,0 @@ async resolveByID(argument, context) { |
@@ -16,8 +16,3 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ | ||
parameter: context.parameter, | ||
identifier: 'ArgumentNewsChannelInvalidChannel', | ||
message: 'The argument did not resolve to a news channel.', | ||
context | ||
}); | ||
: this.error({ parameter: context.parameter, message: 'The argument did not resolve to a news channel.', context }); | ||
} | ||
@@ -24,0 +19,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreArgument = void 0; | ||
require("../lib/errors/Identifiers"); | ||
const Argument_1 = require("../lib/structures/Argument"); | ||
@@ -14,3 +15,2 @@ class CoreArgument extends Argument_1.Argument { | ||
parameter, | ||
identifier: 'ArgumentNumberInvalidNumber', | ||
message: 'The argument did not resolve to a valid number.', | ||
@@ -23,3 +23,3 @@ context | ||
parameter, | ||
identifier: 'ArgumentNumberTooSmall', | ||
identifier: "numberTooSmall" /* ArgumentNumberTooSmall */, | ||
message: `The argument must be greater than ${context.minimum}.`, | ||
@@ -32,3 +32,3 @@ context | ||
parameter, | ||
identifier: 'ArgumentNumberTooBig', | ||
identifier: "numberTooBig" /* ArgumentNumberTooBig */, | ||
message: `The argument must be smaller than ${context.maximum}.`, | ||
@@ -35,0 +35,0 @@ context |
@@ -5,2 +5,3 @@ "use strict"; | ||
const discord_utilities_1 = require("@sapphire/discord-utilities"); | ||
require("../lib/errors/Identifiers"); | ||
const Argument_1 = require("../lib/structures/Argument"); | ||
@@ -15,8 +16,11 @@ class CoreArgument extends Argument_1.Argument { | ||
if (!guild) { | ||
return this.error({ parameter, identifier: 'ArgumentRoleMissingGuild', message: 'The argument must be run on a guild.', context }); | ||
return this.error({ | ||
parameter, | ||
identifier: "roleMissingGuild" /* ArgumentRoleMissingGuild */, | ||
message: 'The argument must be run on a guild.', | ||
context | ||
}); | ||
} | ||
const role = (_a = (await this.resolveByID(parameter, guild))) !== null && _a !== void 0 ? _a : this.resolveByQuery(parameter, guild); | ||
return role | ||
? this.ok(role) | ||
: this.error({ parameter, identifier: 'ArgumentRoleUnknownRole', message: 'The argument did not resolve to a role.', context }); | ||
return role ? this.ok(role) : this.error({ parameter, message: 'The argument did not resolve to a role.', context }); | ||
} | ||
@@ -23,0 +27,0 @@ async resolveByID(argument, guild) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreArgument = void 0; | ||
require("../lib/errors/Identifiers"); | ||
const Argument_1 = require("../lib/structures/Argument"); | ||
@@ -13,4 +14,4 @@ class CoreArgument extends Argument_1.Argument { | ||
parameter, | ||
identifier: 'ArgumentStringTooShort', | ||
message: `The argument must be greater than ${context.minimum} characters.`, | ||
identifier: "stringTooShort" /* ArgumentStringTooShort */, | ||
message: `The argument must be longer than ${context.minimum} characters.`, | ||
context | ||
@@ -22,4 +23,4 @@ }); | ||
parameter, | ||
identifier: 'ArgumentStringTooLong', | ||
message: `The argument must be less than ${context.maximum} characters.`, | ||
identifier: "stringTooLong" /* ArgumentStringTooLong */, | ||
message: `The argument must be shorter than ${context.maximum} characters.`, | ||
context | ||
@@ -26,0 +27,0 @@ }); |
@@ -16,8 +16,3 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ | ||
parameter: context.parameter, | ||
identifier: 'ArgumentTextChannelInvalidChannel', | ||
message: 'The argument did not resolve to a text channel.', | ||
context | ||
}); | ||
: this.error({ parameter: context.parameter, message: 'The argument did not resolve to a text channel.', context }); | ||
} | ||
@@ -24,0 +19,0 @@ } |
@@ -14,5 +14,3 @@ "use strict"; | ||
const user = userID ? await this.context.client.users.fetch(userID[1]).catch(() => null) : null; | ||
return user | ||
? this.ok(user) | ||
: this.error({ parameter, identifier: 'ArgumentUserUnknownUser', message: 'The argument did not resolve to a user.', context }); | ||
return user ? this.ok(user) : this.error({ parameter, message: 'The argument did not resolve to a user.', context }); | ||
} | ||
@@ -19,0 +17,0 @@ } |
@@ -16,8 +16,3 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ | ||
parameter: context.parameter, | ||
identifier: 'ArgumentVoiceChannelInvalidChannel', | ||
message: 'The argument did not resolve to a voice channel.', | ||
context | ||
}); | ||
: this.error({ parameter: context.parameter, message: 'The argument did not resolve to a voice channel.', context }); | ||
} | ||
@@ -24,0 +19,0 @@ } |
@@ -10,14 +10,15 @@ "use strict"; | ||
} | ||
async run({ message, command, parameters, context }) { | ||
async run(payload) { | ||
const { message, command, parameters, context } = payload; | ||
const args = await command.preParse(message, parameters, context); | ||
try { | ||
message.client.emit(Events_1.Events.CommandRun, message, command); | ||
message.client.emit(Events_1.Events.CommandRun, message, command, payload); | ||
const result = await command.run(message, args, context); | ||
message.client.emit(Events_1.Events.CommandSuccess, { message, command, result, parameters }); | ||
message.client.emit(Events_1.Events.CommandSuccess, { ...payload, result }); | ||
} | ||
catch (error) { | ||
message.client.emit(Events_1.Events.CommandError, error, { piece: command, message }); | ||
message.client.emit(Events_1.Events.CommandError, error, { ...payload, piece: command }); | ||
} | ||
finally { | ||
message.client.emit(Events_1.Events.CommandFinish, message, command); | ||
message.client.emit(Events_1.Events.CommandFinish, message, command, payload); | ||
} | ||
@@ -24,0 +25,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreEvent = void 0; | ||
require("../../lib/errors/Identifiers"); | ||
const UserError_1 = require("../../lib/errors/UserError"); | ||
@@ -13,13 +14,8 @@ const Result_1 = require("../../lib/parsers/Result"); | ||
async run(payload) { | ||
const { message, command, parameters, context } = payload; | ||
const { message, command } = payload; | ||
if (!command.enabled) { | ||
message.client.emit(Events_1.Events.CommandDenied, new UserError_1.UserError({ identifier: 'CommandDisabled', message: 'This command is disabled.', context: payload }), { | ||
message, | ||
command, | ||
parameters, | ||
context | ||
}); | ||
message.client.emit(Events_1.Events.CommandDenied, new UserError_1.UserError({ identifier: "commandDisabled" /* CommandDisabled */, message: 'This command is disabled.', context: payload }), payload); | ||
return; | ||
} | ||
const result = await command.preconditions.run(message, command); | ||
const result = await command.preconditions.run(message, command, { command }); | ||
if (Result_1.isErr(result)) { | ||
@@ -26,0 +22,0 @@ message.client.emit(Events_1.Events.CommandDenied, result.error, payload); |
@@ -11,10 +11,11 @@ "use strict"; | ||
run(message, prefix) { | ||
var _a, _b; | ||
const { client, stores } = this.context; | ||
// Retrieve the command name and validate: | ||
const trimLength = typeof prefix === 'string' ? prefix.length : (_b = (_a = prefix.exec(message.content)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0; | ||
const prefixLess = message.content.slice(trimLength).trim(); | ||
const commandPrefix = this.getCommandPrefix(message.content, prefix); | ||
const prefixLess = message.content.slice(commandPrefix.length).trim(); | ||
// The character that separates the command name from the arguments, this will return -1 when '[p]command' is | ||
// passed, and a non -1 value when '[p]command arg' is passed instead. | ||
const spaceIndex = prefixLess.indexOf(' '); | ||
const name = spaceIndex === -1 ? prefixLess : prefixLess.slice(0, spaceIndex); | ||
if (!name) { | ||
const commandName = spaceIndex === -1 ? prefixLess : prefixLess.slice(0, spaceIndex); | ||
if (!commandName) { | ||
client.emit(Events_1.Events.UnknownCommandName, message, prefix); | ||
@@ -24,5 +25,5 @@ return; | ||
// Retrieve the command and validate: | ||
const command = stores.get('commands').get(client.options.caseInsensitiveCommands ? name.toLowerCase() : name); | ||
const command = stores.get('commands').get(client.options.caseInsensitiveCommands ? commandName.toLowerCase() : commandName); | ||
if (!command) { | ||
client.emit(Events_1.Events.UnknownCommand, message, name, prefix); | ||
client.emit(Events_1.Events.UnknownCommand, message, commandName, prefix); | ||
return; | ||
@@ -32,6 +33,9 @@ } | ||
const parameters = spaceIndex === -1 ? '' : prefixLess.substr(spaceIndex + 1).trim(); | ||
client.emit(Events_1.Events.PreCommandRun, { message, command, parameters, context: { commandName: name, prefix } }); | ||
client.emit(Events_1.Events.PreCommandRun, { message, command, parameters, context: { commandName, commandPrefix, prefix } }); | ||
} | ||
getCommandPrefix(content, prefix) { | ||
return typeof prefix === 'string' ? prefix : prefix.exec(content)[0]; | ||
} | ||
} | ||
exports.CoreEvent = CoreEvent; | ||
//# sourceMappingURL=CorePrefixedMessage.js.map |
@@ -22,2 +22,3 @@ "use strict"; | ||
__exportStar(require("./lib/errors/ArgumentError"), exports); | ||
__exportStar(require("./lib/errors/Identifiers"), exports); | ||
__exportStar(require("./lib/errors/PreconditionError"), exports); | ||
@@ -24,0 +25,0 @@ __exportStar(require("./lib/errors/UserError"), exports); |
@@ -6,2 +6,3 @@ "use strict"; | ||
const ArgumentError_1 = require("../errors/ArgumentError"); | ||
require("../errors/Identifiers"); | ||
const UserError_1 = require("../errors/UserError"); | ||
@@ -15,2 +16,7 @@ const Maybe_1 = require("./Maybe"); | ||
constructor(message, command, parser, context) { | ||
/** | ||
* The states stored in the args. | ||
* @see Args#save | ||
* @see Args#restore | ||
*/ | ||
this.states = []; | ||
@@ -196,3 +202,3 @@ this.message = message; | ||
* Saves the current state into the stack following a FILO strategy (first-in, last-out). | ||
* @seealso [[Args.restore]] | ||
* @see Args#restore | ||
*/ | ||
@@ -204,3 +210,3 @@ save() { | ||
* Restores the previously saved state from the stack. | ||
* @seealso [[Args.save]] | ||
* @see Args#save | ||
*/ | ||
@@ -219,3 +225,3 @@ restore() { | ||
return Result_1.err(new UserError_1.UserError({ | ||
identifier: 'UnavailableArgument', | ||
identifier: "argsUnavailable" /* ArgsUnavailable */, | ||
message: `The argument "${typeof type === 'string' ? type : type.name}" was not found.` | ||
@@ -225,3 +231,3 @@ })); | ||
missingArguments() { | ||
return Result_1.err(new UserError_1.UserError({ identifier: 'MissingArguments', message: 'There are no more arguments.' })); | ||
return Result_1.err(new UserError_1.UserError({ identifier: "argsMissing" /* ArgsMissing */, message: 'There are no more arguments.' })); | ||
} | ||
@@ -245,10 +251,14 @@ /** | ||
/** | ||
* Constructs an [[ArgumentError]] with a custom type. | ||
* @param argument The argument that caused the rejection. | ||
* @param parameter The parameter that triggered the argument. | ||
* @param type The identifier for the error. | ||
* @param message The description message for the rejection. | ||
* Constructs an [[Ok]] result. | ||
* @param value The value to pass. | ||
*/ | ||
static ok(value) { | ||
return Result_1.ok(value); | ||
} | ||
/** | ||
* Constructs an [[Err]] result containing an [[ArgumentError]]. | ||
* @param options The options for the argument error. | ||
*/ | ||
static error(options) { | ||
return new ArgumentError_1.ArgumentError(options); | ||
return Result_1.err(new ArgumentError_1.ArgumentError(options)); | ||
} | ||
@@ -255,0 +265,0 @@ } |
@@ -6,3 +6,2 @@ "use strict"; | ||
const Args_1 = require("../parsers/Args"); | ||
const Result_1 = require("../parsers/Result"); | ||
/** | ||
@@ -70,3 +69,3 @@ * The base argument class. This class is abstract and is to be extended by subclasses implementing the methods. In | ||
ok(value) { | ||
return Result_1.ok(value); | ||
return Args_1.Args.ok(value); | ||
} | ||
@@ -80,3 +79,3 @@ /** | ||
error(options) { | ||
return Result_1.err(Args_1.Args.error({ argument: this, ...options })); | ||
return Args_1.Args.error({ argument: this, identifier: this.name, ...options }); | ||
} | ||
@@ -83,0 +82,0 @@ } |
@@ -10,5 +10,5 @@ "use strict"; | ||
exports.PreconditionConditionAnd = { | ||
async sequential(message, command, entries) { | ||
async sequential(message, command, entries, context) { | ||
for (const child of entries) { | ||
const result = await child.run(message, command); | ||
const result = await child.run(message, command, context); | ||
if (Result_1.isErr(result)) | ||
@@ -19,5 +19,5 @@ return result; | ||
}, | ||
async parallel(message, command, entries) { | ||
async parallel(message, command, entries, context) { | ||
var _a; | ||
const results = await Promise.all(entries.map((entry) => entry.run(message, command))); | ||
const results = await Promise.all(entries.map((entry) => entry.run(message, command, context))); | ||
// This is simplified compared to PreconditionContainerAny because we're looking for the first error. | ||
@@ -24,0 +24,0 @@ // However, the base implementation short-circuits with the first Ok. |
@@ -10,6 +10,6 @@ "use strict"; | ||
exports.PreconditionConditionOr = { | ||
async sequential(message, command, entries) { | ||
async sequential(message, command, entries, context) { | ||
let error = null; | ||
for (const child of entries) { | ||
const result = await child.run(message, command); | ||
const result = await child.run(message, command, context); | ||
if (Result_1.isOk(result)) | ||
@@ -21,4 +21,4 @@ return result; | ||
}, | ||
async parallel(message, command, entries) { | ||
const results = await Promise.all(entries.map((entry) => entry.run(message, command))); | ||
async parallel(message, command, entries, context) { | ||
const results = await Promise.all(entries.map((entry) => entry.run(message, command, context))); | ||
let error = null; | ||
@@ -25,0 +25,0 @@ for (const result of results) { |
@@ -96,6 +96,6 @@ "use strict"; | ||
*/ | ||
run(message, command) { | ||
run(message, command, context) { | ||
return this.mode === 0 /* Sequential */ | ||
? this.condition.sequential(message, command, this.entries) | ||
: this.condition.parallel(message, command, this.entries); | ||
? this.condition.sequential(message, command, this.entries, context) | ||
: this.condition.parallel(message, command, this.entries, context); | ||
} | ||
@@ -102,0 +102,0 @@ /** |
@@ -26,6 +26,6 @@ "use strict"; | ||
*/ | ||
run(message, command) { | ||
run(message, command, context) { | ||
const precondition = pieces_1.Store.injectedContext.stores.get('preconditions').get(this.name); | ||
if (precondition) | ||
return precondition.run(message, command, this.context); | ||
return precondition.run(message, command, { ...context, ...this.context }); | ||
throw new Error(`The precondition "${this.name}" is not available.`); | ||
@@ -32,0 +32,0 @@ } |
@@ -5,2 +5,3 @@ "use strict"; | ||
const ratelimits_1 = require("@sapphire/ratelimits"); | ||
require("../lib/errors/Identifiers"); | ||
const Precondition_1 = require("../lib/structures/Precondition"); | ||
@@ -14,4 +15,8 @@ require("../lib/types/Enums"); | ||
run(message, command, context) { | ||
if (!context.delay || context.delay === 0) | ||
// If the command it is testing for is not this one, return ok: | ||
if (context.command !== command) | ||
return this.ok(); | ||
// If there is no delay (undefined, null, 0), return ok: | ||
if (!context.delay) | ||
return this.ok(); | ||
const bucket = this.getBucket(command, context); | ||
@@ -22,2 +27,3 @@ const remaining = bucket.take(this.getID(message, context)); | ||
: this.error({ | ||
identifier: "preconditionCooldown" /* PreconditionCooldown */, | ||
message: `You have just used this command. Try again in ${Math.ceil(remaining / 1000)} second${remaining > 1000 ? 's' : ''}.`, | ||
@@ -24,0 +30,0 @@ context: { remaining } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CorePrecondition = void 0; | ||
require("../lib/errors/Identifiers"); | ||
const Precondition_1 = require("../lib/structures/Precondition"); | ||
class CorePrecondition extends Precondition_1.Precondition { | ||
run(message) { | ||
return message.guild === null ? this.ok() : this.error({ message: 'You cannot run this command outside DMs.' }); | ||
return message.guild === null | ||
? this.ok() | ||
: this.error({ identifier: "preconditionDmOnly" /* PreconditionDMOnly */, message: 'You cannot run this command outside DMs.' }); | ||
} | ||
@@ -9,0 +12,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CorePrecondition = void 0; | ||
require("../lib/errors/Identifiers"); | ||
const Precondition_1 = require("../lib/structures/Precondition"); | ||
class CorePrecondition extends Precondition_1.Precondition { | ||
run(message) { | ||
return message.guild === null ? this.error({ message: 'You cannot run this command in DMs.' }) : this.ok(); | ||
return message.guild === null | ||
? this.error({ identifier: "preconditionGuildOnly" /* PreconditionGuildOnly */, message: 'You cannot run this command in DMs.' }) | ||
: this.ok(); | ||
} | ||
@@ -9,0 +12,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CorePrecondition = void 0; | ||
require("../lib/errors/Identifiers"); | ||
const Precondition_1 = require("../lib/structures/Precondition"); | ||
@@ -11,3 +12,3 @@ class CorePrecondition extends Precondition_1.Precondition { | ||
? this.ok() | ||
: this.error({ message: 'You cannot run this command outside NSFW channels.' }); | ||
: this.error({ identifier: "preconditionNsfw" /* PreconditionNSFW */, message: 'You cannot run this command outside NSFW channels.' }); | ||
} | ||
@@ -14,0 +15,0 @@ } |
@@ -5,2 +5,3 @@ "use strict"; | ||
const discord_js_1 = require("discord.js"); | ||
require("../lib/errors/Identifiers"); | ||
const Precondition_1 = require("../lib/structures/Precondition"); | ||
@@ -32,2 +33,3 @@ class CorePrecondition extends Precondition_1.Precondition { | ||
: this.error({ | ||
identifier: "preconditionPermissions" /* PreconditionPermissions */, | ||
message: `I am missing the following permissions to run this command: ${missing | ||
@@ -34,0 +36,0 @@ .map((perm) => CorePrecondition.readablePermissions[perm]) |
{ | ||
"name": "@sapphire/framework", | ||
"version": "1.0.0-alpha.6", | ||
"version": "1.0.0-alpha.7", | ||
"description": "Discord bot framework built on top of @sapphire/lib for advanced and amazing bots.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -62,4 +62,4 @@ <div align="center"> | ||
<tr> | ||
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Antonio RomΓ‘n</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=kyranet" title="Code">π»</a> <a href="https://github.com/sapphire-project/framework/commits?author=kyranet" title="Documentation">π</a> <a href="#design-kyranet" title="Design">π¨</a> <a href="#ideas-kyranet" title="Ideas, Planning, & Feedback">π€</a> <a href="#infra-kyranet" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#projectManagement-kyranet" title="Project Management">π</a></td> | ||
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=Favna" title="Code">π»</a> <a href="https://github.com/sapphire-project/framework/commits?author=Favna" title="Documentation">π</a> <a href="#infra-Favna" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#projectManagement-Favna" title="Project Management">π</a></td> | ||
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Antonio RomΓ‘n</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=kyranet" title="Code">π»</a> <a href="https://github.com/sapphire-project/framework/commits?author=kyranet" title="Documentation">π</a> <a href="#design-kyranet" title="Design">π¨</a> <a href="#ideas-kyranet" title="Ideas, Planning, & Feedback">π€</a> <a href="#infra-kyranet" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#projectManagement-kyranet" title="Project Management">π</a> <a href="#plugin-kyranet" title="Plugin/utility libraries">π</a></td> | ||
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=Favna" title="Code">π»</a> <a href="https://github.com/sapphire-project/framework/commits?author=Favna" title="Documentation">π</a> <a href="#infra-Favna" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#projectManagement-Favna" title="Project Management">π</a> <a href="#plugin-Favna" title="Plugin/utility libraries">π</a></td> | ||
<td align="center"><a href="https://github.com/cfanoulis"><img src="https://avatars3.githubusercontent.com/u/38255093?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Charalampos Fanoulis</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=cfanoulis" title="Code">π»</a></td> | ||
@@ -74,7 +74,7 @@ <td align="center"><a href="http://www.adityatd.me"><img src="https://avatars0.githubusercontent.com/u/9266227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aditya N. Tripathi</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=AdityaTD" title="Code">π»</a> <a href="https://github.com/sapphire-project/framework/commits?author=AdityaTD" title="Documentation">π</a></td> | ||
<td align="center"><a href="https://atm.moe/"><img src="https://avatars3.githubusercontent.com/u/31011461?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kovacs Alex</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=alexthemaster" title="Code">π»</a></td> | ||
<td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=Alcremie" title="Code">π»</a></td> | ||
<td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=Nytelife26" title="Code">π»</a></td> | ||
<td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=Alcremie" title="Code">π»</a> <a href="https://github.com/sapphire-project/framework/pulls?q=is%3Apr+reviewed-by%3AAlcremie" title="Reviewed Pull Requests">π</a></td> | ||
<td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=Nytelife26" title="Code">π»</a> <a href="#infra-Nytelife26" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#plugin-Nytelife26" title="Plugin/utility libraries">π</a></td> | ||
<td align="center"><a href="https://github.com/Soumil07"><img src="https://avatars0.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Soumil07</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=Soumil07" title="Code">π»</a></td> | ||
<td align="center"><a href="https://lavya.tech/"><img src="https://avatars.githubusercontent.com/u/65386243?v=4?s=100" width="100px;" alt=""/><br /><sub><b>lavgup</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=lavgup" title="Documentation">π</a></td> | ||
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=vladfrangu" title="Code">π»</a> <a href="#infra-vladfrangu" title="Infrastructure (Hosting, Build-Tools, etc)">π</a></td> | ||
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphire-project/framework/commits?author=vladfrangu" title="Code">π»</a> <a href="#infra-vladfrangu" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="https://github.com/sapphire-project/framework/pulls?q=is%3Apr+reviewed-by%3Avladfrangu" title="Reviewed Pull Requests">π</a></td> | ||
</tr> | ||
@@ -81,0 +81,0 @@ </table> |
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
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 too big to display
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
281395
133
4612