diff --git a/config.js b/config.js index 9c76a70..1f9dc7a 100644 --- a/config.js +++ b/config.js @@ -61,24 +61,16 @@ var seconds_added_per_chests = 30 // General Twitch, Streamlabs And StreamElements Config for Happy Hour -var seconds_added_per_sub_prime_happy = 85 -var seconds_added_per_sub_tier1_happy = 85 -var seconds_added_per_sub_tier2_happy = 300 -var seconds_added_per_sub_tier3_happy = 960 +var factor_t1 = 1.5 +var factor_t2 = 1.75 +var factor_t3 = 2.0 +var factor_bits = 1.5 +var factor_donations = 1.5 -var seconds_added_per_resub_prime_happy = 85 -var seconds_added_per_resub_tier1_happy = 85 -var seconds_added_per_resub_tier2_happy = 300 -var seconds_added_per_resub_tier3_happy = 960 -var seconds_added_per_giftsub_tier1_happy = 85 -var seconds_added_per_giftsub_tier2_happy = 300 -var seconds_added_per_giftsub_tier3_happy = 960 - -var seconds_added_per_bits_happy = 60 - -// Streamlabs And StreamElements Config -var seconds_added_per_donation_happy = 60 - -// Streamloots Config -var seconds_added_per_chests_happy = 60 +// General Twitch, Streamlabs And StreamElements Config for Random Hour +var range_t1 = [0.5, 2] +var range_t2 = [1.0, 3] +var range_t3 = [2.0, 5] +var range_bits = [0.5, 2] +var range_donations = [0.5, 2] diff --git a/js/api/streamelements.js b/js/api/streamelements.js index fe35118..e2ae188 100644 --- a/js/api/streamelements.js +++ b/js/api/streamelements.js @@ -34,59 +34,65 @@ if (streamelements_token !== "") { function onEvent(data) { logObject("StreamElements", data); - if (!countdownEnded && !happy_hour_active) { + if (!countdownEnded) { + let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); + let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); + let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); + let factor_bits_local = (happy_hour_active ? factor_bits : 1) * (random_hour_active ? randomInRangeNoRounding(...range_bits): 1); + let factor_donations_local = (happy_hour_active ? factor_donations : 1) * (random_hour_active ? randomInRangeNoRounding(...range_donations): 1); + if ((data['listener'] === "subscriber-latest") && subEnable) { if (data['event']['gifted'] || data['event']['bulkGifted']) { let amount; if (data['event']['gifted']) amount = 1; else amount = data['event']['amount']; if (data['event']['tier'] == "prime" || data['event']['tier'] == "1000") { - addTime(endingTime, seconds_added_per_giftsub_tier1 * amount); - logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier1 * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 1 Subs`); + addTime(endingTime, seconds_added_per_giftsub_tier1 * amount * factor_t1_local); + logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier1 * amount * factor_t1_local} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 1 Subs`); } else if (data['event']['tier'] == "2000") { - addTime(endingTime, seconds_added_per_giftsub_tier2 * amount); - logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier2 * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 2 Subs`); + addTime(endingTime, seconds_added_per_giftsub_tier2 * amount * factor_t2_local); + logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier2 * amount * factor_t2_local} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 2 Subs`); } else if (data['event']['tier'] == "3000") { - addTime(endingTime, seconds_added_per_giftsub_tier3 * amount); - logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier3 * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 3 Subs`); + addTime(endingTime, seconds_added_per_giftsub_tier3 * amount * factor_t3_local); + logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier3 * amount * factor_t3_local} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 3 Subs`); } } else if (data['event']['amount'] != "1") { if (data['event']['tier'] == "prime") { - addTime(endingTime, seconds_added_per_resub_prime); - logMessage("StreamElements", `Added ${seconds_added_per_resub_prime} Seconds Because ${data['event']['name']} ReSubscribed With Prime`); + addTime(endingTime, seconds_added_per_resub_prime * factor_t1_local); + logMessage("StreamElements", `Added ${seconds_added_per_resub_prime * factor_t1_local} Seconds Because ${data['event']['name']} ReSubscribed With Prime`); } else if (data['event']['tier'] == "1000") { - addTime(endingTime, seconds_added_per_resub_tier1); - logMessage("StreamElements", `Added ${seconds_added_per_resub_tier1} Seconds Because ${data['event']['name']} ReSubscribed With Tier 1`); + addTime(endingTime, seconds_added_per_resub_tier1 * factor_t1_local); + logMessage("StreamElements", `Added ${seconds_added_per_resub_tier1 * factor_t1_local} Seconds Because ${data['event']['name']} ReSubscribed With Tier 1`); } else if (data['event']['tier'] == "2000") { - addTime(endingTime, seconds_added_per_resub_tier2); - logMessage("StreamElements", `Added ${seconds_added_per_resub_tier2} Seconds Because ${data['event']['name']} ReSubscribed With Tier 2`); + addTime(endingTime, seconds_added_per_resub_tier2 * factor_t2_local); + logMessage("StreamElements", `Added ${seconds_added_per_resub_tier2 * factor_t2_local} Seconds Because ${data['event']['name']} ReSubscribed With Tier 2`); } else if (data['event']['tier'] == "3000") { - addTime(endingTime, seconds_added_per_resub_tier3); - logMessage("StreamElements", `Added ${seconds_added_per_resub_tier3} Seconds Because ${data['event']['name']} ReSubscribed With Tier 3`); + addTime(endingTime, seconds_added_per_resub_tier3 * factor_t3_local); + logMessage("StreamElements", `Added ${seconds_added_per_resub_tier3 * factor_t3_local} Seconds Because ${data['event']['name']} ReSubscribed With Tier 3`); } } else { if (data['event']['tier'] == "prime") { - addTime(endingTime, seconds_added_per_sub_prime); - logMessage("StreamElements", `Added ${seconds_added_per_sub_prime} Seconds Because ${data['event']['name']} Subscribed With Prime`); + addTime(endingTime, seconds_added_per_sub_prime * factor_t1_local); + logMessage("StreamElements", `Added ${seconds_added_per_sub_prime * factor_t1_local} Seconds Because ${data['event']['name']} Subscribed With Prime`); } else if (data['event']['tier'] == "1000") { - addTime(endingTime, seconds_added_per_sub_tier1); - logMessage("StreamElements", `Added ${seconds_added_per_sub_tier1} Seconds Because ${data['event']['name']} Subscribed With Tier 1`); + addTime(endingTime, seconds_added_per_sub_tier1 * factor_t1_local); + logMessage("StreamElements", `Added ${seconds_added_per_sub_tier1 * factor_t1_local} Seconds Because ${data['event']['name']} Subscribed With Tier 1`); } else if (data['event']['tier'] == "2000") { - addTime(endingTime, seconds_added_per_sub_tier2); - logMessage("StreamElements", `Added ${seconds_added_per_sub_tier2} Seconds Because ${data['event']['name']} Subscribed With Tier 2`); + addTime(endingTime, seconds_added_per_sub_tier2 * factor_t2_local); + logMessage("StreamElements", `Added ${seconds_added_per_sub_tier2 * factor_t2_local} Seconds Because ${data['event']['name']} Subscribed With Tier 2`); } else if (data['event']['tier'] == "3000") { - addTime(endingTime, seconds_added_per_sub_tier3); - logMessage("StreamElements", `Added ${seconds_added_per_sub_tier3} Seconds Because ${data['event']['name']} Subscribed With Tier 3`); + addTime(endingTime, seconds_added_per_sub_tier3 * factor_t3_local); + logMessage("StreamElements", `Added ${seconds_added_per_sub_tier3 * factor_t3_local} Seconds Because ${data['event']['name']} Subscribed With Tier 3`); } } if (!users.includes(data['event']['name'])) { @@ -97,8 +103,8 @@ if (streamelements_token !== "") { else if ((data['listener'] === "cheer-latest") && bitEnable) { if (data['event']['amount'] >= min_amount_of_bits) { let times = Math.floor(data['event']['amount']/min_amount_of_bits); - addTime(endingTime, seconds_added_per_bits * times); - logMessage("StreamElements", `Added ${seconds_added_per_bits * times} Seconds Because ${data['event']['name']} Donated ${data['event']['amount']} Bits`); + addTime(endingTime, seconds_added_per_bits * times * factor_bits_local); + logMessage("StreamElements", `Added ${seconds_added_per_bits * times * factor_bits_local} Seconds Because ${data['event']['name']} Donated ${data['event']['amount']} Bits`); if (!users.includes(data['event']['name'])) { users.push(data['event']['name']); } @@ -108,90 +114,8 @@ if (streamelements_token !== "") { else if ((data['listener'] === "tip-latest") && donationEnable) { if (data['event']['amount'] >= min_donation_amount) { let times = Math.floor(data['event']['amount']/min_donation_amount); - addTime(endingTime, seconds_added_per_donation * times); - logMessage("StreamElements", `Added ${seconds_added_per_donation * times} Seconds Because ${data['event']['name']} Donated ${data['event']['amount']}$`); - if (!users.includes(data['event']['name'])) { - users.push(data['event']['name']); - } - } - } - } - else if (!countdownEnded && happy_hour_active) { - if ((data['listener'] === "subscriber-latest") && subEnable) { - if (data['event']['gifted'] || data['event']['bulkGifted']) { - let amount; - if (data['event']['gifted']) amount = 1; - else amount = data['event']['amount']; - if (data['event']['tier'] == "prime" || data['event']['tier'] == "1000") { - addTime(endingTime, seconds_added_per_giftsub_tier1_happy * amount); - logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier1_happy * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 1 Subs`); - } - else if (data['event']['tier'] == "2000") { - addTime(endingTime, seconds_added_per_giftsub_tier2_happy * amount); - logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier2_happy * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 2 Subs`); - } - else if (data['event']['tier'] == "3000") { - addTime(endingTime, seconds_added_per_giftsub_tier3_happy * amount); - logMessage("StreamElements", `Added ${seconds_added_per_giftsub_tier3_happy * amount} Seconds Because ${data['event']['name']} Gifted ${amount} Tier 3 Subs`); - } - } - else if (data['event']['amount'] != "1") { - if (data['event']['tier'] == "prime") { - addTime(endingTime, seconds_added_per_resub_prime_happy); - logMessage("StreamElements", `Added ${seconds_added_per_resub_prime_happy} Seconds Because ${data['event']['name']} ReSubscribed With Prime`); - } - else if (data['event']['tier'] == "1000") { - addTime(endingTime, seconds_added_per_resub_tier1_happy); - logMessage("StreamElements", `Added ${seconds_added_per_resub_tier1_happy} Seconds Because ${data['event']['name']} ReSubscribed With Tier 1`); - } - else if (data['event']['tier'] == "2000") { - addTime(endingTime, seconds_added_per_resub_tier2_happy); - logMessage("StreamElements", `Added ${seconds_added_per_resub_tier2_happy} Seconds Because ${data['event']['name']} ReSubscribed With Tier 2`); - } - else if (data['event']['tier'] == "3000") { - addTime(endingTime, seconds_added_per_resub_tier3_happy); - logMessage("StreamElements", `Added ${seconds_added_per_resub_tier3_happy} Seconds Because ${data['event']['name']} ReSubscribed With Tier 3`); - } - } - else { - if (data['event']['tier'] == "prime") { - addTime(endingTime, seconds_added_per_sub_prime_happy); - logMessage("StreamElements", `Added ${seconds_added_per_sub_prime_happy} Seconds Because ${data['event']['name']} Subscribed With Prime`); - } - else if (data['event']['tier'] == "1000") { - addTime(endingTime, seconds_added_per_sub_tier1_happy); - logMessage("StreamElements", `Added ${seconds_added_per_sub_tier1_happy} Seconds Because ${data['event']['name']} Subscribed With Tier 1`); - } - else if (data['event']['tier'] == "2000") { - addTime(endingTime, seconds_added_per_sub_tier2_happy); - logMessage("StreamElements", `Added ${seconds_added_per_sub_tier2_happy} Seconds Because ${data['event']['name']} Subscribed With Tier 2`); - } - else if (data['event']['tier'] == "3000") { - addTime(endingTime, seconds_added_per_sub_tier3_happy); - logMessage("StreamElements", `Added ${seconds_added_per_sub_tier3_happy} Seconds Because ${data['event']['name']} Subscribed With Tier 3`); - } - } - if (!users.includes(data['event']['name'])) { - users.push(data['event']['name']); - } - } - - else if ((data['listener'] === "cheer-latest") && bitEnable) { - if (data['event']['amount'] >= min_amount_of_bits) { - let times = Math.floor(data['event']['amount']/min_amount_of_bits); - addTime(endingTime, seconds_added_per_bits_happy * times); - logMessage("StreamElements", `Added ${seconds_added_per_bits_happy * times} Seconds Because ${data['event']['name']} Donated ${data['event']['amount']} Bits`); - if (!users.includes(data['event']['name'])) { - users.push(data['event']['name']); - } - } - } - - else if ((data['listener'] === "tip-latest") && donationEnable) { - if (data['event']['amount'] >= min_donation_amount) { - let times = Math.floor(data['event']['amount']/min_donation_amount); - addTime(endingTime, seconds_added_per_donation_happy * times); - logMessage("StreamElements", `Added ${seconds_added_per_donation_happy * times} Seconds Because ${data['event']['name']} Donated ${data['event']['amount']}$`); + addTime(endingTime, seconds_added_per_donation * times * factor_donations_local); + logMessage("StreamElements", `Added ${seconds_added_per_donation * times * factor_donations_local} Seconds Because ${data['event']['name']} Donated ${data['event']['amount']}$`); if (!users.includes(data['event']['name'])) { users.push(data['event']['name']); } diff --git a/js/api/streamlabs.js b/js/api/streamlabs.js index 466000d..4abdb91 100644 --- a/js/api/streamlabs.js +++ b/js/api/streamlabs.js @@ -7,171 +7,90 @@ if (streamlabs_token !== "") { socket.on("event", (event) => { logObject("Streamlabs", event); + let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); + let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); + let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); + let factor_bits_local = (happy_hour_active ? factor_bits : 1) * (random_hour_active ? randomInRangeNoRounding(...range_bits): 1); + let factor_donations_local = (happy_hour_active ? factor_donations : 1) * (random_hour_active ? randomInRangeNoRounding(...range_donations): 1); + if (event.type == "subscription" && !event.message[0].gifter) { if (!countdownEnded && subEnable) { - if(!happy_hour_active){ - if (event.message[0].sub_plan == "1000") { - addTime(endingTime, seconds_added_per_sub_tier1); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier1} Seconds Because ${event.message[0].name} Subscribed With Tier 1`); - } - else if (event.message[0].sub_plan == "2000") { - addTime(endingTime, seconds_added_per_sub_tier2); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier2} Seconds Because ${event.message[0].name} Subscribed With Tier 2`); - } - else if (event.message[0].sub_plan == "3000") { - addTime(endingTime, seconds_added_per_sub_tier3); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier3} Seconds Because ${event.message[0].name} Subscribed With Tier 3`); - } - else { - addTime(endingTime, seconds_added_per_sub_prime); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_prime} Seconds Because ${event.message[0].name} Subscribed With Prime`); - } - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } + if (event.message[0].sub_plan == "1000") { + addTime(endingTime, seconds_added_per_sub_tier1 * factor_t1_local); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier1 * factor_t1_local} Seconds Because ${event.message[0].name} Subscribed With Tier 1`); } - else if(!happy_hour_active){ - if (event.message[0].sub_plan == "1000") { - addTime(endingTime, seconds_added_per_sub_tier1_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier1_happy} Seconds Because ${event.message[0].name} Subscribed With Tier 1`); - } - else if (event.message[0].sub_plan == "2000") { - addTime(endingTime, seconds_added_per_sub_tier2_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier2_happy} Seconds Because ${event.message[0].name} Subscribed With Tier 2`); - } - else if (event.message[0].sub_plan == "3000") { - addTime(endingTime, seconds_added_per_sub_tier3_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier3_happy} Seconds Because ${event.message[0].name} Subscribed With Tier 3`); - } - else { - addTime(endingTime, seconds_added_per_sub_prime_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_sub_prime_happy} Seconds Because ${event.message[0].name} Subscribed With Prime`); - } - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } + else if (event.message[0].sub_plan == "2000") { + addTime(endingTime, seconds_added_per_sub_tier2 * factor_t2_local); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier2 * factor_t2_local} Seconds Because ${event.message[0].name} Subscribed With Tier 2`); + } + else if (event.message[0].sub_plan == "3000") { + addTime(endingTime, seconds_added_per_sub_tier3 * factor_t3_local); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_tier3 * factor_t3_local} Seconds Because ${event.message[0].name} Subscribed With Tier 3`); + } + else { + addTime(endingTime, seconds_added_per_sub_prime * factor_t1_local); + logMessage("Streamlabs", `Added ${seconds_added_per_sub_prime * factor_t1_local} Seconds Because ${event.message[0].name} Subscribed With Prime`); + } + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); } } } else if (event.type == "resub" && !event.message[0].gifter) { if (!countdownEnded && subEnable) { - if(!happy_hour_active){ - if (event.message[0].sub_plan == "1000") { - addTime(endingTime, seconds_added_per_resub_tier1); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier1} Seconds Because ${event.message[0].name} ReSubscribed With Tier 1`); - } - else if (event.message[0].sub_plan == "2000") { - addTime(endingTime, seconds_added_per_resub_tier2); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier2} Seconds Because ${event.message[0].name} ReSubscribed With Tier 2`); - } - else if (event.message[0].sub_plan == "3000") { - addTime(endingTime, seconds_added_per_resub_tier3); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier3} Seconds Because ${event.message[0].name} ReSubscribed With Tier 3`); - } - else { - addTime(endingTime, seconds_added_per_resub_prime); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_prime} Seconds Because ${event.message[0].name} ReSubscribed With Prime`); - } - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } + if (event.message[0].sub_plan == "1000") { + addTime(endingTime, seconds_added_per_resub_tier1 * factor_t1_local); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier1 * factor_t1_local} Seconds Because ${event.message[0].name} ReSubscribed With Tier 1`); } - else if(!happy_hour_active){ - if (event.message[0].sub_plan == "1000") { - addTime(endingTime, seconds_added_per_resub_tier1_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier1_happy} Seconds Because ${event.message[0].name} ReSubscribed With Tier 1`); - } - else if (event.message[0].sub_plan == "2000") { - addTime(endingTime, seconds_added_per_resub_tier2_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier2_happy} Seconds Because ${event.message[0].name} ReSubscribed With Tier 2`); - } - else if (event.message[0].sub_plan == "3000") { - addTime(endingTime, seconds_added_per_resub_tier3_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier3_happy} Seconds Because ${event.message[0].name} ReSubscribed With Tier 3`); - } - else { - addTime(endingTime, seconds_added_per_resub_prime_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_resub_prime_happy} Seconds Because ${event.message[0].name} ReSubscribed With Prime`); - } - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } + else if (event.message[0].sub_plan == "2000") { + addTime(endingTime, seconds_added_per_resub_tier2 * factor_t2_local); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier2 * factor_t2_local} Seconds Because ${event.message[0].name} ReSubscribed With Tier 2`); + } + else if (event.message[0].sub_plan == "3000") { + addTime(endingTime, seconds_added_per_resub_tier3 * factor_t3_local); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_tier3 * factor_t3_local} Seconds Because ${event.message[0].name} ReSubscribed With Tier 3`); + } + else { + addTime(endingTime, seconds_added_per_resub_prime * factor_t1_local); + logMessage("Streamlabs", `Added ${seconds_added_per_resub_prime * factor_t1_local} Seconds Because ${event.message[0].name} ReSubscribed With Prime`); + } + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); } } } else if (event.message[0].gifter) { if (!countdownEnded && subEnable) { - if(!happy_hour_active){ - if (event.message[0].sub_plan == "1000") { - addTime(endingTime, seconds_added_per_giftsub_tier1); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); - } - else if (event.message[0].sub_plan == "2000") { - addTime(endingTime, seconds_added_per_giftsub_tier2); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier2} Seconds Because ${event.message[0].gifter} Gifted A Tier 2 Sub`); - } - else if (event.message[0].sub_plan == "3000") { - addTime(endingTime, seconds_added_per_giftsub_tier3); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier3} Seconds Because ${event.message[0].gifter} Gifted A Tier 3 Sub`); - } - else { - addTime(endingTime, seconds_added_per_giftsub_tier1); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); - } - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } + if (event.message[0].sub_plan == "1000") { + addTime(endingTime, seconds_added_per_giftsub_tier1 * factor_t1_local); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1 * factor_t1_local} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); } - else if(happy_hour_active){ - if (event.message[0].sub_plan == "1000") { - addTime(endingTime, seconds_added_per_giftsub_tier1_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1_happy} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); - } - else if (event.message[0].sub_plan == "2000") { - addTime(endingTime, seconds_added_per_giftsub_tier2_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier2_happy} Seconds Because ${event.message[0].gifter} Gifted A Tier 2 Sub`); - } - else if (event.message[0].sub_plan == "3000") { - addTime(endingTime, seconds_added_per_giftsub_tier3_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier3_happy} Seconds Because ${event.message[0].gifter} Gifted A Tier 3 Sub`); - } - else { - addTime(endingTime, seconds_added_per_giftsub_tier1_happy); - logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier1_happy} Seconds Because ${event.message[0].gifter} Gifted A Tier 1 Sub`); - } - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } + else if (event.message[0].sub_plan == "2000") { + addTime(endingTime, seconds_added_per_giftsub_tier2 * factor_t2_local); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier2 * factor_t2_local} Seconds Because ${event.message[0].gifter} Gifted A Tier 2 Sub`); + } + else if (event.message[0].sub_plan == "3000") { + addTime(endingTime, seconds_added_per_giftsub_tier3 * factor_t3_local); + logMessage("Streamlabs", `Added ${seconds_added_per_giftsub_tier3 * factor_t3_local} Seconds Because ${event.message[0].gifter} Gifted A Tier 3 Sub`); + } + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); } } } else if (event.type == "donation") { if (!countdownEnded && donationEnable) { - if(!happy_hour_active){ - let dono = parseInt(event.message[0].amount); - let currency = event.message[0].currency; - if (dono >= min_donation_amount) { - let times = Math.floor(dono/min_donation_amount); - addTime(endingTime, seconds_added_per_donation * times); - logMessage("Streamlabs", `Added ${seconds_added_per_donation * times} Seconds Because ${event.message[0].name} Donated ${dono} ${currency}`); - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } - } - } - else if(happy_hour_active){ - let dono = parseInt(event.message[0].amount); - let currency = event.message[0].currency; - if (dono >= min_donation_amount) { - let times = Math.floor(dono/min_donation_amount); - addTime(endingTime, seconds_added_per_donation_happy * times); - logMessage("Streamlabs", `Added ${seconds_added_per_donation_happy * times} Seconds Because ${event.message[0].name} Donated ${dono} ${currency}`); - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } + let dono = parseInt(event.message[0].amount); + let currency = event.message[0].currency; + if (dono >= min_donation_amount) { + let times = Math.floor(dono/min_donation_amount); + addTime(endingTime, seconds_added_per_donation * times * factor_donations_local); + logMessage("Streamlabs", `Added ${seconds_added_per_donation * times} Seconds Because ${event.message[0].name} Donated ${dono} ${currency}`); + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); } } } @@ -179,26 +98,13 @@ if (streamlabs_token !== "") { else if (event.type == "bits") { if (!countdownEnded && donationEnable) { - if(!happy_hour_active){ - let bits = parseInt(event.message[0].amount); - if (bits >= min_amount_of_bits) { - let times = Math.floor(bits/min_amount_of_bits); - addTime(endingTime, seconds_added_per_bits * times); - logMessage("Streamlabs", `Added ${seconds_added_per_bits * times} Seconds Because ${event.message[0].name} Donated ${bits} Bits`); - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } - } - } - else if(happy_hour_active){ - let bits = parseInt(event.message[0].amount); - if (bits >= min_amount_of_bits) { - let times = Math.floor(bits/min_amount_of_bits); - addTime(endingTime, seconds_added_per_bits_happy * times); - logMessage("Streamlabs", `Added ${seconds_added_per_bits_happy * times} Seconds Because ${event.message[0].name} Donated ${bits} Bits`); - if (!users.includes(event.message[0].name)) { - users.push(event.message[0].name); - } + let bits = parseInt(event.message[0].amount); + if (bits >= min_amount_of_bits) { + let times = Math.floor(bits/min_amount_of_bits); + addTime(endingTime, seconds_added_per_bits * times); + logMessage("Streamlabs", `Added ${seconds_added_per_bits * times * factor_bits_local} Seconds Because ${event.message[0].name} Donated ${bits} Bits`); + if (!users.includes(event.message[0].name)) { + users.push(event.message[0].name); } } } diff --git a/js/api/twitch.js b/js/api/twitch.js index 9e0182e..36122a2 100644 --- a/js/api/twitch.js +++ b/js/api/twitch.js @@ -12,45 +12,27 @@ if (twitch_channel_name !== "") { client.on('subscription', (channel, username, methods, message, userstate) => { if (!countdownEnded && subEnable) { - if(!happy_hour_active){ - switch (methods['plan']) { - case "Prime": - addTime(endingTime, seconds_added_per_sub_prime); - logMessage("Twitch", `Added ${seconds_added_per_sub_prime} Seconds Because ${username} Subscribed With Prime`); - break; - case "1000": - addTime(endingTime, seconds_added_per_sub_tier1); - logMessage("Twitch", `Added ${seconds_added_per_sub_tier1} Seconds Because ${username} Subscribed With Tier 1`); - break; - case "2000": - addTime(endingTime, seconds_added_per_sub_tier2); - logMessage("Twitch", `Added ${seconds_added_per_sub_tier2} Seconds Because ${username} Subscribed With Tier 2`); - break; - case "3000": - addTime(endingTime, seconds_added_per_sub_tier3); - logMessage("Twitch", `Added ${seconds_added_per_sub_tier3} Seconds Because ${username} Subscribed With Tier 3`); - break; - } - } - else if(happy_hour_active){ - switch (methods['plan']) { - case "Prime": - addTime(endingTime, seconds_added_per_sub_prime_happy); - logMessage("Twitch", `Added ${seconds_added_per_sub_prime_happy} Seconds Because ${username} Subscribed With Prime`); - break; - case "1000": - addTime(endingTime, seconds_added_per_sub_tier1_happy); - logMessage("Twitch", `Added ${seconds_added_per_sub_tier1_happy} Seconds Because ${username} Subscribed With Tier 1`); - break; - case "2000": - addTime(endingTime, seconds_added_per_sub_tier2_happy); - logMessage("Twitch", `Added ${seconds_added_per_sub_tier2_happy} Seconds Because ${username} Subscribed With Tier 2`); - break; - case "3000": - addTime(endingTime, seconds_added_per_sub_tier3_happy); - logMessage("Twitch", `Added ${seconds_added_per_sub_tier3_happy} Seconds Because ${username} Subscribed With Tier 3`); - break; - } + let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); + let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); + let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); + + switch (methods['plan']) { + case "Prime": + addTime(endingTime, seconds_added_per_sub_prime * factor_t1_local); + logMessage("Twitch", `Added ${seconds_added_per_sub_prime * factor_t1_local} Seconds Because ${username} Subscribed With Prime`); + break; + case "1000": + addTime(endingTime, seconds_added_per_sub_tier1 * factor_t1_local); + logMessage("Twitch", `Added ${seconds_added_per_sub_tier1 * factor_t1_local} Seconds Because ${username} Subscribed With Tier 1`); + break; + case "2000": + addTime(endingTime, seconds_added_per_sub_tier2 * factor_t2_local); + logMessage("Twitch", `Added ${seconds_added_per_sub_tier2 * factor_t2_local} Seconds Because ${username} Subscribed With Tier 2`); + break; + case "3000": + addTime(endingTime, seconds_added_per_sub_tier3 * factor_t3_local); + logMessage("Twitch", `Added ${seconds_added_per_sub_tier3 * factor_t3_local} Seconds Because ${username} Subscribed With Tier 3`); + break; } if (!users.includes(username)) { users.push(username); @@ -60,45 +42,27 @@ if (twitch_channel_name !== "") { client.on('resub', (channel, username, months, message, userstate, methods) => { if (!countdownEnded && subEnable) { - if(!happy_hour_active){ - switch (methods['plan']) { - case "Prime": - addTime(endingTime, seconds_added_per_resub_prime); - logMessage("Twitch", `Added ${seconds_added_per_resub_prime} Seconds Because ${username} ReSubscribed With Prime`); - break; - case "1000": - addTime(endingTime, seconds_added_per_resub_tier1); - logMessage("Twitch", `Added ${seconds_added_per_resub_tier1} Seconds Because ${username} ReSubscribed With Tier 1`); - break; - case "2000": - addTime(endingTime, seconds_added_per_resub_tier2); - logMessage("Twitch", `Added ${seconds_added_per_resub_tier2} Seconds Because ${username} ReSubscribed With Tier 2`); - break; - case "3000": - addTime(endingTime, seconds_added_per_resub_tier3); - logMessage("Twitch", `Added ${seconds_added_per_resub_tier3} Seconds Because ${username} ReSubscribed With Tier 3`); - break; - } - } - else if(happy_hour_active){ - switch (methods['plan']) { - case "Prime": - addTime(endingTime, seconds_added_per_resub_prime_happy); - logMessage("Twitch", `Added ${seconds_added_per_resub_prime_happy} Seconds Because ${username} ReSubscribed With Prime`); - break; - case "1000": - addTime(endingTime, seconds_added_per_resub_tier1_happy); - logMessage("Twitch", `Added ${seconds_added_per_resub_tier1_happy} Seconds Because ${username} ReSubscribed With Tier 1`); - break; - case "2000": - addTime(endingTime, seconds_added_per_resub_tier2_happy); - logMessage("Twitch", `Added ${seconds_added_per_resub_tier2_happy} Seconds Because ${username} ReSubscribed With Tier 2`); - break; - case "3000": - addTime(endingTime, seconds_added_per_resub_tier3_happy); - logMessage("Twitch", `Added ${seconds_added_per_resub_tier3_happy} Seconds Because ${username} ReSubscribed With Tier 3`); - break; - } + let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); + let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); + let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); + + switch (methods['plan']) { + case "Prime": + addTime(endingTime, seconds_added_per_resub_prime * factor_t1_local); + logMessage("Twitch", `Added ${seconds_added_per_resub_prime * factor_t1_local} Seconds Because ${username} ReSubscribed With Prime`); + break; + case "1000": + addTime(endingTime, seconds_added_per_resub_tier1 * factor_t1_local); + logMessage("Twitch", `Added ${seconds_added_per_resub_tier1 * factor_t1_local} Seconds Because ${username} ReSubscribed With Tier 1`); + break; + case "2000": + addTime(endingTime, seconds_added_per_resub_tier2 * factor_t2_local); + logMessage("Twitch", `Added ${seconds_added_per_resub_tier2 * factor_t2_local} Seconds Because ${username} ReSubscribed With Tier 2`); + break; + case "3000": + addTime(endingTime, seconds_added_per_resub_tier3 * factor_t3_local); + logMessage("Twitch", `Added ${seconds_added_per_resub_tier3 * factor_t3_local} Seconds Because ${username} ReSubscribed With Tier 3`); + break; } if (!users.includes(username)) { users.push(username); @@ -108,45 +72,27 @@ if (twitch_channel_name !== "") { client.on('subgift', (channel, username, months, recipient, methods, userstate) => { if (!countdownEnded && subEnable) { - if(!happy_hour_active){ - switch (methods['plan']) { - case "Prime": - addTime(endingTime, seconds_added_per_giftsub_prime); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_prime} Seconds Because ${username} gifted Sub With Prime`); - break; - case "1000": - addTime(endingTime, seconds_added_per_giftsub_tier1); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier1} Seconds Because ${username} gifted Sub With Tier 1`); - break; - case "2000": - addTime(endingTime, seconds_added_per_giftsub_tier2); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier2} Seconds Because ${username} gifted Sub With Tier 2`); - break; - case "3000": - addTime(endingTime, seconds_added_per_giftsub_tier3); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier3} Seconds Because ${username} gifted Sub With Tier 3`); - break; - } - } - else if(happy_hour_active){ - switch (methods['plan']) { - case "Prime": - addTime(endingTime, seconds_added_per_giftsub_prime_happy); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_prime_happy} Seconds Because ${username} gifted Sub With Prime`); - break; - case "1000": - addTime(endingTime, seconds_added_per_giftsub_tier1_happy); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier1_happy} Seconds Because ${username} gifted Sub With Tier 1`); - break; - case "2000": - addTime(endingTime, seconds_added_per_giftsub_tier2_happy); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier2_happy} Seconds Because ${username} gifted Sub With Tier 2`); - break; - case "3000": - addTime(endingTime, seconds_added_per_giftsub_tier3_happy); - logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier3_happy} Seconds Because ${username} gifted Sub With Tier 3`); - break; - } + let factor_t1_local = (happy_hour_active ? factor_t1 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t1): 1); + let factor_t2_local = (happy_hour_active ? factor_t2 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t2): 1); + let factor_t3_local = (happy_hour_active ? factor_t3 : 1) * (random_hour_active ? randomInRangeNoRounding(...range_t3): 1); + + switch (methods['plan']) { + case "Prime": + addTime(endingTime, seconds_added_per_giftsub_prime * factor_t1_local); + logMessage("Twitch", `Added ${seconds_added_per_giftsub_prime * factor_t1_local} Seconds Because ${username} gifted Sub With Prime`); + break; + case "1000": + addTime(endingTime, seconds_added_per_giftsub_tier1 * factor_t1_local); + logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier1 * factor_t1_local} Seconds Because ${username} gifted Sub With Tier 1`); + break; + case "2000": + addTime(endingTime, seconds_added_per_giftsub_tier2 * factor_t2_local); + logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier2 * factor_t2_local} Seconds Because ${username} gifted Sub With Tier 2`); + break; + case "3000": + addTime(endingTime, seconds_added_per_giftsub_tier3 * factor_t3_local); + logMessage("Twitch", `Added ${seconds_added_per_giftsub_tier3 * factor_t3_local} Seconds Because ${username} gifted Sub With Tier 3`); + break; } if (!users.includes(username)) { users.push(username); @@ -156,24 +102,14 @@ if (twitch_channel_name !== "") { client.on('cheer', (channel, userstate, message) => { if (!countdownEnded && bitEnable) { - if(!happy_hour_active){ - if (userstate.bits >= min_amount_of_bits) { - let times = Math.floor(userstate.bits/min_amount_of_bits); - addTime(endingTime, seconds_added_per_bits * times); - logMessage("Twitch", `Added ${seconds_added_per_bits * times} Seconds Because ${userstate['display-name']} Donated ${userstate.bits} Bits`); - if (!users.includes(userstate['display-name'])) { - users.push(userstate['display-name']); - } - } - } - if(happy_hour_active){ - if (userstate.bits >= min_amount_of_bits) { - let times = Math.floor(userstate.bits/min_amount_of_bits); - addTime(endingTime, seconds_added_per_bits_happy * times); - logMessage("Twitch", `Added ${seconds_added_per_bits_happy * times} Seconds Because ${userstate['display-name']} Donated ${userstate.bits} Bits`); - if (!users.includes(userstate['display-name'])) { - users.push(userstate['display-name']); - } + let factor_bits_local = (happy_hour_active ? factor_bits : 1) * (random_hour_active ? randomInRangeNoRounding(...range_bits): 1); + + if (userstate.bits >= min_amount_of_bits) { + let times = Math.floor(userstate.bits/min_amount_of_bits); + addTime(endingTime, seconds_added_per_bits * times * factor_bits_local); + logMessage("Twitch", `Added ${seconds_added_per_bits * times} Seconds Because ${userstate['display-name']} Donated ${userstate.bits} Bits`); + if (!users.includes(userstate['display-name'])) { + users.push(userstate['display-name']); } } } diff --git a/js/lib/generalFunc.js b/js/lib/generalFunc.js index 86a4a06..02d6c29 100644 --- a/js/lib/generalFunc.js +++ b/js/lib/generalFunc.js @@ -6,10 +6,16 @@ const randomInRange = (min, max) => { return Math.floor(Math.random() * (max - min)) + min; }; +const randomInRangeNoRounding = (min, max) => { + return Math.random() * (max - min) + min; +}; + const logMessage = (module, message) => { console.log(`[${module}]: ${message}`); }; const logObject = (module, object) => { console.log(`[${module}]: `, object); -}; \ No newline at end of file +}; + + diff --git a/js/script.js b/js/script.js index bd866f1..2524f4a 100644 --- a/js/script.js +++ b/js/script.js @@ -230,18 +230,19 @@ var addedTimeCounter; var timeoutID; const addTime = async (time, s) => { + let addedTime = Math.floor(s); if(!bulk_enabled) { endingTimeBeforeCounter = time; - addedTimeCounter = s; + addedTimeCounter = addedTime; addTimeInternal(); return; } if(firstSub) { firstSub = false; endingTimeBeforeCounter = time; - addedTimeCounter = s; + addedTimeCounter = addedTime; } else { - addedTimeCounter += s; + addedTimeCounter += addedTime; window.clearTimeout(timeoutID); } timeoutID = window.setTimeout(addTimeInternal, 1000);