From 0d68aa88c269a69340e7e974f7ae43f8f9c4ff58 Mon Sep 17 00:00:00 2001 From: Oj Date: Tue, 8 Jun 2021 16:46:56 +0100 Subject: [PATCH] [PCCompat > Commands] Only destructure if not empty object (no args given) --- moduleWrappers/powercord/global/commands.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/moduleWrappers/powercord/global/commands.js b/moduleWrappers/powercord/global/commands.js index e87bbb6..70b5366 100644 --- a/moduleWrappers/powercord/global/commands.js +++ b/moduleWrappers/powercord/global/commands.js @@ -5,8 +5,16 @@ export const registerCommand = ({ command, alias, description, usage, executor } // TODO: implement alias goosemodScope.patcher.commands.add(command, description, - async ( { args: [ { text } ] } ) => { - const out = await executor(text.split(' ')); // Run original executor func (await incase it's an async function) + async (ret) => { + // Don't just destructure as using without text arguments returns empty object ({}) + + let textGiven = ''; + if (ret.args) { + const { args: [ { text } ] } = ret; + textGiven = text; + } + + const out = await executor(textGiven.split(' ')); // Run original executor func (await incase it's an async function) if (!out.send) { goosemodScope.patcher.internalMessage(out.result); // PC impl. sends internal message when out.send === false, so we also do the same via our previous Patcher API function