We start by adding the event to listen for all Twitch chat messages.
As we want only the messages that start with !command we use this as the criteria for the event. Of course the !command is just an example and could be changed to whatever command indicator you like to use.
In this step we assume the command has this structure !command user. In step 1 we captured the !command and now we want the user part of the message. For this we are going to use the Calculate with Value action:
First you need to create a new Value in which you will temporary store the result of our manipulation. In this case we created a Value called Value 1.
This action stores the result of the calculation set, which in this case is the message ( '${twitch-chat0}' is the code holding the last send Twitch Message) from Twitch and then subtracts the text !command from it.
From this moment the Value 1 will hold the full message with the command part removed. In our case this will be just the user component. We can now use the Value 1 in our other actions to work with. A simple example:
In this simple example we just reply in the chat with a thank you to the user that was specified in the !command chat message. So !command John would result in a message send to Twitch like Thank you John!
In this step we are going to take it to the next level. Sometimes a simple command structure will just not cut it and you want more. In this part we are going to use the powerfull Replace in Value action.
The Replace in Value action is able to use regex to replace parts of the given Value. We are going to use this to store the arguments into a value and then strip everything except the n-th argument. The result is that we can use the n-th argument from the Twitch chat message. Lets work with an example like this: !shoutout John Doe.
We want to do a formal shoutout which means that we will do a shout out to the give persons surname. In this case we want to send to the Twitch chat Follow Mr. Doe!.
Our approach with the simple structure will not work anymore as we have some unknowns which we cannot remove beforehand. This is where we are going to use the regex functionality of the Replace in Value action to remove everything except the n-th word in that Value. So in our case we want the 3rd word, which is Doe.
See the action flow in the image below to select the 3rd word. If you need a different word for your own personal situation then just change the 2 into the number you require.
Just so you do not have to type it from the image here the regex:
You are now able to parse commands send to you from Twitch and use simple and complex structures and use them to enhance the experience for your users.