Skip to content

Commit

Permalink
Merge pull request #4455 from activepieces/discord
Browse files Browse the repository at this point in the history
chore: merge all discord actions into single pr
  • Loading branch information
abuaboud committed Apr 13, 2024
2 parents 30e9a54 + 2780c2f commit 7af0d84
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 3 deletions.
4 changes: 2 additions & 2 deletions 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.10"
}
"version": "0.3.11"
}
21 changes: 20 additions & 1 deletion packages/pieces/community/discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ 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 { 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';

const markdown = `
To obtain a token, follow these steps:
Expand Down Expand Up @@ -45,6 +49,10 @@ export const discord = createPiece({
discordCreateChannel,
discordDeleteChannel,
discordFindChannel,
discordRemoveBanFromUser,
discordCreateGuildRole,
discordDeleteGuildRole,
discordBanGuildMember,
createCustomApiCallAction({
baseUrl: () => {
return 'https://discord.com/api/v9';
Expand All @@ -56,6 +64,17 @@ export const discord = createPiece({
},
}),
],
authors: ["creed983","TaskMagicKyle","karimkhaleel","Abdallah-Alwarawreh","kishanprmr","MoShizzle","AbdulTheActivePiecer","khaledmashaly","abuaboud"],
authors: [
'creed983',
'TaskMagicKyle',
'karimkhaleel',
'Abdallah-Alwarawreh',
'kishanprmr',
'MoShizzle',
'AbdulTheActivePiecer',
'khaledmashaly',
'abuaboud',
'tintinthedev',
],
triggers: [newMessage],
});
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,
};
},
});
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,
},
};
},
});
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,
};
},
});
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,
};
},
});

0 comments on commit 7af0d84

Please sign in to comment.