]> git.localhorst.tv Git - alttp.git/blobdiff - app/TwitchBot/TwitchChatBot.php
update dunkatracker
[alttp.git] / app / TwitchBot / TwitchChatBot.php
index 700de25bfb86bff91542b0f95f98f43bb4af9f80..7b505ed8c48341d61d9733934c56b33d3ac3c0ea 100644 (file)
@@ -46,6 +46,22 @@ class TwitchChatBot extends TwitchBot {
                $this->tagChannelRead($channel, $msg);
        }
 
+       public function handleRoomstate(IRCMessage $msg) {
+               $channel = $this->getMessageChannel($msg);
+               if ($channel && $msg->hasTag('emote-only')) {
+                       $oldEmote = $this->getNote($channel, 'emote_only');
+                       $newEmote = !!intval($msg->getTag('emote-only'));
+                       if ($oldEmote != $newEmote) {
+                               $this->setNote($channel, 'emote_only', $newEmote);
+                       }
+               }
+       }
+
+       public function handleWhisper(IRCMessage $msg) {
+               $text = $this->chatlib->generate($msg->getText());
+               $this->sendWhisper($msg->tags['user-id'], $text);
+       }
+
        public function getChatlibDatabase(Channel $channel) {
                return $this->chatlib;
        }
@@ -104,6 +120,7 @@ class TwitchChatBot extends TwitchBot {
        private function getNotes(Channel $channel) {
                if (!isset($this->notes[$channel->id])) {
                        $this->notes[$channel->id] = [
+                               'emote_only' => false,
                                'last_read' => 0,
                                'last_special' => [],
                                'last_write' => time(),
@@ -198,9 +215,12 @@ class TwitchChatBot extends TwitchBot {
        }
 
        private function randomChat(Channel $channel) {
-               return $channel->queryChatlog()
-                       ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7'])
-                       ->first();
+               $query = $channel->queryChatlog()
+                       ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7']);
+               if ($this->getNote($channel, 'emote_only', false)) {
+                       $query->where('emote_only', '=', true);
+               }
+               return $query->first();
        }
 
        private function randomContextualNumber(Channel $channel) {
@@ -253,7 +273,11 @@ class TwitchChatBot extends TwitchBot {
        }
 
        private function randomMsg(Channel $channel) {
-               return $channel->queryChatlog()->first();
+               $query = $channel->queryChatlog();
+               if ($this->getNote($channel, 'emote_only', false)) {
+                       $query->where('emote_only', '=', true);
+               }
+               return $query->first();
        }
 
        private function performAdlib(Channel $channel) {