NightDev Community Forums

Count Number of wins


#1

So a friend of mine posted here earlier to get help on his Duel command and asked me to post here since he is busy.
/me $(user) challenged $(touser) to a DUEL! || $(eval a=$(urlfetch json https://pastebin.com/raw/9EaiNMgF).split(,);a[Math.floor(Math.random()*a.length)].replace(/touser/g,$(touser)).replace(/user/g,$(user))) - Command he has
Is there is anyway to count the number of duel wins each viewer has?


#2

@BigBallerNationLA @Aw3som3n3ss Original thread: Nightbot Replace For Duel

Setting up a wins counter command is possible using ehsankia’s quote custom API - read more about it here.


What I need you to do first is edit your pastebin file https://pastebin.com/9EaiNMgF
For each line, replace the winner with W- and the loser with L-

For example, this line:

user pummeled touser

becomes this:

W- pummeled L-

And this line:

touser beat user with no hands

becomes this:

W- beat L- with no hands

Note that it doesn’t matter whether user or touser is the winner. Replace whoever wins with W- and whoever loses with L- It would also help if you got rid of the third-party winner line. Also note that editing the file in this way lets you remove repetitive lines (e.g. user pummeled touser & touser pummeled user)


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 and keep them somewhere safe!

I’ve set up 3 commands below:

!duel and !duelp2 which work in tandem to output the response for a duel between two users and save the winner’s name to a list
!wins which will output how many wins a user has

First delete !duel if you already added it. Then copy and paste these commands into chat. Replace each publicTokenHere with your public token and each privateTokenHere with your private token:

!addcom -cd=5 !duel -a=!duelp2 $(eval a=`-$(user)-`;b=decodeURIComponent(`-$(querystring $(touser))-`);if(a.toLowerCase()!=b.toLowerCase()){if(Math.round(Math.random())==0){`privateTokenHere&data=`+a+` `+b;}else{`privateTokenHere&data=`+b+` `+a;}}else{` `;})
!addcom -cd=5 !duelp2 $(eval a=`$(urlfetch json https://pastebin.com/raw/9EaiNMgF)`.split(`,`);b=`$(urlfetch http://twitch.center/customapi/addquote?token=$(1))`;c=`$(query)`.split(`&data=`)[1].split(` `);c[0].toLowerCase()==`$(user)`.toLowerCase()?d=c[1]:d=c[0];`$(query)`.includes(`privateTokenHere`)?`/me $(user) challenged `+d+` to a DUEL! || `+a[Math.floor(Math.random()*a.length)].replace(/W-/g,c[0]).replace(/L-/g,c[1]):`Invalid input!`)
!addcom -cd=5 !wins $(eval a=`$(urlfetch json http://twitch.center/customapi/quote/list?token=publicTokenHere)`.match(/-$(touser)-/gi);a!=null?`$(touser) has won `+a.length+` duels.`:`$(touser) has won 0 duels.`)

Usages:
!duel [target user you wish to duel]
!wins [username you wish to look up, if you leave this field blank it will look up your own name]


#3

@BigBallerNationLA @Aw3som3n3ss Response updated. Please refresh this page before adding the commands.


#4

So, I used that code but it glitches out when someone doesn’t type in the name exactly like they add an @ or capitalize a letter, it challenges themself.

  1. How do you stop it from challenging the user that activated the command -(!duel player123 TheRealOnez challenged TheRealOnez to a duel.)
  2. Is it possible to make it so that a viewer always loses?
  3. How do you add a command to clear the number of wins someone has?
    Thank you

#6

@TheRealOnez Commands updated. They will now ignore @ symbols in the input and will block users from targeting themselves. Delete the existing !duel, !duelp2, and !wins commands, then copy and paste these into chat. I added a new command !reset (mod-only) which clears the whole scoreboard. Replace publicTokenHere with your public token and privateTokenHere with your private token. In the command response for !duel replace userThatAlwaysLoses with the user you want to always lose (note there can only be one user):

!addcom -cd=5 !duel -a=!duelp2 $(eval a=`-$(user)-`;b=decodeURIComponent(`-$(querystring $(touser))-`).replace(/@/g,``);if(a.toLowerCase()!=b.toLowerCase()){if(Math.round(Math.random())==0){c=a,d=b;}else{c=b,d=a;}e=`-userThatAlwaysLoses-`;if(e.toLowerCase()==a.toLowerCase()){c=b,d=a;}if(e.toLowerCase()==b.toLowerCase()){c=a,d=b;}`privateTokenHere&data=`+c+` `+d;}else{` `;})
!addcom -cd=5 !duelp2 $(eval if(`$(query)`.includes(`privateTokenHere`)){a=`$(urlfetch json https://pastebin.com/raw/9EaiNMgF)`.split(`,`);b=`$(urlfetch http://twitch.center/customapi/addquote?token=$(1))`;c=`$(query)`.split(`data=`)[1].split(` `);c[0]=c[0].slice(1,c[0].length-1),c[1]=c[1].slice(1,c[1].length-1);c[0]==`$(user)`?d=c[1]:d=c[0];`/me $(user) challenged `+d+` to a DUEL! || `+a[Math.floor(Math.random()*a.length)].replace(/W-/g,c[0]).replace(/L-/g,c[1]);}else{`Invalid input!`;})
!addcom -cd=5 !wins $(eval a=`$(urlfetch json http://twitch.center/customapi/quote/list?token=publicTokenHere)`;b=new RegExp(`-$(touser)-`.replace(/@/g,``),`gi`);c=a.match(b);c!=null?`$(touser) has won `+c.length+` duels.`:`$(touser) has won 0 duels.`)
!addcom -ul=mod !reset $(eval a=`$(urlfetch http://twitch.center/customapi/delquote?token=privateTokenHere&clear=1)`;` `) The duel scoreboard has been reset!

#7

Sorry two more things,
How would you make it to show the number of losses?
Is there a way to make it so that a UserAlwaysWins, like the always loses but wins?
I’m new to nightbot


#8

@TheRealOnez

Delete !duel, !duelp2, and !wins if you already added those. !reset doesn’t need editing. Here are new setups for !duel, !duelp2, !wins, and !losses. Copy and paste them into chat. Replace publicTokenHere with your public token and privateTokenHere with your private token. In the response for !duel, replace userThatAlwaysLoses with the user you want to always lose and userThatAlwaysWins with the user you want to always win:

!addcom -cd=5 !duel -a=!duelp2 $(eval a=`-$(user)-`;b=decodeURIComponent(`-$(querystring $(touser))-`).replace(/@/g,``);if(a.toLowerCase()!=b.toLowerCase()){if(Math.round(Math.random())==0){c=a,d=b;}else{c=b,d=a;}e=`-userThatAlwaysLoses-`,f=`-userThatAlwaysWins-`;if(a.toLowerCase()==e.toLowerCase()||b.toLowerCase()==f.toLowerCase()){c=b,d=a;}if(a.toLowerCase()==f.toLowerCase()||b.toLowerCase==e.toLowerCase()){c=a,d=b;}c=c.replace(`-`,`-W:`),d=d.replace(`-`,`-L:`);`privateTokenHere&data=`+c+`|`+d;}else{` `;})
!addcom -cd=5 !duelp2 $(eval if(`$(query)`.includes(`privateTokenHere`)){a=`$(urlfetch json https://pastebin.com/raw/9EaiNMgF)`.split(`,`);b=`$(urlfetch http://twitch.center/customapi/addquote?token=$(1))`;c=`$(query)`.split(`data=`)[1].split(`|`);c[0]=c[0].slice(3,c[0].length-1),c[1]=c[1].slice(3,c[1].length-1);c[0]==`$(user)`?d=c[1]:d=c[0];`/me $(user) challenged `+d+` to a DUEL! || `+a[Math.floor(Math.random()*a.length)].replace(/W-/g,c[0]).replace(/L-/g,c[1]);}else{`Invalid input!`;})
!addcom -cd=5 !wins $(eval a=`$(urlfetch json http://twitch.center/customapi/quote/list?token=publicTokenHere)`;b=new RegExp(`-W:$(touser)-`.replace(/@/g,``),`gi`);c=a.match(b);c!=null?`$(touser) has won `+c.length+` duels.`:`$(touser) has won 0 duels.`)
!addcom -cd=5 !losses $(eval a=`$(urlfetch json http://twitch.center/customapi/quote/list?token=publicTokenHere)`;b=new RegExp(`-L:$(touser)-`.replace(/@/g,``),`gi`);c=a.match(b);c!=null?`$(touser) has lost `+c.length+` duels.`:`$(touser) has lost 0 duels.`)

#9

Thank You so much.
The user that always loses doesn’t always lose.
If there is a way to fix that, that would be great.
But honestly you have already done so much, so I can just go back to the command that doesn’t do AlwaysLose and AlwaysWin. -I Don’t want to waste your time.


#10

@TheRealOnez I forgot to mention that you must replace userThatAlwaysWins and userThatAlwaysLoses with their corresponding usernames exactly as they are, with the correct capitalization. If for some reason you can’t get the correct capitalization I’ve edited the command response for !duel to accommodate for that.


#11

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