3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-07 16:05:01 +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,26 @@
import { PluginData } from "knub";
import { CustomEventsPluginType } from "../types";
import * as t from "io-ts";
import { renderTemplate } from "../../../templateFormatter";
import { ActionError } from "../ActionError";
import { TextChannel } from "eris";
export const MessageAction = t.type({
type: t.literal("message"),
channel: t.string,
content: t.string,
});
export type TMessageAction = t.TypeOf<typeof MessageAction>;
export async function messageAction(
pluginData: PluginData<CustomEventsPluginType>,
action: TMessageAction,
values: any,
) {
const targetChannelId = await renderTemplate(action.channel, values, false);
const targetChannel = pluginData.guild.channels.get(targetChannelId);
if (!targetChannel) throw new ActionError("Unknown target channel");
if (!(targetChannel instanceof TextChannel)) throw new ActionError("Target channel is not a text channel");
await targetChannel.createMessage({ content: action.content });
}