From fe5221ed38a769232596e95ec7a8bc56faa42b18 Mon Sep 17 00:00:00 2001 From: Tyler-A Date: Sun, 19 Jan 2020 00:29:20 -0600 Subject: [PATCH] Add code to check for the max bits on each donation --- src/Twitch.ts | 24 +++++++++++++++++++----- src/types.d.ts | 5 +++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Twitch.ts b/src/Twitch.ts index cdab27c..1bc9e43 100644 --- a/src/Twitch.ts +++ b/src/Twitch.ts @@ -1,7 +1,7 @@ // // Twitch.ts // -// Written by: Tyler Akins (2020/01/06 - 2020/01/09) +// Written by: Tyler Akins (2020/01/06 - 2020/01/18) // @@ -72,9 +72,15 @@ export const START_BOT = async () => { // Ensure the user is live if (!response) { - data["offline"].total_bits += bits; - data["offline"].donations.push(bits); - data["offline"].donators.push(donator); + data.offline.total_bits += bits; + data.offline.donations.push(bits); + data.offline.donators.push(donator); + + // Check if we have a new max + if (data.offline.max[1] < bits) { + data.offline.max[0] = donator; + data.offline.max[1] = bits; + }; } else { // Data already exists @@ -88,6 +94,13 @@ export const START_BOT = async () => { // Add the bits to the total and the array of donations data[date].total_bits += bits; data[date].donations.push(bits); + + + // Check if we have a new max + if (data[date].max[1] < bits) { + data[date].max[0] = donator; + data[date].max[1] = bits; + }; } // Making new data point @@ -95,7 +108,8 @@ export const START_BOT = async () => { data[date] = { total_bits: bits, donators: [donator], - donations: [bits] + donations: [bits], + max: [donator, bits] }; }; }; diff --git a/src/types.d.ts b/src/types.d.ts index 7d8e33c..a059b90 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,14 +1,15 @@ // // types.d.ts // -// Written by: Tyler Akins (2020/01/06) +// Written by: Tyler Akins (2020/01/06 - 2020/01/18) // interface data { [key: string]: { + max: [string, number]; + donations: number[]; total_bits: number; donators: string[]; - donations: number[]; }; } \ No newline at end of file