zappyzep/backend/src/plugins/Automod/events/runAutomodOnThreadEvents.ts
Almeida 92dfbca362
feat: add thread_create and thread_delete automod triggers (#272)
Co-authored-by: metal <admin@metalruller.com>
2021-10-31 17:21:53 +02:00

47 lines
1.3 KiB
TypeScript

import { typedGuildEventListener } from "knub";
import { runAutomod } from "../functions/runAutomod";
import { AutomodContext, AutomodPluginType } from "../types";
export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginType>()({
event: "threadCreate",
async listener({ pluginData, args: { thread } }) {
const user = thread.ownerId
? await pluginData.client.users.fetch(thread.ownerId).catch(() => undefined)
: undefined;
const context: AutomodContext = {
timestamp: Date.now(),
threadChange: {
created: thread,
},
user,
channel: thread,
};
pluginData.state.queue.add(() => {
runAutomod(pluginData, context);
});
},
});
export const RunAutomodOnThreadDelete = typedGuildEventListener<AutomodPluginType>()({
event: "threadDelete",
async listener({ pluginData, args: { thread } }) {
const user = thread.ownerId
? await pluginData.client.users.fetch(thread.ownerId).catch(() => undefined)
: undefined;
const context: AutomodContext = {
timestamp: Date.now(),
threadChange: {
deleted: thread,
},
user,
channel: thread,
};
pluginData.state.queue.add(() => {
runAutomod(pluginData, context);
});
},
});