feat: add automod thread_archive and thread_unarchive triggers (#292)
Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
parent
6709115166
commit
446f188e16
6 changed files with 160 additions and 1 deletions
|
@ -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);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue