Oh NO WAY! Thatās crazy, thank you so much for putting all that time and effort into this!
Would it be possible to have Nightbot refresh the match history/rr gainloss when I go live? So that it checks every stream session and not based on a period of time?
This command only considers games that occurred after the currently live stream started. So if your channel is not currently live, it will return ājamie is not liveā. Iād like for the command to work for games that occurred during the previous stream if the channel is not currently live, but Nightbotās twitch variable does not supply information about the previous stream. Maybe someone has a custom API for this. Unsure.
Hereās the code for the part of the command thatās hosted on Pastebin. I had to host the majority of the commandās code on Pastebin since the code was too long for Nightbot by itself. This will be useful if the Pastebin link is ever taken down.
Code
((
/** @type {string} */ streamUptimeString,
/** @type {string} */ streamStartDateString,
/** @type {string} */ urlEncodedGetMmrHistoryResponseJson,
) => {
/* streamStartDateString will be a date string even if the channel is not currently live (the date will be the current
date). This may be a Nightbot bug. This is why streamUptimeString is needed to check whether the channel is live */
if (/\bnot live\b/i.test(streamUptimeString)) {
return 'jamie is not live';
}
const streamStartDate = new Date(streamStartDateString);
if (Number.isNaN(streamStartDate.valueOf())) {
return `Failed to parse stream start date: ${streamStartDateString}`.slice(0, 400);
}
const getMmrHistoryResponseJson = decodeURIComponent(urlEncodedGetMmrHistoryResponseJson);
if (/^Error Connecting To Remote Server\b/i.test(getMmrHistoryResponseJson)) {
return getMmrHistoryResponseJson;
}
try {
/** @type {{
readonly data: ReadonlyArray<{
readonly mmr_change_to_last_game: number;
readonly date_raw: number;
}>;
}} */
const getMmrHistoryResponse = JSON.parse(getMmrHistoryResponseJson);
let mmrChangeThisStream = 0;
let winCountThisStream = 0;
let lossCountThisStream = 0;
for (const {date_raw: dateUnixS, mmr_change_to_last_game: mmrChange} of getMmrHistoryResponse.data) {
const date = new Date(dateUnixS * 1000);
if (date >= streamStartDate) {
mmrChangeThisStream += mmrChange;
if (mmrChange > 0) {
winCountThisStream++;
} else {
lossCountThisStream++;
}
}
}
return `jamie is ${mmrChangeThisStream > 0 ? 'UP' : 'DOWN'} ${mmrChangeThisStream}RR${winCountThisStream}-${lossCountThisStream}`;
} catch (e) {
return `Failed to parse MMR history: ${e.message}: ${getMmrHistoryResponseJson}`.slice(0, 400);
}
})
Please let me know if this is what you had in mind or if youād like any help making modifications.
I havenāt been able to test your new command yet, but I just want to say thank you for taking time out of your day/night to do this for me; a complete stranger. It really means a lot to me. Once again thank you c:
I was able to test your command today, there are some things that I noticed with the new command. It seemed to update a lot slower than the previous command you made. Is that due to Nightbot having to fetch from two URLs? It was a considerable amount of latency. I was at 2-1, and won two and lost 1, and it still registered at 2-1.
For the newer command would you be able to change the formatting to look like this?
jamie is UP 35RR. W/L: 7-4
It currently looks like
jamie is DOWN 0RR0-0
Otherwise, the addition of having it know when Iām live is so nice ^^