Nightbot doesn’t naturally keep track of how many times a command has been used by a particular user. You’ll have to set up a command that makes Nightbot send and retrieve information from an external script. One such external script we can use to store information outside Nightbot is ehsan’s quote list custom API.
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’ve set up 4 commands below: !valentine and !valentinep2 which work in tandem to increase the valentine counter of the command user, !valentinecount which shows how many valentines the command user has sent, and !valentinereset which clears every user’s counter (mod-only). Copy and paste the following command setups into chat. Do this only if you are sure no one else is in chat, otherwise they might see your private token which is used to manage the valentine counters. Replace PUBLIC_TOKEN with your public token and PRIVATE_TOKEN with your private token:
!addcom -cd=5 !valentine -a=!valentinep2 $(eval a=decodeURIComponent(`$(querystring)`);a?`PRIVATE_TOKEN&data=-${decodeURIComponent(`$(user)`)}- $$$${a}`:` `)
!addcom -cd=5 !valentinep2 $(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(1))`;a=`$(query)`.split(`$$$`);a[0].includes(`PRIVATE_TOKEN`)?`$(user) has sent ${a[1]} a valentine! <3`:`Please specify a user to send a valentine to!`)
!addcom -cd=5 !valentinecount $(eval a=decodeURIComponent(`$(querystring $(touser))`);b=new RegExp(`-`+a+`-`,`gi`);c=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN)`.match(b);c!=null?`${a} has gifted a total of ${c.length} valentines!`:`${a} has yet to gift a valentine...`)
!addcom -ul=mod !valentinereset $(eval a=`$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&clear=1)`;`$(user) has reset the valentine counter!`)
Command usages:
!valentine [user you want to send a valentine to]
!valentinecount [username you want to search]
!valentinereset