forked from activepieces/activepieces
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'activepieces:main' into hubspot
- Loading branch information
Showing
6 changed files
with
128 additions
and
3 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
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
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" | ||
} |
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
114 changes: 114 additions & 0 deletions
114
packages/pieces/community/discord/src/lib/triggers/new-member.ts
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,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, | ||
}); | ||
}, | ||
}); |
File renamed without changes.