X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchAppBot.php;h=a103a8847316c3ff8595a85a13a5459ea94e1f1b;hb=771f1761f0abec996838c0ccc71cec0219bad71a;hp=ce0f75112558563f9cf7f8e7866082e50bc850e9;hpb=06fbdc15c8db57590c9b6a38ee1f00d5f349cff9;p=alttp.git diff --git a/app/TwitchBot/TwitchAppBot.php b/app/TwitchBot/TwitchAppBot.php index ce0f751..a103a88 100644 --- a/app/TwitchBot/TwitchAppBot.php +++ b/app/TwitchBot/TwitchAppBot.php @@ -18,23 +18,40 @@ 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->isAcceptingGuesses() && + !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) { $cmd = explode(' ', ltrim($msg->getText(), '!'), 2); - if (!isset($channel->chat_commands[$cmd[0]])) return; - $config = $channel->chat_commands[$cmd[0]]; - $this->getLogger()->info('got command '.$cmd[0].' on channel '.$channel->title); + $cmd_name = strtolower($cmd[0]); + if (!isset($channel->chat_commands[$cmd_name])) return; + $config = $channel->chat_commands[$cmd_name]; + $this->getLogger()->info('got command '.$cmd_name.' 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()); + $this->getLogger()->warning('error executing command '.$cmd_name.' on channel '.$channel->title.': '.$e->getMessage()); } }