From c6306eecc11f012a082edbae6054f1df37a5aa6c Mon Sep 17 00:00:00 2001 From: lior <diler.lior@gmail.com> Date: Sat, 30 Jul 2022 22:13:32 +0200 Subject: [PATCH] add no options verification for all commands --- src/commandExecutor.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/commandExecutor.js b/src/commandExecutor.js index 26ca6a6..d15ea49 100644 --- a/src/commandExecutor.js +++ b/src/commandExecutor.js @@ -44,6 +44,12 @@ async function VerifyAndExecuteGetAllMembers(data, userMediaID) const templateOptions = commandHelper.getGroupIDsWithCondition(userDatabase.connectedGroups, groups, true); + if(templateOptions.length === 0) + { + data.text = "You are not connected to any groups yet. please use the !connecttogroup command first."; + return data; + } + return await commandHelper.executeCommandOnGroup(data.message, getAllMembers, { "type":"talkToGroup", @@ -70,6 +76,12 @@ async function VerifyAndExecuteDisconnectFromGroup(data, userMediaID) const templateOptions = commandHelper.getGroupIDsWithCondition(userDatabase.connectedGroups, groups, true); + if(templateOptions.length === 0) + { + data.text = "You are not connected to any groups."; + return data; + } + return await commandHelper.executeCommandOnGroup(data.message, ExecuteDisconnectFromGroup,{ "type":"talkToGroup", "command":"DI", @@ -198,6 +210,12 @@ async function VerifyAndExecuteOpenSessionToMember(data, userDatabase, userMedia } } + if(templateOptions.length === 0) + { + data.text = "No other user is currently connected to the group " + targetGroup.groupName + "."; + return data; + } + return await commandHelper.executeCommandOnGroupMember(data.message, ExecuteOpenSessionToMember, { "type":"talkToGroup", @@ -212,6 +230,12 @@ async function VerifyAndExecuteOpenSessionToGroup(data, userDatabase, userMediaI const templateOptions = commandHelper.getGroupIDsWithCondition(userDatabase.connectedGroups, groups, true); + if(templateOptions.length === 0) + { + data.text = "You are currently not connected to a group. Please connect to a group with the command !connectToGroup first."; + return data; + } + return await commandHelper.executeCommandOnGroup(data.message, ExecuteOpenSessionToGroup, { "type":"talkToGroup", "command":"SE", @@ -312,6 +336,11 @@ async function VerifyAndExecuteGetConnectedMembers(data, userMediaID) const templateOptions = commandHelper.getGroupIDsWithCondition(userDatabase.connectedGroups, groups, true); + if(templateOptions.length === 0) + { + data.text = "You are not connected to any groups yet. please use the !connecttogroup command first"; + return data; + } return await commandHelper.executeCommandOnGroup(data.message,ExecuteGetConnectedMembers, { "type":"talkToGroup", -- GitLab