zappyzep/backend/src/plugins/Automod/triggers/exampleTrigger.ts
2020-07-27 21:51:03 +03:00

31 lines
758 B
TypeScript

import * as t from "io-ts";
import { automodTrigger } from "../helpers";
interface ExampleMatchResultType {
isBanana: boolean;
}
export const ExampleTrigger = automodTrigger<ExampleMatchResultType>()({
configType: t.type({
allowedFruits: t.array(t.string),
}),
defaultConfig: {
allowedFruits: ["peach", "banana"],
},
async match({ triggerConfig, context }) {
const foundFruit = triggerConfig.allowedFruits.find(fruit => context.message?.data.content === fruit);
if (foundFruit) {
return {
extra: {
isBanana: foundFruit === "banana",
},
};
}
},
renderMatchInformation({ matchResult }) {
return `Matched fruit, isBanana: ${matchResult.extra.isBanana ? "yes" : "no"}`;
},
});