Javascript question in eval

Hi,

so i have a urlfetch with responses a text like:
Player (998) Rank #19,792, has played 402 games with a 51% winrate, -2 streak, and 5 drops

This works fine, but now i want to translate it in german before Nightbot posts it in the chat.

So i’ve tried eval to use some javascript.

My current Try looks like this:

$(eval a=$(urlfetch https://aoe2.net/api/nightbot/rank?leaderboard_id=3&search=Player&flag=false);b = a.slice(0, a.indexOf(' Rank')).replace(' (', ' hat eine Elo von: ').replace(')', '.'); c = a.slice(a.indexOf(', has played')+13, a.indexOf(' games ')); d = a.slice(a.indexOf(' with a ')+8, a.indexOf('%')); e = a.slice(a.indexOf('winrate, ')+9, a.indexOf(' streak,')); b = b + ' Gespielte Spiele: ' + c + '. Die Siegrate beträgt: ' + d + '%.' + ' Die aktuelle Serie ist ' + e + '.';b)

But it just writes “Unexpected identifier” to the chat.

I want following Javascript code inside the eval.

  • a is the result of the urlfetch.
  • b is the variable i want nightbot to post inside the chat

Javascript version i want inside eval:

a = $(urlfetch https://aoe2.net/api/nightbot/rank?leaderboard_id=3&search=Player&flag=false);
b = a.slice(0, a.indexOf(' Rank')).replace(' (', ' hat eine Elo von: ').replace(')', '.');
c = a.slice(a.indexOf(', has played')+13, a.indexOf(' games '));
d = a.slice(a.indexOf(' with a ')+8, a.indexOf('%'));
e = a.slice(a.indexOf('winrate, ')+9, a.indexOf(' streak,'));
b = b + ' Gespielte Spiele: ' + c + '. Die Siegrate beträgt: ' + d + '%.' + ' Die aktuelle Serie ist ' + e + '.';

Can someone help me please?

Hi @Aignetti Probably, you should quote those “$(urlfetch ...)”. I am not very good in German Language (using translator) consider trying the following code.

Note:- At this time API is returning: _Worst_AoE_Player_ (1982) Rank #286, has played 168 games with a 54% winrate, +1 streak, and 1 drops

!addcom !CmdName -cd=5 $(eval var a = `$(urlfetch https://aoe2.net/api/nightbot/rank?leaderboard_id=3&search=Player&flag=false)`; var results = a.match(/(\-|\+|\#)?([0-9])+%?/g); `_Worst_AoE_Player_ (${results[0]}) Rang ${results[1]}, hat ${results[2]} Spiele mit einer Gewinnrate von ${results[3]}, ${results[4]} Streak und ${results[5]} Drops gespielt`)

Usage:

Ritik: !cmdname
Nightbot: _Worst_AoE_Player_ (1982) Rang #286, hat 168 Spiele mit einer Gewinnrate von 54%, +1 Streak und 1 Drops gespielt

Edit: As said, your code is OK. Just quote those $(urlfetch ...)

$(eval a=`$(urlfetch https://aoe2.net/api/nightbot/rank?leaderboard_id=3&search=Player&flag=false)`;b = a.slice(0, a.indexOf(' Rank')).replace(' (', ' hat eine Elo von: ').replace(')', '.'); c = a.slice(a.indexOf(', has played')+13, a.indexOf(' games ')); d = a.slice(a.indexOf(' with a ')+8, a.indexOf('%')); e = a.slice(a.indexOf('winrate, ')+9, a.indexOf(' streak,')); b = b + ' Gespielte Spiele: ' + c + '. Die Siegrate beträgt: ' + d + '%.' + ' Die aktuelle Serie ist ' + e + '.';b)

Regards

2 Likes

Thank you bro, you were right - i just had to put quotes on my urlfetch, now its working. Thank you a lot man !

1 Like

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