NightDev Community Forums

[CustomAPI] Quote system


#203

Everything seems to work but the quotes themselfs are not being added.
(i copy pasted them from your post not the lines u see in this quotation of your post)

test


#204

I’ve tested the commands, and they work. Make sure you are copying the commands exactly and replacing all FIRSTTOKEN AND SECONDTOKEN


#205

My Bad :slight_smile: i made a mistake. it works now :slight_smile:


#206

Yes :smiley: i would like that very much :slight_smile:


#207

This is what i have build right now.

I used one generated string to design a set of 12 quotes all named Empty.
And i used another generated string to make a !votelist command for users to know what can be voted for.
Wich i can change by using (this would be !changevote1 , changing both quote 1 and 7, there would be 6 identical commands for 2/8, 3/9, 4/10, 5/11, 6/12):

`$(urlfetch http://twitch.center/customapi/editquote?token=STRING&data=1 $(querystring))$(urlfetch http://twitch.center/customapi/editquote?token=STRING&data=7 $(querystring)) $(urlfetch http://twitch.center/customapi/editquote?token=STRING&data=1 Vote for $(querystring) with !vote1)`

Voting itself looks like this (this would be !vote1, there would be 6 identical commands for 2,3,4,5,6):

`$(urlfetch http://twitch.center/customapi/editquote?token=STRING&data=1%20$(urlfetch http://twitch.center/customapi/quote?token=STRING&data=7&no_id=1)%20-%20$(count)) $(urlfetch http://twitch.center/customapi/addquote?token=STRING&data=$(user) voted for Option 1)`

Wich adds a number behind quote 7 and Places that on quote 1.
It also registers on a AGAIN seperate generated string who voted for what.

I also made a Results command (wich is the reason i sticked with 6 options since it does not fit in the command line)

`$(urlfetch http://twitch.center/customapi/quote?token=STRING&data=1&no_id=1) ♦ $(urlfetch http://twitch.center/customapi/quote?token=STRING&data=2&no_id=1) ♦ $(urlfetch http://twitch.center/customapi/quote?token=STRING&data=3&no_id=1) ♦ $(urlfetch http://twitch.center/customapi/quote?token=STRING&data=4&no_id=1) ♦ $(urlfetch http://twitch.center/customapi/quote?token=STRING&data=5&no_id=1) ♦ $(urlfetch http://twitch.center/customapi/quote?token=STRING&data=6&no_id=1)`

The votelist command

`SUBSCRIBERS ONLY! To see what you can vote for check: twitch.center/customapi/quote/list?token=STRING&no_id=1`

So this system works kinda. But is a hassle to reset. You need to go to Nightbot and reset the counts once your removed something.
and this also allows users to vote 100000 times on one option wich is not ideal.
BUT AT LEAST I TRIED :joy:


#208

Go to https://twitch.center/customapi/quote/generate. You will see three lines. After token= on the first line, you will see your first token. After token= on the second and third lines, you will see your second token. Use these to replace FIRSTTOKEN and SECONDTOKEN before you add the following commands.

Users vote by typing !vote #, where # is a number between 1 and 6. If a user attempts to cast a second vote, their original vote will be removed. A moderator can change the title of the vote with !votetitle New Title Here or reset the vote to default with !votereset (also resets title). The results are displayed with !results.

!vote (alias to !voteadder)

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`);`$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`}catch(e){q={t:"Title",v:{1:[],2:[],3:[],4:[],5:[],6:[]}}}v=0;for(k in q.v){if(k==`$(query)`){v=k}for(u in q.v[k]){if(q.v[k][u]==`$(user)`){q.v[k].splice(u,1)}}}if(v){q.v[v].push(`$(user)`)}r="?token=SECONDTOKEN&data="+encodeURIComponent(JSON.stringify(q));if(v){r}else{r+"&novote,"+q.t})

!voteadder

$(eval if(`$(urlfetch http://twitch.center/customapi/addquote$(query))`.includes("Successfully added entry")){q=`$(query)`; if ((match = /&novote,(.+)$/.exec(`$(query)`)) != null){match[1] + `: Please enter a valid vote @$(user)`} else{`Your vote was added @$(user)`}}else{`Please use !vote @$(user)`})

!votetitle (alias to !votetitleadder and userlevel moderator)

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`);`$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`}catch(e){q={t:"Title",v:{1:[],2:[],3:[],4:[],5:[],6:[]}}}c=0;if(`$(query)`){q.t=`$(query)`;c=1}r="?token=SECONDTOKEN&data="+encodeURIComponent(JSON.stringify(q));if(!c){r+="&empty"}r)

!votetitleadder (userlevel moderator)

$(eval if (`$(urlfetch http://twitch.center/customapi/addquote$(query))`.includes("Successfully added entry")){if (`$(query)`.endsWith("&empty")){`Please enter a title @$(user)`} else{`The title has been changed @$(user)`}}else{`Please use !votetitle @$(user)`})

!votereset (userlevel moderator)

$(eval `$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`; `The votes have been reset @$(user)`)

!results

$(eval v=1; try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`)}catch(e){v=0} m=""; if (v){for (k in q.v){if (q.v[k].length>0){m+=" Option "+k+": "+q.v[k].length+" vote"+(q.v[k].length==1?"":"s")+","}}}if(m){"Results for "+q.t+": "+m.substr(0,m.length-1)}else{"No votes have been added"})


#209

Tested and worked! Awesome :stuck_out_tongue: the link u posted for generate had a 1 on the end tho. Is it very complex to add actual names to the options 1-6 (maybe more options)


#210

I don’t understand. Can you rephrase this?

You should be able to manually edit the default values {t:"Title",v:{1:[],2:[],3:[],4:[],5:[],6:[]}} in !votetitle (run this command immediately after !votereset to initialize the default values).

You can change it like this:

{t:"Title",v:{"Game Title 1":[],"Game Title 2":[],"Game Title 3":[],"Game Title 4":[],"Game Title 5":[],"Game Title 6":[]}}

The voters would have to enter the game titles exactly though. But that’s easily fixable if you only intend to use strings as voting options.

I could come up with a command to allow mods to enter the options if that needs to happen often.


#211

This is the link you posted:
https://twitch.center/customapi/quote/generate1
Should be:
https://twitch.center/customapi/quote/generate

the 1 on the end makes it fail

This would indeed happen often. So that command would be much apreciated :slight_smile: something like

!voteoption 1 <gamename>

#212

Ignore that, I accidentally copied the 1 that the forum software added to my previous message.


#213

Many of these have changed slightly so you should probably just replace them all. !voteoptions is called like this:

!voteoptions Option 1 | Option 2 | Option 3

!vote (alias to !voteadder)

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`);`$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`}catch(e){q={t:"Title",v:{"Option 1":[]}}}v=0;for(k in q.v)if(k.toUpperCase()==`$(query)`.toUpperCase())v=k;if(v){for(k in q.v)for(u in q.v[k])if(q.v[k][u]==`$(user)`)q.v[k].splice(u,1);q.v[v].push(`$(user)`)}r="?token=SECONDTOKEN&data="+encodeURIComponent(JSON.stringify(q));v?r:(r+"&n"+JSON.stringify(q)))

!voteadder

$(eval if(`$(urlfetch http://twitch.center/customapi/addquote$(query))`.includes("Successfully added entry")){if ((match = /&n(.+)$/.exec(`$(query)`)) != null){q=JSON.parse(match[1]); o=" OPTIONS:"; for (k in q.v){o+=" "+k + ","}q.t + o.substr(0, o.length-1) + ` @$(user)`} else{`Your vote was added @$(user)`}}else{`Please use !vote @$(user)`})

!votetitle (alias to !votetitleadder and userlevel moderator)

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`);`$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`}catch(e){q={v:{"Option 1":[]}}}c=0;if(`$(query)`){q.t=`$(query)`;c=1}r="?token=SECONDTOKEN&data="+encodeURIComponent(JSON.stringify(q));if(!c){r+="&empty"}r)

!votetitleadder (userlevel moderator)

$(eval if (`$(urlfetch http://twitch.center/customapi/addquote$(query))`.includes("Successfully added entry")){if (`$(query)`.endsWith("&empty")){`Please enter a title @$(user)`} else{`The title has been changed @$(user)`}}else{`Please use !votetitle @$(user)`})

!voteoptions (alias to !voteoptionsadder and userlevel moderator)

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`);`$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`}catch(e){q={t:"Title"}}c=0;if(`$(query)`){q.v={};o=`$(query)`.split(/\s*\|\s*/);for(i=0;i<o.length;i++){q.v[o[i]]=[]}c=1}r="?token=SECONDTOKEN&data="+encodeURIComponent(JSON.stringify(q));if(!c){r+="&empty"}r)

!voteoptionsadder (userlevel moderator)

$(eval if (`$(urlfetch http://twitch.center/customapi/addquote$(query))`.includes("Successfully added entry")){if (`$(query)`.endsWith("&empty")){`Please enter the vote options separated by | @$(user)`} else{`The vote options have been changed @$(user)`}}else{`Please use !voteoptions @$(user)`})

!votereset (userlevel moderator)

$(eval `$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`; `The votes have been reset @$(user)`)

!results

$(eval v=1; try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`)}catch(e){v=0} m=""; if (v){for (k in q.v){if (q.v[k].length>0){m+=" "+k+": "+q.v[k].length+" vote"+(q.v[k].length==1?"":"s")+","}}}if(m){q.t+" RESULTS:"+m.substr(0,m.length-1)}else{"No votes have been added"})

Be careful when adding !vote because it is exactly the character limit for a command.


#214

DUDE! it works perfectly!! :smiley: You cant use spaces in !voteoptions tho. so I need to do “Horizon-Zero-Dawn”. Is that normal? if so then no problem ill work with it! :smiley:

Im super happy that this works so wel!!!

You should definatly make a topic about this here so other can implement it too :stuck_out_tongue: Maybe generate an auto installer

Also just a side idea :stuck_out_tongue: is there a way to generate a string of the usernames who already voted? So i can check who still needs to vote incase i want to wait till all my subs have voted.


#215

Spaces work fine for me.


#216

Oh? ill try it out then. I might have done something wrong.


#217

!voted

$(eval m="";c=0;try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`); for (k in q.v){for (u in q.v[k]){m += q.v[k][u] + ", ";c++}}}catch(e){} if(m){m.substr(0,m.length-2) + (c==1?" has":" have") + " voted"}else{"Nobody has voted"})

#218

It seems to be removing the vote when somebody votes an unvalid entry.


#219

I think this was due to Nightbot loading the quote pages slowly sometimes. The old commands were removing then readding the vote quote to change it. So when one command attempted to read the votes before another command finished readding them, all the votes would be lost. I modified all the commands to use editquote so this shouldn’t be an issue anymore.

Go to https://twitch.center/customapi/quote/generate. You will see three lines. After token= on the first line, you will see your first token. After token= on the second and third lines, you will see your second token. Use these to replace FIRSTTOKEN and SECONDTOKEN before you add the following commands.

!vote (alias to !voteadder)

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`); v=0;for(k in q.v)if(k.toUpperCase()==`$(query)`.toUpperCase())v=k;if(v){for(k in q.v)for(u in q.v[k])if(q.v[k][u]==`$(user)`)q.v[k].splice(u,1);q.v[v].push(`$(user)`);"?token=SECONDTOKEN&data=1%20"+encodeURIComponent(JSON.stringify(q))}else{(`$(query)`?"?i":"?n")+JSON.stringify(q)}}catch(e){"?u"})

!voteadder

$(eval u=`$(query)`;if(`$(urlfetch http://twitch.center/customapi/editquote$(query))`=="Successfully modified entry #1"){`Your vote was added @$(user)`}else if(/^\?i.+$/.exec(u)!=null){`Invalid vote option @$(user)`}else if((m=/^\?n(.+)$/.exec(u))!=null){q=JSON.parse(m[1]);o=" OPTIONS: ";for(k in q.v){o+=k+", "}q.t+o.substr(0,o.length-2)+` @$(user)`}else if(u=="?u"){"A mod must type !votereset"}else if(u.startsWith("?token=")){"Failed to reach website"}else{`Please use !vote @$(user)`})

!votetitle (alias to !votetitleadder and userlevel moderator)

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`); if (`$(query)`){q.t=`$(query)`;"?token=SECONDTOKEN&data=1%20"+encodeURIComponent(JSON.stringify(q))}else{"?n"}}catch(e){"?u"})

!votetitleadder (userlevel moderator)

$(eval u=`$(query)`;if(`$(urlfetch http://twitch.center/customapi/editquote$(query))`=="Successfully modified entry #1"){`The vote title has been changed @$(user)`}else if(u=="?n"){`Please enter a title @$(user)`}else if(u=="?u"){"A mod must type !votereset"}else if(u.startsWith("?token=")){"Failed to reach website"}else{`Please use !votetitle @$(user)`})

!voteoptions (alias to !voteoptionsadder and userlevel moderator)

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`); if (`$(query)`){q.v={};o=`$(query)`.split(/\s*\|\s*/);for(i=0;i<o.length;i++){q.v[o[i]]=[]}"?token=SECONDTOKEN&data=1%20"+encodeURIComponent(JSON.stringify(q))}else{"?n"}}catch(e){"?u"})

!voteoptionsadder (userlevel moderator)

$(eval u=`$(query)`;if(`$(urlfetch http://twitch.center/customapi/editquote$(query))`=="Successfully modified entry #1"){`The vote options have been changed @$(user)`}else if(u=="?n"){`Please enter the vote options separated by | @$(user)`}else if(u=="?u"){"A mod must type !votereset"}else if(u.startsWith("?token=")){"Failed to reach website"}else{`Please use !voteoptions @$(user)`})

!votereset (userlevel moderator)

$(eval `$(urlfetch http://twitch.center/customapi/delquote?token=SECONDTOKEN&clear=1)`; `$(urlfetch http://twitch.center/customapi/addquote?token=SECONDTOKEN&data=$(querystring {"t":"Title","v":{"Option 1":[]}}))`; `The votes have been reset @$(user)`)

!results

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`); m="";for (k in q.v){if (q.v[k].length>0){m+=" "+k+": "+q.v[k].length+" vote"+(q.v[k].length==1?"":"s")+","}} if(m){q.t+" RESULTS:"+m.substr(0,m.length-1)}else{"No votes have been added"}}catch(e){"A mod must type !votereset"})

!voted

$(eval try{q=JSON.parse(`$(urlfetch http://twitch.center/customapi/quote/list?token=FIRSTTOKEN&no_id=1)`); m="";c=0;for (k in q.v){for (u in q.v[k]){m += q.v[k][u] + ", ";c++}}if(m){m.substr(0,m.length-2) + (c==1?" has":" have") + " voted"}else{"Nobody has voted"}}catch(e){"A mod must type !votereset"})

#220

I wasen’t typing it too fast I waited at least 5-10 seconds between commands. I think the problem was that in the Vote command it read the quote line, saved it and then removed the quote line. But if the voteadder replied with “else{Please use !vote @$(user)}” there would be no new quote line made, hence deleting the quote entirely.


#221

Hi! I’m wondering if there is a way to add the game the streamer is playing, what day the quote was said on, and who said the quote, to this quote command? Thanks.


#222

@davis0293 Change your !addquote to something like this:

$(urlfetch http://twitch.center/customapi/addquote?token=TOKENHERE&data=$(querystring $(time US/Central "M/D/YYYY") $(user): $(query) ($(twitch CHANNELNAMEHERE "{{game}}"))))

Remember to replace TOKENHERE with your token and CHANNELNAMEHERE with the channel.