I would like to create a couple of commands, for example !addnumber & !average, where mods would be able to use !addnumber and the $(touser) information would be added to an existing number. This existing number will accumulate every time and keep adding the numbers we feed to it. I then plan on using !average to take the average number of all the numbers that the !addnumber command has taken. I have no clue how to or even if Nightbot can do something like this, so any help would be appreciated
How do I create a command with a running average
11 replies
Yes firstly generate your two tokens here:
https://twitch.center/customapi/quote/generate
They come between token= and &data
The public token is 8 digits and the private token is 16 digits
!addnumber command:
$(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(1),)`;`Added $(1) to the total average.`)
Add through the dashboard so no one sees your private token.
Set user level to mod
!average command:
$(eval N=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`.split(`,`);x=0;for(i=0;i<N.length-1;i++){x=x+parseInt(N[i])};`The average is ${x/(N.length-1)}.`)
This can be added through chat or any other means.
No other special instructions
Note: I didn’t test this but it should work let me know if there are any issues.
The average result shouldn’t be changing randomly it should be the average of all the numbers.
You can delete qoutes with this link
https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&data=NUMBER_OF_Q…
Or you can delete them all with this link
https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&data=&clear=1
I’m assuming that’s what you mean when you say clear your tokens.
For my average command I have
$(eval N=$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&no_id=1).split(,);x=0;for(i=0;i<N.length-1;i++){x=x+parseInt(N[i])};The average is ${x/(N.length)}.)
and my addnumber command is
$(eval a=$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(touser),);Added $(touser) to the total.)
Is there an issuse with what I have written?
Didn't find your answer? The community is on Discord.
Ask on Discord