]> git.localhorst.tv Git - alttp.git/commitdiff
prevent repeat special chat
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 11 Apr 2024 07:37:51 +0000 (09:37 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 11 Apr 2024 07:37:51 +0000 (09:37 +0200)
app/TwitchBot/TwitchChatBot.php

index 420e93704490fe804e037697fb070883547b3846..abc1b4518e2b7f528e289643551109c4b135a63a 100644 (file)
@@ -132,7 +132,7 @@ class TwitchChatBot extends TwitchBot {
        }
 
        private function contextualMsg(Channel $channel) {
-               $last = $this->getNote($channel, 'last_special');
+               $last = $this->getLastSpecialSent($channel);
                $classifications = $this->collectClassifications($channel);
                $count_quotas = [
                        'gg' => 2,
@@ -155,6 +155,7 @@ class TwitchChatBot extends TwitchBot {
                        'o7' => 300,
                ];
                foreach ($classifications as $classification => $count) {
+                       if ($classification == $last) continue;
                        if (!isset($count_quotas[$classification]) || $count < $count_quotas[$classification]) continue;
                        if (!isset($time_quotas[$classification]) || $this->getTimeSinceSpecial($channel, $classification) < $time_quotas[$classification]) continue;
                        $this->tagChannelSpecialSent($channel, $classification);
@@ -270,6 +271,19 @@ class TwitchChatBot extends TwitchBot {
                $this->notes[$channel->id]['last_special'][$classification] = time();
        }
 
+       private function getLastSpecialSent(Channel $channel) {
+               $notes = $this->getNotes($channel);
+               $max_time = 0;
+               $max_classification = '';
+               foreach ($notes['last_special'] as $classification => $time) {
+                       if ($time > $max_time) {
+                               $max_time = $time;
+                               $max_classification = $classification;
+                       }
+               }
+               return $max_classification;
+       }
+
        private function getTimeSinceSpecial(Channel $channel, $classification) {
                $notes = $this->getNotes($channel);
                if (isset($notes['last_special'][$classification])) {