How to do shoutouts with @ in front of the user
Background Story
Many streamers and moderators have set up a simple way to do shoutouts to announce important people in their streams. The issue that I always see is that when someone does a shoutout like this !shoutout @unarmedguitar
you get something like Please give a big shoutout to @unarmedguitar. Be sure to follow them at https://twitch.tv/@unarmedguitar
Notice how that @ appears in front of my username and the link also has @ infront of it. Now you could get this result or you may get Unknown User. Either way, you should be able to use @ in front of the user and it should not affect your shoutout command.
The reason you want to use this @ reference for a user is because you can take advantage of autocomplete, which will allow you to easily complete the user you are shouting out without making any mistakes with their name. That is another common issue you can have when trying to type someones name.
The code
This is a simple command I have created to address this issue. This code is not heavily tested and is by no means perfect but it does the job. This command uses add to add a new command, if you have already set up a shoutout command you would use edit instead. You may also need to change !so to your command you set up for shoutout, for example: !shoutout
!commands add !so -ul=moderator $(twitch $(eval "$(touser)".replace("@", "")) "Please give a big shoutout to {{displayName}}. Be sure to follow them at {{url}}")
Before I explain what this code does, I will show you how to test it and what it should output so you can compare the results.
!so @unarmedguitar
or you could do
!so unarmedguitar
either method is fine and this is to help those who are already accustomed to not using @ for the username.
Here is the result
Nightbot: Please give a big shoutout to unarmedguitar. Be sure to follow them at https://twitch.tv/unarmedguitar
Now this is exactly what you want to happen.
Code Explanation
Letâs get some links for pieces that will help you, so I can just explain what my command does:
Nightbot Docs - commands
Nightbot Docs - Variables - twitch
Nightbot Docs - Variables - eval
Nightbot Docs - Variables - touser
EMCAScript/Javascript - String - replace
Now that the documentation is out of the way, letâs explain the code.
$(twitch $(eval "$(touser)".replace("@", "")) "Please give a big shoutout to {{displayName}}. Be sure to follow them at {{url}}")
So first letâs fill in this with the shoutout command !so @unarmedguitar
$(eval "@unarmedguitar".replace("@", ""))
results into unarmedguitar
$(twitch unarmedguitar "Please give a big shoutout to {{displayName}}. Be sure to follow them at {{url}}")
results into Please give a big shoutout to unarmedguitar. Be sure to follow them at https://twitch.tv/unarmedguitar
And that is what you would expect.
Now this is not foolproof code, it can be broken, but since only moderators and above userlevels can use this code, you should trust that they will not attempt to break the code. If however, you do have issues then you should read what RokettoJanpu has added.
If anyone has anymore tips, hints, hacks or workarounds for Nightbot then I would like to hear them. Be nice to see other methods or annoyances that people have encountered.
Thank you