Recipes
Custom Events
Module augmentation
As in other sections, module augmentation will be used, we recommend reading it first.
Seyfert allows to load, integrate and execute custom "events" to be called anywhere, for the sake of this example an simple event will be created called ourEvent.
Overwriting events
If two events have the same name, they will be overwritten.
Integrating
First we need to let know Seyfert typing system that we will have an custom event.
declare module "seyfert" {
interface CustomEvents {
ourEvent: (text: string) => void;
}
}Loading event
This is just here to flex that you don't have to do anything, just put your events in the designated folder in seyfert.config.
import { createEvent } from 'seyfert';
export default createEvent({
data: { name: "ourEvent", once: false },
run: (text) => {
console.log(text);
}
});Executing
import { Client } from "seyfert";
const client = new Client();
(async () => {
await client.start();
client.events?.runCustom('ourEvent', 'Hello, world!');
})();
declare module "seyfert" {
interface CustomEvents {
ourEvent: (text: string) => void;
}
}After running the code, you should see Hello, world! in the console. That's it!