3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

feat: add automod thread_archive and thread_unarchive triggers (#292)

Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
metal 2021-10-31 20:08:29 +00:00 committed by GitHub
parent 6709115166
commit 446f188e16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 160 additions and 1 deletions

View file

@ -53,3 +53,35 @@ 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(() => undefined)
: undefined;
const changes: AutomodContext["threadChange"] = {};
if (oldThread.archived !== thread.archived) {
changes.archived = thread.archived ? thread : undefined;
changes.unarchived = !thread.archived ? thread : undefined;
}
if (oldThread.locked !== thread.locked) {
changes.locked = thread.locked ? thread : undefined;
changes.unlocked = !thread.locked ? thread : undefined;
}
if (Object.keys(changes).length === 0) return;
const context: AutomodContext = {
timestamp: Date.now(),
threadChange: changes,
user,
channel: thread,
};
pluginData.state.queue.add(() => {
runAutomod(pluginData, context);
});
},
});