Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/discord_bot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/discord_bot",
"version": "0.6.1",
"version": "0.6.2",
"description": "Pipedream Discord_bot Components",
"main": "discord_bot.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import common from "../common.mjs";
import constants from "../common/constants.mjs";
import common from "../../common.mjs";
import constants from "../../common/constants.mjs";

export default {
...common,
Expand All @@ -17,5 +17,16 @@ export default {
_setLastMemberID(memberID) {
this.db.set(constants.LAST_MEMBER_ID, memberID);
},
_getBotId() {
return this.db.get("botId");
},
_setBotId(botId) {
this.db.set("botId", botId);
},
getBotProfile() {
return this.discord._makeRequest({
path: "/users/@me",
});
},
},
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import maxBy from "lodash.maxby";
import constants from "../../common/constants.mjs";
import common from "../common.mjs";
import common from "../common/common.mjs";
import sampleEmit from "./test-event.mjs";

export default {
Expand All @@ -10,7 +10,7 @@ export default {
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 documentation](https://discord.com/developers/docs/topics/gateway#message-content-intent).",
type: "source",
version: "0.0.4",
version: "0.0.5",
dedupe: "unique", // Dedupe events based on the Discord message ID
props: {
...common.props,
Expand All @@ -35,6 +35,20 @@ export default {
label: "Forum Id",
description: "Select the forum you want to watch.",
},
ignoreBotMessages: {
type: "boolean",
label: "Ignore Bot Messages",
description: "Set to `true` to only emit messages NOT from the configured Discord bot",
optional: true,
},
},
hooks: {
async deploy() {
if (this.ignoreBotMessages) {
const { id } = await this.getBotProfile();
this._setBotId(id);
}
},
},
methods: {
...common.methods,
Expand All @@ -47,6 +61,9 @@ export default {
async run({ $ }) {
// We store a cursor to the last message ID
let lastMessageIDs = this._getLastMessageIDs();
const botId = this.ignoreBotMessages
? this._getBotId()
: null;

const { threads } = await this.discord.listThreads({
$,
Expand Down Expand Up @@ -113,6 +130,10 @@ export default {
continue;
}

if (botId) {
messages = messages.filter((message) => message.author.id !== botId);
}

console.log(`${messages.length} new messages in thread ${channelId}`);

messages = await Promise.all(messages.map(async (message) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import common from "../common.mjs";
import common from "../common/common.mjs";

export default {
...common,
Expand All @@ -8,7 +8,7 @@ export default {
description: "Emit new event for every member added to a guild. [See docs here](https://discord.com/developers/docs/resources/guild#list-guild-members)",
type: "source",
dedupe: "unique",
version: "0.1.4",
version: "0.1.5",
props: {
...common.props,
db: "$.service.db",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import maxBy from "lodash.maxby";
import common from "../common.mjs";
import common from "../common/common.mjs";
import sampleEmit from "./test-event.mjs";

const { discord } = common.props;
Expand All @@ -11,8 +11,7 @@ export default {
name: "New Message in Channel",
description: "Emit new event for each message posted to one or more channels",
type: "source",
version: "0.0.18",

version: "0.0.19",
dedupe: "unique", // Dedupe events based on the Discord message ID
props: {
...common.props,
Expand All @@ -37,16 +36,33 @@ export default {
optional: true,
default: false,
},
ignoreBotMessages: {
type: "boolean",
label: "Ignore Bot Messages",
description: "Set to `true` to only emit messages NOT from the configured Discord bot",
optional: true,
},
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
hooks: {
async deploy() {
if (this.ignoreBotMessages) {
const { id } = await this.getBotProfile();
this._setBotId(id);
}
},
},
async run({ $ }) {
// We store a cursor to the last message ID
let lastMessageIDs = this._getLastMessageIDs();
const botId = this.ignoreBotMessages
? this._getBotId()
: null;

// If this is our first time running this source,
// get the last N messages, emit them, and checkpoint
Expand Down Expand Up @@ -97,6 +113,10 @@ export default {
return;
}

if (botId) {
messages = messages.filter((message) => message.author.id !== botId);
}

console.log(`${messages.length} new messages in channel ${channelId}`);

// Batched emits do not take advantage of the built-in deduper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import common from "../common.mjs";
import common from "../common/common.mjs";
import sampleEmit from "./test-event.mjs";

export default {
Expand All @@ -8,7 +8,7 @@ export default {
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",
version: "0.0.2",
dedupe: "unique",
props: {
...common.props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import maxBy from "lodash.maxby";
import common from "../common.mjs";
import common from "../common/common.mjs";
import sampleEmit from "./test-event.mjs";

export default {
Expand All @@ -9,7 +9,7 @@ export default {
name: "New Thread Message",
description: "Emit new event for each thread message posted.",
type: "source",
version: "0.0.5",
version: "0.0.6",
dedupe: "unique", // Dedupe events based on the Discord message ID
props: {
...common.props,
Expand All @@ -20,10 +20,27 @@ export default {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
ignoreBotMessages: {
type: "boolean",
label: "Ignore Bot Messages",
description: "Set to `true` to only emit messages NOT from the configured Discord bot",
optional: true,
},
},
hooks: {
async deploy() {
if (this.ignoreBotMessages) {
const { id } = await this.getBotProfile();
this._setBotId(id);
}
},
},
async run({ $ }) {
// We store a cursor to the last message ID
let lastMessageIDs = this._getLastMessageIDs();
const botId = this.ignoreBotMessages
? this._getBotId()
: null;

const { threads } = await this.discord.listThreads({
$,
Expand Down Expand Up @@ -81,6 +98,10 @@ export default {
continue;
}

if (botId) {
messages = messages.filter((message) => message.author.id !== botId);
}

console.log(`${messages.length} new messages in thread ${channelId}`);

messages.reverse().forEach((message) => {
Expand Down
18 changes: 6 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading