-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discord Bot - Source updates (#14472)
* updates * pnpm-lock.yaml * update * include tag objects in applied_tags
- Loading branch information
1 parent
d956d5c
commit 6856152
Showing
6 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/discord_bot", | ||
"version": "0.5.5", | ||
"version": "0.6.0", | ||
"description": "Pipedream Discord_bot Components", | ||
"main": "discord_bot.app.js", | ||
"keywords": [ | ||
|
@@ -10,7 +10,7 @@ | |
"homepage": "https://pipedream.com/apps/discord_bot", | ||
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"dependencies": { | ||
"@pipedream/platform": "^1.6.0", | ||
"@pipedream/platform": "^3.0.3", | ||
"form-data": "^4.0.0", | ||
"lodash.maxby": "^4.6.0" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
components/discord_bot/sources/new-tag-added-to-thread/new-tag-added-to-thread.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
import common from "../common.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "discord_bot-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", | ||
dedupe: "unique", | ||
props: { | ||
...common.props, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
}, | ||
}, | ||
}, | ||
hooks: { | ||
async deploy() { | ||
const tags = {}; | ||
const { threads } = await this.discord.listThreads({ | ||
guildId: this.guildId, | ||
}); | ||
threads.forEach((thread) => { | ||
if (thread?.applied_tags) { | ||
tags[thread.id] = thread?.applied_tags; | ||
} | ||
}); | ||
this._setTags(tags); | ||
}, | ||
}, | ||
methods: { | ||
...common.methods, | ||
_getTags() { | ||
return this.db.get("tags") || {}; | ||
}, | ||
_setTags(tags) { | ||
this.db.set("tags", tags); | ||
}, | ||
generateMeta(thread) { | ||
return { | ||
id: thread.id, | ||
summary: `New tag in thread ${thread.id}`, | ||
ts: Date.now(), | ||
}; | ||
}, | ||
getChannel(id) { | ||
return this.discord._makeRequest({ | ||
path: `/channels/${id}`, | ||
}); | ||
}, | ||
}, | ||
async run() { | ||
let tags = this._getTags(); | ||
|
||
const { threads } = await this.discord.listThreads({ | ||
guildId: this.guildId, | ||
}); | ||
|
||
for (const thread of threads) { | ||
if (!thread.applied_tags) { | ||
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); | ||
|
||
} | ||
} | ||
|
||
this._setTags(tags); | ||
}, | ||
sampleEmit, | ||
}; |
47 changes: 47 additions & 0 deletions
47
components/discord_bot/sources/new-tag-added-to-thread/test-event.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export default { | ||
"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": "1301282004998033428", | ||
"name": "tag3", | ||
"moderated": false, | ||
"emoji_id": null, | ||
"emoji_name": null, | ||
}, | ||
{ | ||
"id": "1301281978968178759", | ||
"name": "tag2", | ||
"moderated": false, | ||
"emoji_id": null, | ||
"emoji_name": null, | ||
}, | ||
], | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.