@sapphire/framework
Advanced tools
Comparing version 1.0.0-alpha.9 to 1.0.0-alpha.10
@@ -5,2 +5,24 @@ # Changelog | ||
## [1.0.0-alpha.10](https://github.com/sapphire-project/framework/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2021-02-12) | ||
### ⚠ BREAKING CHANGES | ||
- **command-accepted:** `Events.CommandRun` third argument changed type to `CommandRunPayload`, | ||
this is mostly identical to `CommandAcceptedPayload` (and exactly identical to `CommandFinishPayload`) | ||
and likely won't be a breaking change for your code, however you may need to adjust | ||
your import when using TypeScript. | ||
- **command-accepted:** `Events.CommandFinish` third argument changed type to `CommandFinishPayload`, | ||
this is mostly identical to `CommandAcceptedPayload` (and exactly identical to `CommandRunPayload`) | ||
and likely won't be a breaking change for your code, however you may need to adjust | ||
your import when using TypeScript. | ||
### Features | ||
- **args:** add `name` to context of `Args.unavailableArgument` ([#171](https://github.com/sapphire-project/framework/issues/171)) ([a5bda61](https://github.com/sapphire-project/framework/commit/a5bda611108fc7e382a62f292a667f0228bf2dfa)) | ||
- **args:** add more data to error context for core arguments ([0cfff79](https://github.com/sapphire-project/framework/commit/0cfff793c8f9c8ede6d954a0dbeaad2e7647cb15)) | ||
- **args:** pass more context to args errors ([#174](https://github.com/sapphire-project/framework/issues/174)) ([007eaed](https://github.com/sapphire-project/framework/commit/007eaed76e827bde8d75c9db368620e55b4b017e)) | ||
- **argumenterror:** add type default of `unknown` ([55be30a](https://github.com/sapphire-project/framework/commit/55be30ae4d279067f8dbedab12ba9c034d197cbc)) | ||
- **command-accepted:** add received args to event payloads ([#173](https://github.com/sapphire-project/framework/issues/173)) ([fa60b13](https://github.com/sapphire-project/framework/commit/fa60b13247b71927a26e4738596155b6c041afcb)) | ||
- **message-parser:** add `caseInsensitivePrefixes` client option ([#170](https://github.com/sapphire-project/framework/issues/170)) ([61f9c41](https://github.com/sapphire-project/framework/commit/61f9c41d53f641a92a1f344cba96a2d5ae589d43)) | ||
## [1.0.0-alpha.9](https://github.com/sapphire-project/framework/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2021-02-07) | ||
@@ -7,0 +29,0 @@ |
@@ -16,3 +16,7 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ parameter: context.parameter, 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: { ...context, channel } | ||
}); | ||
} | ||
@@ -19,0 +23,0 @@ } |
@@ -11,3 +11,9 @@ "use strict"; | ||
const channel = (context.message.guild ? context.message.guild.channels : this.context.client.channels).cache.get(parameter); | ||
return channel ? this.ok(channel) : this.error({ parameter, message: 'The argument did not resolve to a channel.', context }); | ||
return channel | ||
? this.ok(channel) | ||
: this.error({ | ||
parameter, | ||
message: 'The argument did not resolve to a channel.', | ||
context: { ...context, channel } | ||
}); | ||
} | ||
@@ -14,0 +20,0 @@ } |
@@ -13,3 +13,7 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ parameter: context.parameter, 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: { ...context, channel } | ||
}); | ||
} | ||
@@ -16,0 +20,0 @@ } |
@@ -19,7 +19,13 @@ "use strict"; | ||
message: 'The argument must be run in a guild.', | ||
context | ||
context: { ...context, guild } | ||
}); | ||
} | ||
const channel = (_a = this.resolveByID(parameter, guild)) !== null && _a !== void 0 ? _a : this.resolveByQuery(parameter, guild); | ||
return channel ? this.ok(channel) : this.error({ parameter, 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: { ...context, guild } | ||
}); | ||
} | ||
@@ -26,0 +32,0 @@ resolveByID(argument, guild) { |
@@ -19,7 +19,13 @@ "use strict"; | ||
message: 'The argument must be run on a guild.', | ||
context | ||
context: { ...context, guild } | ||
}); | ||
} | ||
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, 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: { ...context, guild } | ||
}); | ||
} | ||
@@ -26,0 +32,0 @@ async resolveByID(argument, guild) { |
@@ -12,9 +12,14 @@ "use strict"; | ||
async run(parameter, context) { | ||
var _a; | ||
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, message: 'The argument did not resolve to a message.', context }); | ||
var _a, _b; | ||
const channel = (_a = context.channel) !== null && _a !== void 0 ? _a : context.message.channel; | ||
const message = (_b = (await this.resolveByID(parameter, channel))) !== null && _b !== void 0 ? _b : (await this.resolveByLink(parameter, context)); | ||
return message | ||
? this.ok(message) | ||
: this.error({ | ||
parameter, | ||
message: 'The argument did not resolve to a message.', | ||
context: { ...context, channel } | ||
}); | ||
} | ||
async resolveByID(argument, context) { | ||
var _a; | ||
const channel = (_a = context.channel) !== null && _a !== void 0 ? _a : context.message.channel; | ||
async resolveByID(argument, channel) { | ||
return discord_js_utilities_1.SnowflakeRegex.test(argument) ? channel.messages.fetch(argument).catch(() => null) : null; | ||
@@ -21,0 +26,0 @@ } |
@@ -16,3 +16,7 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ parameter: context.parameter, 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: { ...context, channel } | ||
}); | ||
} | ||
@@ -19,0 +23,0 @@ } |
@@ -16,3 +16,7 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ parameter: context.parameter, 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: { ...context, channel } | ||
}); | ||
} | ||
@@ -19,0 +23,0 @@ } |
@@ -16,3 +16,7 @@ "use strict"; | ||
? this.ok(channel) | ||
: this.error({ parameter: context.parameter, 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: { ...context, channel } | ||
}); | ||
} | ||
@@ -19,0 +23,0 @@ } |
@@ -14,11 +14,11 @@ "use strict"; | ||
try { | ||
message.client.emit(Events_1.Events.CommandRun, message, command, payload); | ||
message.client.emit(Events_1.Events.CommandRun, message, command, { ...payload, args }); | ||
const result = await command.run(message, args, context); | ||
message.client.emit(Events_1.Events.CommandSuccess, { ...payload, result }); | ||
message.client.emit(Events_1.Events.CommandSuccess, { ...payload, args, result }); | ||
} | ||
catch (error) { | ||
message.client.emit(Events_1.Events.CommandError, error, { ...payload, piece: command }); | ||
message.client.emit(Events_1.Events.CommandError, error, { ...payload, args, piece: command }); | ||
} | ||
finally { | ||
message.client.emit(Events_1.Events.CommandFinish, message, command, payload); | ||
message.client.emit(Events_1.Events.CommandFinish, message, command, { ...payload, args }); | ||
} | ||
@@ -25,0 +25,0 @@ } |
@@ -75,5 +75,9 @@ "use strict"; | ||
return null; | ||
if (typeof prefixes === 'string') | ||
return content.startsWith(prefixes) ? prefixes : null; | ||
return (_a = prefixes.find((prefix) => content.startsWith(prefix))) !== null && _a !== void 0 ? _a : null; | ||
const { caseInsensitivePrefixes } = this.context.client.options; | ||
if (caseInsensitivePrefixes) | ||
content = content.toLowerCase(); | ||
if (typeof prefixes === 'string') { | ||
return content.startsWith(caseInsensitivePrefixes ? prefixes.toLowerCase() : prefixes) ? prefixes : null; | ||
} | ||
return (_a = prefixes.find((prefix) => content.startsWith(caseInsensitivePrefixes ? prefix.toLowerCase() : prefix))) !== null && _a !== void 0 ? _a : null; | ||
} | ||
@@ -80,0 +84,0 @@ } |
@@ -219,10 +219,18 @@ "use strict"; | ||
} | ||
/** | ||
* Defines the `JSON.stringify` override. | ||
*/ | ||
toJSON() { | ||
return { message: this.message, command: this.command, commandContext: this.commandContext }; | ||
} | ||
unavailableArgument(type) { | ||
const name = typeof type === 'string' ? type : type.name; | ||
return Result_1.err(new UserError_1.UserError({ | ||
identifier: "argsUnavailable" /* ArgsUnavailable */, | ||
message: `The argument "${typeof type === 'string' ? type : type.name}" was not found.` | ||
message: `The argument "${name}" was not found.`, | ||
context: { name, ...this.toJSON() } | ||
})); | ||
} | ||
missingArguments() { | ||
return Result_1.err(new UserError_1.UserError({ identifier: "argsMissing" /* ArgsMissing */, message: 'There are no more arguments.' })); | ||
return Result_1.err(new UserError_1.UserError({ identifier: "argsMissing" /* ArgsMissing */, message: 'There are no more arguments.', context: this.toJSON() })); | ||
} | ||
@@ -229,0 +237,0 @@ /** |
{ | ||
"name": "@sapphire/framework", | ||
"version": "1.0.0-alpha.9", | ||
"version": "1.0.0-alpha.10", | ||
"description": "Discord bot framework built on top of @sapphire/lib for advanced and amazing bots.", | ||
@@ -11,3 +11,2 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"prepublishOnly": "run-s build:**", | ||
"lint": "eslint src tests scripts --ext mjs,ts --fix", | ||
@@ -28,3 +27,6 @@ "format": "prettier --write {src,tests,scripts}/**/*.ts", | ||
"commit": "git-cz", | ||
"cz": "git-cz" | ||
"cz": "git-cz", | ||
"prepublishOnly": "run-s build:** && pinst --disable", | ||
"_postinstall": "husky install .github/husky", | ||
"postpublish": "pinst --enable" | ||
}, | ||
@@ -34,3 +36,3 @@ "dependencies": { | ||
"@sapphire/discord.js-utilities": "^1.4.0", | ||
"@sapphire/pieces": "^1.2.1", | ||
"@sapphire/pieces": "^1.2.2", | ||
"@sapphire/ratelimits": "^1.1.4", | ||
@@ -51,6 +53,6 @@ "@sapphire/utilities": "^1.4.4", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.22", | ||
"@types/node": "^14.14.25", | ||
"@types/ws": "^7.4.0", | ||
"@typescript-eslint/eslint-plugin": "^4.14.2", | ||
"@typescript-eslint/parser": "^4.14.2", | ||
"@typescript-eslint/eslint-plugin": "^4.15.0", | ||
"@typescript-eslint/parser": "^4.15.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
@@ -61,7 +63,8 @@ "discord.js": "^12.5.1", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"husky": "^4.3.8", | ||
"husky": "^5.0.9", | ||
"jest": "^26.6.3", | ||
"jest-circus": "^26.6.3", | ||
"lint-staged": "^10.5.3", | ||
"lint-staged": "^10.5.4", | ||
"npm-run-all": "^4.1.5", | ||
"pinst": "^2.1.4", | ||
"prettier": "^2.2.1", | ||
@@ -72,7 +75,7 @@ "pretty-quick": "^3.1.0", | ||
"standard-version": "^9.1.0", | ||
"ts-jest": "^26.5.0", | ||
"ts-jest": "^26.5.1", | ||
"ts-node": "^9.1.1", | ||
"typedoc": "^0.20.23", | ||
"typedoc-plugin-nojekyll": "^1.0.1", | ||
"typescript": "^4.1.3" | ||
"typescript": "^4.1.5" | ||
}, | ||
@@ -104,8 +107,2 @@ "repository": { | ||
"homepage": "https://sapphire-project.github.io/framework", | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "yarn pretty-quick --staged && yarn lint-staged" | ||
} | ||
}, | ||
"commitlint": { | ||
@@ -133,5 +130,6 @@ "extends": [ | ||
"jest-jasmine2": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.1.tgz", | ||
"dot-prop": "^6.0.1" | ||
"dot-prop": "^6.0.1", | ||
"marked": "^2.0.0" | ||
}, | ||
"prettier": "@sapphire/prettier-config" | ||
} |
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
290001
4712
32
Updated@sapphire/pieces@^1.2.2