User Command Cooldowns

Cooldowns are per command instead of per user. This means that, if someone uses a command with a 30-second cooldown, that command can not be used by anyone for the next 30 seconds (excluding moderators and above). However, creating commands with cooldowns that work on a per-user basis is possible with the use of Ehsan’s quote system.


Click this link. It will generate three links and two tokens, a public token (8 characters long) and a private token (16 characters long). The public token is located within the first generated link. The private token is located within both the second and third generated links. The tokens are found after token= and before &data=$(querystring) Copy them down and keep them somewhere safe!

I have set up 2 commands below, !command and _!command_helper which work in tandem to output a response depending on whether the user has already recently used the command (only !command is meant to be used directly). Copy and paste the command setups into chat one by one to add the commands, but read the next set of instructions further below before you actually add the commands.

!addcom -cd=5 !command -a=_!command_helper $(eval z=COOLDOWN;d=Date.parse(Date());a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN)`.match(/~$(user)~\d+~/g);`PRIVATE_TOKEN`+(!a||d-parseInt(a[a.length-1].split(`~`)[2])>=z*1000?`&data=~$(user)~${d}~`:``))

!addcom -cd=5 _!command_helper $(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`;decodeURIComponent(`$(querystring)`).includes(`PRIVATE_TOKEN`)?(a.includes(`Successfully added entry`)?`MESSAGE`:`FALLBACK_MESSAGE`):` `)

Further instructions for adding the commands

Feel free to rename !command to whatever command name you want, but do not rename _!command_helper

Locate the following words within the command responses and replace them as instructed below:

COOLDOWN => your desired per-user cooldown in seconds; for example, change this to 86400 for a one-day cooldown
PUBLIC_TOKEN => your public token
PRIVATE_TOKEN => your private token
MESSAGE => what you want Nightbot to respond with
FALLBACK_MESSAGE => what you want Nightbot to respond with if the user has not waited out the cooldown

EDIT 7/9/20: !command is aliased to _!command_helper and is passing information to _!command_helper, specifically your private token and the UTC timestamp at which you used the command, both things that _!command_helper needs to work properly but no one in chat exactly needs to see. Do not use any of the following variables in your message texts: $(touser), $(query), $(querystring)

3 Likes

hello, so i had a question. im using this in conjunction with the !catch pokemon command for nightbot. when im using the command as written above (with correct tokens and messages etc) it shows the users tokens in chat on either side of their name. any idea on how to not have those shown in the response? ill post my commands as well as what is shown by nightbot when the command is executed. any help would be greatly appreciated as i dont know enough about how to change the code without messing it all up.

Pokemon

@ShreddingMonkey

The commands work exactly as they should. However, !command is aliased to _!command_helper and is passing information to _!command_helper, specifically your private token and the UTC timestamp at which you used the command, both things that _!command_helper needs to work properly but no one in chat exactly needs to see. An input variable like $(touser) contains exactly this info, and an easy fix is to replace it with $(user).

2 Likes

I’m working on something somewhat similar to this and I know I’ll need an API to do it. I’m working on a command that can be used by one person and has a cooldown of the entire stream. It basically will display the first persons username to use the command that stream and say “($user)! was first” so it displays who got to stream first. So do you think it would be possible to implement this kind of idea but for everyone instead of just one person?

Hi. I’m a newbie mod. Does this apply to simple commands such as a hug command?

Something like this:
!commands add !hug /me $(user) just gave a big bear hug to $(touser) <3 VirtualHug HarleyWink MercyWing1 PinkMercy MercyWing2

And should I create a new thread for this? I already have the commands added on my end mentioned on this post. I’m a bit lost on where to continue from this point. Doing tests on my channel btw. Will be applying everything to a friend’s channel.

Trying to add a custom cooldown for the said command.

Hey @Scribbles!

Yes, you can apply that to your hug command, but remember that there’s also a command cooldown built-in with Nightbot, if your goal is to reduce this command’s spam I’d recommend using it instead, user-specific cooldowns seem a bit overpowered for a hug command.


To adapt the user cooldowns to you command you’ll need to modify the code a bit, this should work:

!addcom -cd=5 !hug -a=_hug $(eval z=COOLDOWN;d=Date.parse(Date());a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN)`.match(/~$(user)~\d+~/g);`PRIVATE_TOKEN`+(!a||d-parseInt(a[a.length-1].split(`~`)[2])>=z*1000?`&data=~$(user)~${d}~ $(touser)`:``))

!addcom -cd=5 _hug $(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`;decodeURIComponent(`$(querystring)`).includes(`PRIVATE_TOKEN`)?(a.includes(`Successfully added entry`)?`/me $(user) just gave a big bear hug to ${'$(query)'.split(' ')[1]} <3 VirtualHug HarleyWink MercyWing1 PinkMercy MercyWing2`:`$(user), your cooldown hasn't ended yet`):` `)

hi there!

is it possible to use with this command? or is there a way to do it using pastebin?

$(eval a=parseInt(decodeURIComponent($(querystring)));b=a&&a>=1?a:10;c=Math.floor(Math.random()*b)+1;(c==9999 && b==10000)?¡felicidades $(user)! ¡sacaste ${c} de ${b}! ¡¡¡TENEMOS GANADOOOOOORRRR!!! @franzeq PAGA PVTO!:(b==10000?$(user) sacó ${c} de ${b}, sigue intentando!:$(user) sacó ${c} de ${b}))

sorry if its a dumb question, i am newbie at this, thanks in advance!