Skip to content

Commit

Permalink
Merge branch 'activepieces:main' into hubspot
Browse files Browse the repository at this point in the history
  • Loading branch information
kishanprmr authored Jan 2, 2025
2 parents 5fb4bc4 + 9aa4bc2 commit 695bf40
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,15 @@
"contributions": [
"plugin"
]
},
{
"login": "AshotZaqoyan",
"name": "Ashot",
"avatar_url": "https://avatars.githubusercontent.com/u/72438085?v=4",
"profile": "https://codesign.rf.gd",
"contributions": [
"plugin"
]
}
],
"commitType": "docs"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ Not into coding but still interested in contributing? Come join our [Discord](ht
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ChineseHamberger"><img src="https://avatars.githubusercontent.com/u/101547635?v=4?s=100" width="100px;" alt="张晟杰"/><br /><sub><b>张晟杰</b></sub></a><br /><a href="#plugin-ChineseHamberger" title="Plugin/utility libraries">🔌</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://codesign.rf.gd"><img src="https://avatars.githubusercontent.com/u/72438085?v=4?s=100" width="100px;" alt="Ashot"/><br /><sub><b>Ashot</b></sub></a><br /><a href="#plugin-AshotZaqoyan" title="Plugin/utility libraries">🔌</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion packages/pieces/community/discord/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-discord",
"version": "0.3.12"
"version": "0.3.13"
}
5 changes: 3 additions & 2 deletions packages/pieces/community/discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { discordCreateChannel } from './lib/actions/create-channel';
import { discordDeleteChannel } from './lib/actions/delete-channel';
import { discordSendApprovalMessage } from './lib/actions/send-approval-message';
import { discordSendMessageWebhook } from './lib/actions/send-message-webhook';
import { newMessage } from './lib/trigger/new-message';
import { newMessage } from './lib/triggers/new-message';
import { discordRemoveBanFromUser } from './lib/actions/remove-ban-from-user';
import { discordCreateGuildRole } from './lib/actions/create-guild-role';
import { discordDeleteGuildRole } from './lib/actions/delete-guild-role';
import { discordBanGuildMember } from './lib/actions/ban-a-guild-member';
import { newMember } from './lib/triggers/new-member';

const markdown = `
To obtain a token, follow these steps:
Expand Down Expand Up @@ -77,5 +78,5 @@ export const discord = createPiece({
'abuaboud',
'tintinthedev',
],
triggers: [newMessage],
triggers: [newMessage, newMember],
});
114 changes: 114 additions & 0 deletions packages/pieces/community/discord/src/lib/triggers/new-member.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import {
DedupeStrategy,
HttpMethod,
HttpRequest,
Polling,
httpClient,
pollingHelper,
} from '@activepieces/pieces-common';
import {
createTrigger,
Property,
TriggerStrategy,
} from '@activepieces/pieces-framework';
import dayjs from 'dayjs';
import { discordAuth } from '../..';
import { discordCommon } from '../common';

interface Member {
user: {
id: string;
username: string;
discriminator: string;
avatar: string | null;
};
joined_at: string;
}

const polling: Polling<string, { guildId: string | undefined; limit: number }> =
{
strategy: DedupeStrategy.TIMEBASED,
items: async ({ auth, propsValue: { guildId, limit } }) => {
if (!guildId) return [];

const request: HttpRequest = {
method: HttpMethod.GET,
url: `https://discord.com/api/v9/guilds/${guildId}/members?limit=${limit}`,
headers: {
Authorization: 'Bot ' + auth,
},
};

const res = await httpClient.sendRequest<Member[]>(request);

const items = res.body;
return items.map((item) => ({
epochMilliSeconds: dayjs(item.joined_at).valueOf(),
data: item,
}));
},
};

export const newMember = createTrigger({
auth: discordAuth,
name: 'new_member',
displayName: 'New Member',
description: 'Triggers when a new member joins a guild',
type: TriggerStrategy.POLLING,
props: {
limit: Property.Number({
displayName: 'Limit',
description: 'The number of members to fetch (max 1000)',
required: false,
defaultValue: 50,
}),
guildId: Property.ShortText({
displayName: 'Guild ID',
description: 'The ID of the Discord guild (server)',
required: true,
}),
},
sampleData: {},
onEnable: async (context) => {
await pollingHelper.onEnable(polling, {
auth: context.auth,
store: context.store,
propsValue: {
guildId: context.propsValue.guildId,
limit: context.propsValue.limit ?? 50,
},
});
},
onDisable: async (context) => {
await pollingHelper.onDisable(polling, {
auth: context.auth,
store: context.store,
propsValue: {
guildId: context.propsValue.guildId,
limit: context.propsValue.limit ?? 50,
},
});
},
run: async (context) => {
return await pollingHelper.poll(polling, {
auth: context.auth,
store: context.store,
propsValue: {
guildId: context.propsValue.guildId,
limit: context.propsValue.limit ?? 50,
},
files: context.files,
});
},
test: async (context) => {
return await pollingHelper.test(polling, {
auth: context.auth,
store: context.store,
propsValue: {
guildId: context.propsValue.guildId,
limit: context.propsValue.limit ?? 50,
},
files: context.files,
});
},
});

0 comments on commit 695bf40

Please sign in to comment.