X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FTwitchBot.php;h=63f4236f685e92bf659610257e93177a78cf7a11;hb=771f1761f0abec996838c0ccc71cec0219bad71a;hp=79b6bf13f1861af5bde63e400992cbc060e08ae0;hpb=85879ea0c27ce6506919e2c083a139c470c0952c;p=alttp.git diff --git a/app/TwitchBot/TwitchBot.php b/app/TwitchBot/TwitchBot.php index 79b6bf1..63f4236 100644 --- a/app/TwitchBot/TwitchBot.php +++ b/app/TwitchBot/TwitchBot.php @@ -3,6 +3,7 @@ namespace App\TwitchBot; use App\Models\Channel; +use App\Models\TwitchBotCommand; use App\Models\TwitchToken; use Monolog\Handler\StreamHandler; use Monolog\Logger; @@ -22,6 +23,9 @@ class TwitchBot { if (!$this->token) { throw new \Exception('unable to find access token'); } + if ($this->token->hasExpired()) { + $this->token->refresh(); + } $this->connector = new Connector(); $this->connect(); @@ -155,7 +159,7 @@ class TwitchBot { if (!$this->ready) return; if (time() - $this->last_contact < 60) return; try { - $this->sendIRCMessage(IRCMessage::ping()); + $this->sendIRCMessage(IRCMessage::ping($this->nick)); } catch (\Exception $e) { } }); @@ -169,6 +173,20 @@ class TwitchBot { } + protected function listenCommands() { + $this->getLoop()->addPeriodicTimer(1, function () { + if (!$this->isReady()) return; + $command = TwitchBotCommand::where('bot_nick', '=', $this->nick)->where('status', '=', 'pending')->oldest()->first(); + if ($command) { + try { + $command->execute($this); + } catch (\Exception $e) { + } + } + }); + } + + private $logger; private $nick;