-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//@ts-nocheck | ||
/** | ||
* @plugin | ||
* fromCallback turns a callback into a plugin result. | ||
* if the callback returns truthy value, plugin continues. | ||
* This control plugin works for every command type. The arguments of the callback | ||
* mirror the execute method on the current module. | ||
* @author @jacoobes [<@182326315813306368>] | ||
* @version 1.0.0 | ||
* @example | ||
* ```ts | ||
* const myServer = "941002690211766332"; | ||
* export default commandModule({ | ||
* type: CommandType.Both, | ||
* plugins: [ | ||
* //This plugin prevents this command module from executing in other servers except myServer | ||
* fromCallback((ctx, args) => ctx.guildId == myServer) | ||
* ], | ||
* execute: ctx => { | ||
* ctx.reply("I only respond in myServer!"); | ||
* } | ||
* }) | ||
* ``` | ||
* @end | ||
*/ | ||
|
||
|
||
import { PluginType, makePlugin, controller } from "@sern/handler"; | ||
|
||
export const fromCallback = (cb: (...args: any[]) => boolean) => | ||
makePlugin(PluginType.Control, (...args) => { | ||
//console.log(args) | ||
if(cb.apply(null, args)) { | ||
return controller.next(); | ||
} | ||
return controller.stop(); | ||
}); |