I creating vote system

Hey @Jackob!

It was hard to understand, but I think I get what you want.

First of all, let me redirect you towards a solution that is already existing with Nightbot: https://docs.nightbot.tv/commands/poll
I would personally recommend this solution.

Now if you want something custom, keep reading.
Have you read the first link I sent before? Please do.


This solution isn’t 100% accurate as not every vote entry will be taken in account because of Nightbot’s cooldown.

One way you could do this is by using the quote system API. You’ll get your TOKENS by clicking on the second link in the post, use these in the commands I wrote. To know where to look for your PUBLIC_TOKEN and PRIVATE_TOKEN, look at the field bellow:

$(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))

Keep your PRIVATE_TOKEN secret, don’t share it anywhere. To add a command containing your PRIVATE_TOKEN do it from the dashboard. Don’t use the chat as anyone could monitor it and copy the token, they could then edit your data.


Then the voting commands are:
1

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

2

$(eval z=`$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=b)`;` `)

3

$(eval z=`$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=c)`;` `)

For the result command (make sure it’s for mods+):
!pollresults (for Twitch)

$(eval q=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`;a=q.match(/a/g);b=q.match(/b/g);c=q.match(/c/g);a==null?a=0:a=a.length;b==null?b=0:b=b.length;c==null?c=0:c=c.length;t=a+b+c;`Poll results: 1 → ${Math.round(a*100/t)}% | 2 → ${Math.round(b*100/t)}% | 3 → ${Math.round(c*100/t)}%`)

But since you’re on YouTube we’ll have to use Pastebin to work around the characters limit:

!pollresults

$(eval q=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`;e=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`;eval(e);`1 → ${a}% | 2 → ${b}% | 3 → ${c}%`)

Create an account, then create a paste with no expiration date, and paste the following code in it:

a=q.match(/a/g);b=q.match(/b/g);c=q.match(/c/g);a==null?a=0:a=a.length;b==null?b=0:b=b.length;c==null?c=0:c=c.length;t=a+b+c;a=Math.round(a*100/t);b=Math.round(b*100/t);c=Math.round(c*100/t);

Then replace XXXXXXXX in the command by the paste ID in the URL.


And finally to reset the poll (to run before each new poll, make sure it’s for mods+):
!pollreset

$(eval z=`$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&clear=1)`;`Poll reset`)
1 Like