X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchAppBot.php;h=13499f5d46b38d5913e3994e43ce09dc43250a15;hb=f6408dcec11bb63eb1c996d73ebf5629335e25aa;hp=4e2c7d493ff5050c36fa6d0ed37dcfeb0fb0260b;hpb=85879ea0c27ce6506919e2c083a139c470c0952c;p=alttp.git diff --git a/app/TwitchBot/TwitchAppBot.php b/app/TwitchBot/TwitchAppBot.php index 4e2c7d4..13499f5 100644 --- a/app/TwitchBot/TwitchAppBot.php +++ b/app/TwitchBot/TwitchAppBot.php @@ -3,7 +3,6 @@ namespace App\TwitchBot; use App\Models\Channel; -use App\Models\TwitchBotCommand; class TwitchAppBot extends TwitchBot { @@ -19,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->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) { @@ -33,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()); } @@ -52,18 +67,4 @@ class TwitchAppBot extends TwitchBot { } } - - private function listenCommands() { - $this->getLoop()->addPeriodicTimer(1, function () { - if (!$this->isReady()) return; - $command = TwitchBotCommand::where('status', '=', 'pending')->oldest()->first(); - if ($command) { - try { - $command->execute($this); - } catch (\Exception $e) { - } - } - }); - } - }