From 148e48247e8ae40f485340333ee39980fc1cc346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 10 Mar 2021 20:00:32 -0300 Subject: [PATCH] :zap: Add generic functions stub --- .../nodes/Discord/GenericFunctions.ts | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/packages/nodes-base/nodes/Discord/GenericFunctions.ts b/packages/nodes-base/nodes/Discord/GenericFunctions.ts index 97ca9b1cd3..2a395c0311 100644 --- a/packages/nodes-base/nodes/Discord/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Discord/GenericFunctions.ts @@ -12,16 +12,12 @@ import { IDataObject, } from 'n8n-workflow'; -import WebSocket = require('ws'); - export async function discordApiRequest( this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions, method: string, resource: string, body: IDataObject = {}, qs: IDataObject = {}, - uri?: string, - option: IDataObject = {}, ) { const { oauthTokenData } = this.getCredentials('discordOAuth2Api') as { @@ -31,50 +27,35 @@ export async function discordApiRequest( const options: OptionsWithUri = { headers: { 'Content-Type': 'application/json', + 'user-agent': 'n8n', Authorization: `Bearer ${oauthTokenData.access_token}`, }, method, body, qs, - uri: uri || `https://discord.com/api${resource}`, + uri: `https://discord.com/api${resource}`, json: true, }; - if (Object.keys(option).length) { - Object.assign(options, option); + if (!Object.keys(body).length) { + delete options.body; } if (!Object.keys(qs).length) { delete options.qs; } - if (!Object.keys(body).length) { - delete options.body; - } - const oAuth2Options = { includeCredentialsOnRefreshOnBody: true, }; try { - // console.log(options); + console.log(options); return await this.helpers.requestOAuth2!.call(this, 'discordOAuth2Api', options, oAuth2Options); - // return await this.helpers.request!.call(this, options); } catch (error) { - // TODO + // TODO: Prettify error throw error; } } - -export function setHeartbeatInterval(ws: WebSocket, data: string) { - const interval = JSON.parse(data).d.heartbeat_interval; - - const payload = JSON.stringify({ - op: 1, // opcode - d: 251, // last sequence number `s` received by client - }); - - return setInterval(() => ws.send(payload), interval); -}