]> git.localhorst.tv Git - alttp.git/blobdiff - app/TwitchBot/TwitchAppBot.php
simple guessing game
[alttp.git] / app / TwitchBot / TwitchAppBot.php
index ce0f75112558563f9cf7f8e7866082e50bc850e9..04d03e609cb6ecd007df3927d467e25de89b249f 100644 (file)
@@ -18,11 +18,25 @@ class TwitchAppBot extends TwitchBot {
        public function handlePrivMsg(IRCMessage $msg) {
                $target = $msg->getPrivMsgTarget();
                if ($target[0] != '#') return; // direct message
-               $text = $msg->getText();
-               if ($text[0] != '!') return;
                $channel = $this->getMessageChannel($msg);
                if (!$channel) return;
-               $this->handleChatCommand($channel, $msg);
+               $text = $msg->getText();
+               if ($text[0] == '!') {
+                       $this->handleChatCommand($channel, $msg);
+               } else if (
+                       $channel->hasActiveGuessing() &&
+                       !empty($msg->tags['user-id']) &&
+                       !empty($msg->tags['display-name'] &&
+                       $channel->isValidGuess($text))
+               ) {
+                       $uid = 't:'.$msg->tags['user-id'];
+                       $uname = $msg->tags['display-name'];
+                       try {
+                               $channel->registerGuess($uid, $uname, $text);
+                       } catch (\Exception $e) {
+                               $this->getLogger()->warning('error registering guess "'.$text.'" on channel '.$channel->title.': '.$e->getMessage());
+                       }
+               }
        }
 
        public function handleChatCommand(Channel $channel, IRCMessage $msg) {
@@ -32,7 +46,9 @@ class TwitchAppBot extends TwitchBot {
                $this->getLogger()->info('got command '.$cmd[0].' on channel '.$channel->title);
                try {
                        $command = ChatCommand::create($this, $channel, $config);
-                       $command->execute($cmd[1] ?? '');
+                       if ($command->checkAccess($msg)) {
+                               $command->execute($cmd[1] ?? '');
+                       }
                } catch (\Exception $e) {
                        $this->getLogger()->warning('error executing command '.$cmd[0].' on channel '.$channel->title.': '.$e->getMessage());
                }