3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-11 13:07:20 +00:00

Thread events - attempt to pass message object in context (#3)

* initial

* rmv console log

* Update backend/src/plugins/Automod/events/runAutomodOnThreadEvents.ts

Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
metal 2021-09-01 13:35:27 +01:00 committed by almeidx
parent 723995f30c
commit 0b4369f0c8
No known key found for this signature in database
GPG key ID: 01C5E03866747F46

View file

@ -6,7 +6,6 @@ export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginTyp
event: "threadCreate",
async listener({ pluginData, args: { thread } }) {
const user = thread.ownerId ? await pluginData.client.users.fetch(thread.ownerId).catch(() => void 0) : void 0;
const context: AutomodContext = {
timestamp: Date.now(),
threadChange: {
@ -14,6 +13,19 @@ export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginTyp
},
user,
};
const sourceChannel = pluginData.client.channels.cache.find(c => c.id === thread.parentId);
if (sourceChannel?.isText()) {
const sourceMessage = sourceChannel.messages.cache.find(
m => m.thread?.id === thread.id || m.reference?.channelId === thread.id,
);
if (sourceMessage) {
const message = await pluginData.state.savedMessages.find(sourceMessage.id);
if (message) {
message.channel_id = thread.id;
context.message = message;
}
}
}
pluginData.state.queue.add(() => {
runAutomod(pluginData, context);