3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-24 01:55:03 +00:00
This commit is contained in:
metal 2021-09-14 14:37:48 +00:00 committed by almeidx
parent 6c01bb6200
commit 0f0f47a390
No known key found for this signature in database
GPG key ID: F403F80B79353CB4
8 changed files with 275 additions and 1 deletions

View file

@ -2,6 +2,7 @@ import { typedGuildEventListener } from "knub";
import { RecentActionType } from "../constants";
import { GuildSavedMessages } from "../../../data/GuildSavedMessages";
import { runAutomod } from "../functions/runAutomod";
import diff from "lodash.difference";
import { AutomodContext, AutomodPluginType } from "../types";
export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginType>()({
@ -67,3 +68,31 @@ export const RunAutomodOnThreadDelete = typedGuildEventListener<AutomodPluginTyp
});
},
});
export const RunAutomodOnThreadUpdate = typedGuildEventListener<AutomodPluginType>()({
event: "threadUpdate",
async listener({ pluginData, args: { oldThread, newThread: thread } }) {
const user = thread.ownerId ? await pluginData.client.users.fetch(thread.ownerId).catch(() => void 0) : void 0;
const changes: AutomodContext["threadChange"] = {};
if (oldThread.archived !== thread.archived) {
changes.archived = thread.archived ? thread : void 0;
changes.unarchived = !thread.archived ? thread : void 0;
}
if (oldThread.locked !== thread.locked) {
changes.locked = thread.locked ? thread : void 0;
changes.unlocked = !thread.locked ? thread : void 0;
}
if (Object.keys(changes).length === 0) return;
const context: AutomodContext = {
timestamp: Date.now(),
threadChange: changes,
user,
};
pluginData.state.queue.add(() => {
runAutomod(pluginData, context);
});
},
});