47 lines
1.3 KiB
TypeScript
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);
|
|
});
|
|
},
|
|
});
|