3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Port CustomEventsPlugin

This commit is contained in:
Dragory 2020-07-30 02:47:47 +03:00
parent 28de8a592b
commit 4c4496600b
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
9 changed files with 268 additions and 0 deletions

View file

@ -0,0 +1,39 @@
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
import { ConfigSchema, CustomEventsPluginType } from "./types";
import { command, parseSignature } from "knub";
import { commandTypes } from "../../commandTypes";
import { stripObjectToScalars } from "../../utils";
import { runEvent } from "./functions/runEvent";
const defaultOptions = {
config: {
events: {},
},
};
export const CustomEventsPlugin = zeppelinPlugin<CustomEventsPluginType>()("custom_events", {
configSchema: ConfigSchema,
defaultOptions,
onLoad(pluginData) {
const config = pluginData.config.get();
for (const [key, event] of Object.entries(config.events)) {
if (event.trigger.type === "command") {
const signature = event.trigger.params ? parseSignature(event.trigger.params, commandTypes) : {};
const eventCommand = command({
trigger: event.trigger.name,
permission: `events.${key}.trigger.can_use`,
signature,
run({ message, args }) {
const strippedMsg = stripObjectToScalars(message, ["channel", "author"]);
runEvent(pluginData, event, { msg: message, args }, { args, msg: strippedMsg });
},
});
}
}
},
onUnload() {
// TODO: Run clearTriggers() once we actually have something there
},
});