3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00
zeppelin/backend/src/plugins/Automod/triggers/threadDelete.ts

51 lines
1.7 KiB
TypeScript

import { Snowflake } from "discord-api-types/v9";
import { User, Util } from "discord.js";
import * as t from "io-ts";
import { automodTrigger } from "../helpers";
interface ThreadDeleteResult {
matchedThreadId: Snowflake;
matchedThreadName: string;
matchedThreadParentId: Snowflake;
matchedThreadParentName: string;
matchedThreadOwner: User | undefined;
}
export const ThreadDeleteTrigger = automodTrigger<ThreadDeleteResult>()({
configType: t.type({}),
defaultConfig: {},
async match({ context }) {
if (!context.threadChange?.deleted) {
return;
}
const thread = context.threadChange.deleted;
return {
extra: {
matchedThreadId: thread.id,
matchedThreadName: thread.name,
matchedThreadParentId: thread.parentId ?? "Unknown",
matchedThreadParentName: thread.parent?.name ?? "Unknown",
matchedThreadOwner: context.user,
},
};
},
renderMatchInformation({ matchResult }) {
const threadId = matchResult.extra.matchedThreadId;
const threadOwner = matchResult.extra.matchedThreadOwner;
const threadName = matchResult.extra.matchedThreadName;
const parentId = matchResult.extra.matchedThreadParentId;
const parentName = matchResult.extra.matchedThreadParentName;
if (threadOwner) {
return `Thread **#${threadName ?? "Unknown"}** (\`${threadId}\`) created by **${Util.escapeBold(
threadOwner.tag,
)}** (\`${threadOwner.id}\`) in the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
}
return `Thread **#${
threadName ?? "Unknown"
}** (\`${threadId}\`) from the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
},
});