X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FIRCMessage.php;h=0f73c06797a79b4694215dbe09a380392e56620f;hb=ac6921da72ff4b0beab9e5f1308788a55aae3ad9;hp=c730ef7d0bfa962126417f7b513e7adc46984b9b;hpb=e10222af705e3475fcea6e0b17d1c9984a62db26;p=alttp.git diff --git a/app/TwitchBot/IRCMessage.php b/app/TwitchBot/IRCMessage.php index c730ef7..0f73c06 100644 --- a/app/TwitchBot/IRCMessage.php +++ b/app/TwitchBot/IRCMessage.php @@ -2,6 +2,8 @@ namespace App\TwitchBot; +use App\Models\ChatLog; + class IRCMessage { public $command = null; @@ -33,7 +35,7 @@ class IRCMessage { $has_host = false; $prefix = explode(' ', $processed, 2); $processed = $prefix[1]; - $prefix = ltrim($prefix[0], ':'); + $prefix = $prefix[0][0] === ':' ? substr($prefix[0], 1) : $prefix[0]; if (strpos($prefix, '!') !== false) { $has_user = true; } @@ -65,7 +67,7 @@ class IRCMessage { while (strlen($processed)) { if ($processed[0] == ':') { - $msg->params[] = ltrim($processed, ':'); + $msg->params[] = substr($processed, 1); break; } $e = explode(' ', $processed, 2); @@ -125,6 +127,19 @@ class IRCMessage { return $str; } + public function log() { + ChatLog::create([ + 'command' => $this->command, + 'nick' => $this->nick, + 'params' => $this->params, + 'tags' => $this->tags, + ]); + } + + public function tokenize() { + return TokenizedMessage::fromIRC($this); + } + public static function join($channels) { $msg = new IRCMessage(); $msg->command = 'JOIN'; @@ -139,6 +154,13 @@ class IRCMessage { return $msg; } + public static function ping($token = 'localhorsttv') { + $msg = new IRCMessage(); + $msg->command = 'PING'; + $msg->params[] = $token; + return $msg; + } + public static function privmsg($target, $message) { $msg = new IRCMessage(); $msg->command = 'PRIVMSG'; @@ -169,10 +191,22 @@ class IRCMessage { return $this->command == 'PING'; } + public function isPong() { + return $this->command == 'PONG'; + } + public function isPrivMsg() { return $this->command == 'PRIVMSG'; } + public function isOwner() { + return substr($this->getPrivMsgTarget(), 1) == $this->nick; + } + + public function isMod() { + return $this->isOwner() || (isset($this->tags['mod']) && $this->tags['mod'] == '1'); + } + public function makePong() { $msg = new IRCMessage(); $msg->command = 'PONG';