-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4455 from activepieces/discord
chore: merge all discord actions into single pr
- Loading branch information
Showing
6 changed files
with
231 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"name": "@activepieces/piece-discord", | ||
"version": "0.3.10" | ||
} | ||
"version": "0.3.11" | ||
} |
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
49 changes: 49 additions & 0 deletions
49
packages/pieces/community/discord/src/lib/actions/ban-a-guild-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,49 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { | ||
HttpRequest, | ||
HttpMethod, | ||
httpClient, | ||
} from '@activepieces/pieces-common'; | ||
import { discordAuth } from '../../index'; | ||
import { discordCommon } from '../common'; | ||
|
||
export const discordBanGuildMember = createAction({ | ||
auth: discordAuth, | ||
name: 'ban_guild_member', | ||
description: 'Bans a guild member', | ||
displayName: 'Ban guild member', | ||
props: { | ||
guild_id: discordCommon.guilds, | ||
user_id: Property.ShortText({ | ||
displayName: 'User ID', | ||
description: 'The user id of the member', | ||
required: true, | ||
}), | ||
ban_reason: Property.ShortText({ | ||
displayName: 'Ban Reason', | ||
description: 'The reason for banning the member', | ||
required: false, | ||
}), | ||
}, | ||
|
||
async run(configValue) { | ||
const request: HttpRequest<any> = { | ||
method: HttpMethod.PUT, | ||
url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/bans/${configValue.propsValue.user_id}`, | ||
headers: { | ||
authorization: `Bot ${configValue.auth}`, | ||
'Content-Type': 'application/json', | ||
'X-Audit-Log-Reason': `${configValue.propsValue.ban_reason}`, | ||
}, | ||
body: { | ||
reason: `${configValue.propsValue.ban_reason}`, | ||
}, | ||
}; | ||
|
||
const res = await httpClient.sendRequest<never>(request); | ||
|
||
return { | ||
success: res.status === 204, | ||
}; | ||
}, | ||
}); |
71 changes: 71 additions & 0 deletions
71
packages/pieces/community/discord/src/lib/actions/create-guild-role.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,71 @@ | ||
import { | ||
HttpMethod, | ||
HttpRequest, | ||
httpClient, | ||
} from '@activepieces/pieces-common'; | ||
import { discordAuth } from '../../index'; | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { discordCommon } from '../common'; | ||
|
||
export const discordCreateGuildRole = createAction({ | ||
auth: discordAuth, | ||
name: 'createGuildRole', | ||
displayName: 'Create guild role', | ||
description: 'Creates a new role on the specified guild', | ||
props: { | ||
guild_id: discordCommon.guilds, | ||
role_name: Property.ShortText({ | ||
displayName: 'Role Name', | ||
description: 'The name of the role', | ||
required: true, | ||
}), | ||
role_color: Property.ShortText({ | ||
displayName: 'Role Color', | ||
description: `The RGB color of the role (may be better to set manually on the server)`, | ||
required: false, | ||
}), | ||
display_separated: Property.Checkbox({ | ||
displayName: 'Display Separated', | ||
description: | ||
'Whether the role should be displayed separately in the sidebar', | ||
required: false, | ||
}), | ||
role_mentionable: Property.Checkbox({ | ||
displayName: 'Mentionable', | ||
description: 'Whether the role can be mentioned by other users', | ||
required: false, | ||
}), | ||
creation_reason: Property.ShortText({ | ||
displayName: 'Creation Reason', | ||
description: 'The reason for creating the role', | ||
required: false, | ||
}), | ||
}, | ||
async run(configValue) { | ||
const request: HttpRequest = { | ||
url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/roles`, | ||
method: HttpMethod.POST, | ||
headers: { | ||
authorization: `Bot ${configValue.auth}`, | ||
'Content-Type': 'application/json', | ||
'X-Audit-Log-Reason': `${configValue.propsValue.creation_reason}`, | ||
}, | ||
body: { | ||
name: configValue.propsValue.role_name, | ||
color: configValue.propsValue.role_color, | ||
hoist: configValue.propsValue.display_separated, | ||
mentionable: configValue.propsValue.role_mentionable, | ||
}, | ||
}; | ||
|
||
const res = await httpClient.sendRequest(request); | ||
|
||
return { | ||
success: res.status === 201, | ||
role: { | ||
id: res.body.id, | ||
name: res.body.name, | ||
}, | ||
}; | ||
}, | ||
}); |
41 changes: 41 additions & 0 deletions
41
packages/pieces/community/discord/src/lib/actions/delete-guild-role.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,41 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { discordCommon } from '../common'; | ||
import { discordAuth } from '../../index'; | ||
import { | ||
httpClient, | ||
HttpMethod, | ||
HttpRequest, | ||
} from '@activepieces/pieces-common'; | ||
|
||
export const discordDeleteGuildRole = createAction({ | ||
auth: discordAuth, | ||
name: 'deleteGuildRole', | ||
displayName: 'Delete guild role', | ||
description: 'Deletes the specified role from the specified guild', | ||
props: { | ||
guild_id: discordCommon.guilds, | ||
role_id: discordCommon.roles, | ||
deletion_reason: Property.ShortText({ | ||
displayName: 'Deletion reason', | ||
description: 'The reason for deleting the role', | ||
required: false, | ||
}), | ||
}, | ||
async run(configValue) { | ||
const request: HttpRequest = { | ||
url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/roles/${configValue.propsValue.role_id}`, | ||
method: HttpMethod.DELETE, | ||
headers: { | ||
Authorization: `Bot ${configValue.auth}`, | ||
'Content-Type': 'application/json', | ||
'X-Audit-Log-Reason': `${configValue.propsValue.deletion_reason}`, | ||
}, | ||
}; | ||
|
||
const res = await httpClient.sendRequest(request); | ||
|
||
return { | ||
success: res.status === 204, | ||
}; | ||
}, | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/pieces/community/discord/src/lib/actions/remove-ban-from-user.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,48 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { discordCommon } from '../common'; | ||
import { discordAuth } from '../../index'; | ||
import { | ||
httpClient, | ||
HttpMethod, | ||
HttpRequest, | ||
} from '@activepieces/pieces-common'; | ||
|
||
export const discordRemoveBanFromUser = createAction({ | ||
auth: discordAuth, | ||
name: 'remove_ban_from_user', | ||
displayName: 'Remove ban from user', | ||
description: 'Removes the guild ban from a user', | ||
props: { | ||
guild_id: discordCommon.guilds, | ||
user_id: Property.ShortText({ | ||
displayName: 'User ID', | ||
description: 'The ID of the user', | ||
required: true, | ||
}), | ||
unban_reason: Property.ShortText({ | ||
displayName: 'Unban Reason', | ||
description: 'The reason for unbanning the user', | ||
required: false, | ||
}), | ||
}, | ||
async run(configValue) { | ||
const request: HttpRequest<any> = { | ||
method: HttpMethod.DELETE, | ||
url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/bans/${configValue.propsValue.user_id}`, | ||
headers: { | ||
authorization: `Bot ${configValue.auth}`, | ||
'Content-Type': 'application/json', | ||
'X-Audit-Log-Reason': `${configValue.propsValue.unban_reason}`, | ||
}, | ||
body: { | ||
reason: `${configValue.propsValue.unban_reason}`, | ||
}, | ||
}; | ||
|
||
const res = await httpClient.sendRequest<never>(request); | ||
|
||
return { | ||
success: res.status === 204, | ||
}; | ||
}, | ||
}); |