diff --git a/src/nodes/ts3-get/handleGet.ts b/src/nodes/ts3-get/handleGet.ts deleted file mode 100644 index e338841..0000000 --- a/src/nodes/ts3-get/handleGet.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { TeamSpeak } from "ts3-nodejs-library"; - -export default function handleGet(func: string, client: TeamSpeak, options: any): Promise{ - const member: any = client[func as keyof TeamSpeak] - - if (typeof member === "function"){ - let rtn; - - if (options instanceof Array){ - rtn = member(...options) - }else{ - rtn = member(options) - } - - if (rtn instanceof Promise){ - return rtn - }else{ - return rtn - } - }else{ - throw new Error(`"${func}" is not a valid function name`); - } -} \ No newline at end of file diff --git a/src/nodes/ts3-get/ts3-get.ts b/src/nodes/ts3-get/ts3-get.ts index 755c589..08456cc 100644 --- a/src/nodes/ts3-get/ts3-get.ts +++ b/src/nodes/ts3-get/ts3-get.ts @@ -1,6 +1,6 @@ import { NodeInitializer } from "node-red"; +import { TeamSpeak } from "ts3-nodejs-library"; import { Ts3ConfigNode } from "../ts3-config/types"; -import handleGet from "./handleGet"; import { Ts3GetConfig, Ts3GetNode } from "./types"; const nodeInit: NodeInitializer = (RED): void => { @@ -28,12 +28,22 @@ const nodeInit: NodeInitializer = (RED): void => { this.on("input", async (msg,send,done) => { const client = await ts3Config.getConnection() - let payload = await handleGet(config.selection,client,msg.payload) - //let payload = await client.whoami() + const member: any = client[config.selection as keyof TeamSpeak] + if (typeof member === "function"){ + let args: any[] = [] - msg.payload = payload + if (msg.payload instanceof Array){ + args = msg.payload + }else{ + args = [msg.payload] + } + msg.payload = await member.apply(client,args) + + send(msg) + }else{ + this.error(`Failed to call ${config.selection}. Not a function`) + } - send(msg) done() }) }