[PCCompat > Commands] Only destructure if not empty object (no args given)

This commit is contained in:
Ducko 2021-06-08 16:46:56 +01:00 committed by Alyxia Sother
parent 9bcf6d59f8
commit 0d68aa88c2
No known key found for this signature in database
GPG Key ID: 355968D14144B739
1 changed files with 10 additions and 2 deletions

View File

@ -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