Skip to content

Commit

Permalink
include tag objects in applied_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
michelle0927 committed Nov 5, 2024
1 parent ec0819b commit 8aca7e9
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
...common,
key: "discord_bot-new-forum-thread-message",
name: "New Forum Thread Message",
description: "Emit new event for each forum thread message posted. Note that your bot must have the `MESSAGE_CONTENT` privilege intent to see the message content, [see the docs here](https://discord.com/developers/docs/topics/gateway#message-content-intent).",
description: "Emit new event for each forum thread message posted. Note that your bot must have the `MESSAGE_CONTENT` privilege intent to see the message content. [See the documentation](https://discord.com/developers/docs/topics/gateway#message-content-intent).",
type: "source",
version: "0.0.4",
dedupe: "unique", // Dedupe events based on the Discord message ID
Expand Down Expand Up @@ -120,6 +120,16 @@ export default {
thread: await this.getChannel(message.channel_id),
})));

const { available_tags: availableTags = [] } = await this.getChannel(this.forumId);
for (const message of messages) {
if (!message.thread.applied_tags) {
message.thread.applied_tags = [];
}
message.thread.applied_tags = message.thread.applied_tags.map((tagId) => ({
...availableTags.find(({ id }) => id === tagId),
}));
}

messages.reverse().forEach((message) => {
this.$emit(message, {
id: message.id, // dedupes events based on this ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,45 @@ export default {
"edited_timestamp": null,
"flags": 0,
"components": [],
"position": 13
}
"position": 13,
"thread": {
"id": "1301256410990116917",
"type": 11,
"last_message_id": "1301256410990116917",
"flags": 0,
"guild_id": "901259362205589565",
"name": "hello world",
"parent_id": "1301256016934994024",
"rate_limit_per_user": 0,
"bitrate": 64000,
"user_limit": 0,
"rtc_region": null,
"owner_id": "867892178135023656",
"thread_metadata": {
"archived": false,
"archive_timestamp": "2024-10-30T18:48:24.555000+00:00",
"auto_archive_duration": 4320,
"locked": false,
"create_timestamp": "2024-10-30T18:48:24.555000+00:00",
},
"message_count": 0,
"member_count": 1,
"total_message_sent": 0,
"applied_tags": [
{
"id": "1301256232052457563",
"name": "tag",
"moderated": false,
"emoji_id": null,
"emoji_name": null,
},
{
"id": "1301281978968178759",
"name": "tag2",
"moderated": false,
"emoji_id": null,
"emoji_name": null,
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sampleEmit from "./test-event.mjs";
export default {
...common,
key: "discord_bot-new-tag-added-to-thread",
name: "New Tag Added to Thread",
name: "New Tag Added to Forum Thread",
description: "Emit new event when a new tag is added to a thread",
type: "source",
version: "0.0.1",
Expand Down Expand Up @@ -49,6 +49,11 @@ export default {
ts: Date.now(),
};
},
getChannel(id) {
return this.discord._makeRequest({
path: `/channels/${id}`,
});
},
},
async run() {
let tags = this._getTags();
Expand All @@ -62,10 +67,17 @@ export default {
continue;
}
if (thread.applied_tags.some((tag) => !tags[thread.id] || !tags[thread.id].includes(tag))) {
tags[thread.id] = thread.applied_tags;

const { available_tags: availableTags = [] } = await this.getChannel(thread.parent_id);

thread.applied_tags = thread.applied_tags.map((tagId) => ({
...availableTags.find(({ id }) => id === tagId),
}));

const meta = this.generateMeta(thread);
this.$emit(thread, meta);

tags[thread.id] = thread.applied_tags;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,26 @@ export default {
"member_count": 1,
"total_message_sent": 0,
"applied_tags": [
"1301256232052457563",
"1301281978968178759"
]
}
{
"id": "1301256232052457563",
"name": "tag",
"moderated": false,
"emoji_id": null,
"emoji_name": null,
},
{
"id": "1301282004998033428",
"name": "tag3",
"moderated": false,
"emoji_id": null,
"emoji_name": null,
},
{
"id": "1301281978968178759",
"name": "tag2",
"moderated": false,
"emoji_id": null,
"emoji_name": null,
},
],
};

0 comments on commit 8aca7e9

Please sign in to comment.