🔨 Added some things, removed others

This commit is contained in:
Tanay Pant 2021-02-04 09:59:20 +01:00
parent f27954d973
commit fbaa26a760
5 changed files with 123 additions and 109 deletions

View file

@ -5,6 +5,9 @@ import {
const scopes = [
'bot',
'connections',
'guilds',
'identify',
'webhook.incoming',
];

View file

@ -1,51 +0,0 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const channelOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'channel',
],
},
},
options: [
{
name: 'Get Channel',
value: 'getChannel',
description: 'Get a channel by ID',
},
],
default: 'getChannel',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const channelFields = [
/* -------------------------------------------------------------------------- */
/* channel:getChannel */
/* -------------------------------------------------------------------------- */
{
displayName: 'Channel ID',
name: 'channelId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'channel',
],
operation: [
'getChannel',
],
},
},
},
] as INodeProperties[];

View file

@ -16,9 +16,9 @@ import {
} from './GenericFunctions';
import {
channelFields,
channelOperations,
} from './ChannelDescription';
messageFields,
messageOperations,
} from './MessageDescription';
import {
userFields,
@ -52,10 +52,6 @@ export class Discord implements INodeType {
name: 'resource',
type: 'options',
options: [
{
name: 'Channel',
value: 'channel',
},
{
name: 'Message',
value: 'message',
@ -65,53 +61,15 @@ export class Discord implements INodeType {
value: 'user',
},
],
default: 'channel',
default: 'message',
description: 'Resource to consume.',
},
// Channel
...channelOperations,
...channelFields,
// Message
...messageOperations,
...messageFields,
// User
...userOperations,
...userFields,
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'message',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a message',
},
],
default: 'create',
description: 'The operation to perform.',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'message',
],
operation: [
'create',
],
},
},
},
],
};
@ -128,11 +86,16 @@ export class Discord implements INodeType {
if (resource === 'message') {
if (operation === 'create') {
const content = this.getNodeParameter('content', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const { oauthTokenData } = this.getCredentials('discordOAuth2Api') as IDataObject;
const { webhook: { url } } = oauthTokenData as { webhook: { url: string } };
const body: IDataObject = {
content,
};
Object.assign(body, additionalFields);
responseData = await discordApiRequest.call(this, 'POST', '', body, {}, url);
responseData = { success: true };
}
@ -141,12 +104,11 @@ export class Discord implements INodeType {
if (operation === 'getCurrentUser') {
responseData = await discordApiRequest.call(this, 'GET', `/users/@me`);
}
}
if (resource === 'channel') {
if (operation === 'getChannel') {
const channelId = this.getNodeParameter('channelId', i) as string;
responseData = await discordApiRequest.call(this, 'GET', `/channels/${channelId}`);
if (operation === 'getCurrentUserGuilds') {
responseData = await discordApiRequest.call(this, 'GET', `/users/@me/guilds`);
}
if (operation === 'getUserConnections') {
responseData = await discordApiRequest.call(this, 'GET', `/users/@me/connections`);
}
}
if (Array.isArray(responseData)) {

View file

@ -0,0 +1,91 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const messageOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'message',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a message',
},
],
default: 'create',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const messageFields = [
/* -------------------------------------------------------------------------- */
/* message:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'message',
],
operation: [
'create',
],
},
},
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
resource: [
'message',
],
operation: [
'create',
],
},
},
default: {},
options: [
{
displayName: 'Username',
name: 'username',
type: 'string',
default: '',
description: '',
},
{
displayName: 'Avatar URL',
name: 'avatar_url',
type: 'string',
default: '',
description: '',
},
{
displayName: 'TTS',
name: 'tts',
type: 'boolean',
default: false,
description: '',
},
],
},
] as INodeProperties[];

View file

@ -18,7 +18,17 @@ export const userOperations = [
{
name: 'Get Current User',
value: 'getCurrentUser',
description: 'Returns details of the requesters account',
description: 'Returns the user object of the requester\'s account.',
},
{
name: 'Get Current User Guilds',
value: 'getCurrentUserGuilds',
description: 'Returns a list of partial guild objects the current user is a member of.',
},
{
name: 'Get User Connections',
value: 'getUserConnections',
description: 'Returns a list of connection objects.',
},
],
default: 'getCurrentUser',
@ -29,8 +39,7 @@ export const userOperations = [
export const userFields = [
/* -------------------------------------------------------------------------- */
/* activity:create */
/* user:getUser */
/* -------------------------------------------------------------------------- */
] as INodeProperties[];