mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Port CustomEventsPlugin
This commit is contained in:
parent
28de8a592b
commit
4c4496600b
9 changed files with 268 additions and 0 deletions
39
backend/src/plugins/CustomEvents/CustomEventsPlugin.ts
Normal file
39
backend/src/plugins/CustomEvents/CustomEventsPlugin.ts
Normal 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
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue