A counter for an individual

Hi, I successfully created a version of ceelo (the dice game) that works in nightbot. I am not very knowledgable with coding, but I successfully set it up so it gives you a random 3 rolls, and tells you your score. due to my lack of ability, it is then up to the players to play until someone wins. It is at this point that I hit a roadblock. I made a mod only command that allows someone to declare someone else a winner of the game, but I want a command that will track how many times someone has won when they use it. for example, someone would say “!wins @shanearchy” and it would say “shanearchy has won (x) games of dice!”. I’ve read through numerous threads but cannot figure out a way to do it currently. Any help would be appreciated.

I had hoped I could somehow make a command that used $(counter) to count how many times the !wins command was used with a specific $(touser) but no such luck so far, it only tracks the !wins command globally. (IE !commands add !wins $(eval var a=[“$(touser) has won $(counter)”]) games of ceelo!

Hey @shanearchy!

Yeah, the $(counter) variable is for the whole command, it can’t be user-specific, however, you can leverage existing tools to achieve what you’re looking for.


We’ll use the Quote API, get your tokens by following the Manual Installation link.
Refer to the following to identify your PUBLIC_TOKEN and PRIVATE_TOKEN:

$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&data=$(querystring))
$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(querystring))
$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&data=$(querystring))

Copy them and store them somewhere safe, never share your PRIVATE_TOKEN, anyone could then manage your list, that’s why the code I’ll write won’t contain command calls to add the new commands through the chat, add the new commands through the dashboard.


And here are the commands…
…for your mods:

  • !addwin:

    $(eval a = `$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(touser))`; '$(touser)|' + a;)
    

    :warning: Set this command’s userlevel to Moderator, and its alias to _addwin
    :beginner: Syntax: !addwin username

  • _addwin:

    $(eval q = `$(query)`.split('|'); l = `$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`; re = new RegExp(q[0], 'gi'); n = l.match(re).length; q[1].includes('Successfully') ? `${q[0]} has won ${n} games of ceelo!` : 'There was an error, try again.';)
    

    :warning: Set this command’s userlevel to Moderator
    :beginner: Don’t call this command, it’ll automatically be

…for everyone:

  • !wins:

    $(eval u = '$(touser)'; l = `$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`; re = new RegExp(u, 'gi'); n = l.match(re)?.length || 0; `${u} has won ${n} games of ceelo!`)
    

    :beginner: Syntax: !wins username_optional

And in case you want to reset the counters:

  • !resetwins

    $(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&clear=1)
    

    :warning: Set this command’s userlevel to Moderator
    :beginner: Syntax: !resetwins


This is an update to an older topic: Help with $(count) - #3 by Emily

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.