Automod work vol 2

This commit is contained in:
Dragory 2020-07-27 21:51:03 +03:00
parent f657b169df
commit 0e9f65e0d5
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
12 changed files with 420 additions and 59 deletions

View file

@ -1,27 +1,31 @@
import * as t from "io-ts";
import { automodTrigger } from "../helpers";
export const ExampleTrigger = automodTrigger({
interface ExampleMatchResultType {
isBanana: boolean;
}
export const ExampleTrigger = automodTrigger<ExampleMatchResultType>()({
configType: t.type({
some: t.number,
value: t.string,
allowedFruits: t.array(t.string),
}),
defaultConfig: {},
matchResultType: t.type({
thing: t.string,
}),
async match() {
return {
extra: {
thing: "hi",
},
};
defaultConfig: {
allowedFruits: ["peach", "banana"],
},
renderMatchInformation() {
return "";
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"}`;
},
});