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