@sapphire/framework
Advanced tools
Comparing version 1.0.0-alpha.10 to 1.0.0-alpha.11
@@ -5,2 +5,12 @@ # Changelog | ||
## [1.0.0-alpha.11](https://github.com/sapphire-project/framework/compare/v1.0.0-alpha.10...v1.0.0-alpha.11) (2021-02-16) | ||
### Features | ||
- **structures:** add global preconditions ([#176](https://github.com/sapphire-project/framework/issues/176)) ([e8ef41f](https://github.com/sapphire-project/framework/commit/e8ef41fbbc420ee8cc2283d99554fc16d241fec8)) | ||
### Bug Fixes | ||
- **enabled:** remove last remnant of essentials ([4928823](https://github.com/sapphire-project/framework/commit/4928823751baa8f9e6a6f4e3c4237055f56e1384)) | ||
## [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) | ||
@@ -7,0 +17,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreEvent = void 0; | ||
require("../../lib/errors/Identifiers"); | ||
const UserError_1 = require("../../lib/errors/UserError"); | ||
const Result_1 = require("../../lib/parsers/Result"); | ||
const Event_1 = require("../../lib/structures/Event"); | ||
@@ -15,13 +12,15 @@ const Events_1 = require("../../lib/types/Events"); | ||
const { message, command } = payload; | ||
if (!command.enabled) { | ||
message.client.emit(Events_1.Events.CommandDenied, new UserError_1.UserError({ identifier: "commandDisabled" /* CommandDisabled */, message: 'This command is disabled.', context: payload }), payload); | ||
// Run global preconditions: | ||
const globalResult = await this.context.stores.get('preconditions').run(message, command, payload); | ||
if (!globalResult.success) { | ||
message.client.emit(Events_1.Events.CommandDenied, globalResult.error, payload); | ||
return; | ||
} | ||
const result = await command.preconditions.run(message, command); | ||
if (Result_1.isErr(result)) { | ||
message.client.emit(Events_1.Events.CommandDenied, result.error, payload); | ||
// Run command-specific preconditions: | ||
const localResult = await command.preconditions.run(message, command, payload); | ||
if (!localResult.success) { | ||
message.client.emit(Events_1.Events.CommandDenied, localResult.error, payload); | ||
return; | ||
} | ||
else { | ||
message.client.emit(Events_1.Events.CommandAccepted, payload); | ||
} | ||
message.client.emit(Events_1.Events.CommandAccepted, payload); | ||
} | ||
@@ -28,0 +27,0 @@ } |
@@ -8,2 +8,7 @@ "use strict"; | ||
class Precondition extends pieces_1.Piece { | ||
constructor(context, options = {}) { | ||
var _a; | ||
super(context, options); | ||
this.position = (_a = options.position) !== null && _a !== void 0 ? _a : null; | ||
} | ||
ok() { | ||
@@ -10,0 +15,0 @@ return Result_1.ok(); |
@@ -5,2 +5,3 @@ "use strict"; | ||
const pieces_1 = require("@sapphire/pieces"); | ||
const Result_1 = require("../parsers/Result"); | ||
const Precondition_1 = require("./Precondition"); | ||
@@ -10,5 +11,36 @@ class PreconditionStore extends pieces_1.Store { | ||
super(Precondition_1.Precondition, { name: 'preconditions' }); | ||
this.globalPreconditions = []; | ||
} | ||
async run(message, command, context = {}) { | ||
for (const precondition of this.globalPreconditions) { | ||
const result = await precondition.run(message, command, context); | ||
if (!result.success) | ||
return result; | ||
} | ||
return Result_1.ok(); | ||
} | ||
set(key, value) { | ||
if (value.position !== null) { | ||
const index = this.globalPreconditions.findIndex((precondition) => precondition.position >= value.position); | ||
// If a middleware with lower priority wasn't found, push to the end of the array | ||
if (index === -1) | ||
this.globalPreconditions.push(value); | ||
else | ||
this.globalPreconditions.splice(index, 0, value); | ||
} | ||
return super.set(key, value); | ||
} | ||
delete(key) { | ||
const index = this.globalPreconditions.findIndex((precondition) => precondition.name === key); | ||
// If the middleware was found, remove it | ||
if (index !== -1) | ||
this.globalPreconditions.splice(index, 1); | ||
return super.delete(key); | ||
} | ||
clear() { | ||
this.globalPreconditions.length = 0; | ||
return super.clear(); | ||
} | ||
} | ||
exports.PreconditionStore = PreconditionStore; | ||
//# sourceMappingURL=PreconditionStore.js.map |
{ | ||
"name": "@sapphire/framework", | ||
"version": "1.0.0-alpha.10", | ||
"version": "1.0.0-alpha.11", | ||
"description": "Discord bot framework built on top of @sapphire/lib for advanced and amazing bots.", | ||
@@ -32,7 +32,7 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@sapphire/discord-utilities": "^2.0.1", | ||
"@sapphire/discord.js-utilities": "^1.4.0", | ||
"@sapphire/discord-utilities": "^2.0.4", | ||
"@sapphire/discord.js-utilities": "^1.4.3", | ||
"@sapphire/pieces": "^1.2.2", | ||
"@sapphire/ratelimits": "^1.1.4", | ||
"@sapphire/utilities": "^1.4.4", | ||
"@sapphire/ratelimits": "^1.1.5", | ||
"@sapphire/utilities": "^1.4.5", | ||
"lexure": "^0.17.0" | ||
@@ -47,13 +47,13 @@ }, | ||
"@mdx-js/mdx": "^1.6.22", | ||
"@sapphire/eslint-config": "^2.1.1", | ||
"@sapphire/prettier-config": "^1.0.6", | ||
"@sapphire/ts-config": "^2.0.0", | ||
"@sapphire/eslint-config": "^2.1.2", | ||
"@sapphire/prettier-config": "^1.0.7", | ||
"@sapphire/ts-config": "^2.0.1", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.25", | ||
"@types/node": "^14.14.28", | ||
"@types/ws": "^7.4.0", | ||
"@typescript-eslint/eslint-plugin": "^4.15.0", | ||
"@typescript-eslint/parser": "^4.15.0", | ||
"@typescript-eslint/eslint-plugin": "^4.15.1", | ||
"@typescript-eslint/parser": "^4.15.1", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"discord.js": "^12.5.1", | ||
"eslint": "^7.19.0", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
@@ -69,3 +69,3 @@ "eslint-plugin-prettier": "^3.3.1", | ||
"pretty-quick": "^3.1.0", | ||
"rollup": "^2.38.5", | ||
"rollup": "^2.39.0", | ||
"rollup-plugin-dts": "^2.0.1", | ||
@@ -75,3 +75,3 @@ "standard-version": "^9.1.0", | ||
"ts-node": "^9.1.1", | ||
"typedoc": "^0.20.23", | ||
"typedoc": "^0.20.25", | ||
"typedoc-plugin-nojekyll": "^1.0.1", | ||
@@ -78,0 +78,0 @@ "typescript": "^4.1.5" |
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
295270
137
4783