JoSChhmo

Untitled

Apr 8th, 2023 (edited)
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. ((
  2. /** @type {string} */ streamUptimeString,
  3. /** @type {string} */ streamStartDateString,
  4. /** @type {string} */ urlEncodedGetMmrHistoryResponseJson,
  5. ) => {
  6. /* streamStartDateString will be a date string even if the channel is not currently live (the date will be the current
  7. date). This may be a Nightbot bug. This is why streamUptimeString is needed to check whether the channel is live */
  8. if (/\bnot live\b/i.test(streamUptimeString)) {
  9. return 'Draxick is not live';
  10. }
  11.  
  12. const streamStartDate = new Date(streamStartDateString);
  13. if (Number.isNaN(streamStartDate.valueOf())) {
  14. return `Failed to parse stream start date: ${streamStartDateString}`.slice(0, 400);
  15. }
  16.  
  17. const getMmrHistoryResponseJson = decodeURIComponent(urlEncodedGetMmrHistoryResponseJson);
  18. if (/^Error Connecting To Remote Server\b/i.test(getMmrHistoryResponseJson)) {
  19. return 'No games played yet.';
  20. }
  21.  
  22. try {
  23. /** @type {{
  24. readonly data: ReadonlyArray<{
  25. readonly mmr_change_to_last_game: number;
  26. readonly date_raw: number;
  27. }>;
  28. }} */
  29.  
  30.  
  31. const getMmrHistoryResponse = JSON.parse(getMmrHistoryResponseJson);
  32.  
  33. let mmrChangeThisStream = 0;
  34. let winCountThisStream = 0;
  35. let lossCountThisStream = 0;
  36. let rankedRating = 0;
  37. var string = "";
  38. var rank = "";
  39.  
  40. json = JSON.parse(getMmrHistoryResponseJson);
  41.  
  42. currenttierpatched = json.data.currenttierpatched;
  43. elo = json.data.elo;
  44. mmr_change_to_last_game = json.data.mmr_change_to_last_game;
  45.  
  46. if(mmr_change_to_last_game > 0) {
  47. string = "gained";
  48. }else if(mmr_change_to_last_game < 0){
  49. string = "lost";
  50. }else{
  51. string = "at";
  52. }
  53.  
  54. return `Draxick is at ${(elo-2100)}RR in ${currenttierpatched} and ${string} ${Math.abs(mmr_change_to_last_game)}RR last game.` ;
  55. } catch (e) {
  56. return `Failed to parse MMR history: ${e.message}: ${getMmrHistoryResponseJson}`.slice(0, 400);
  57. }
  58. })
  59.  
Advertisement
Add Comment
Please, Sign In to add comment