X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FTwitchBot%2FIRCMessage.php;h=89aa023a1230c2ca74ba108c315a72a8d5b88434;hb=e5192dadab765ecf0cdb877e0497293e0c9f1e45;hp=c0acfbb547cc2d205fff7ef5420fdfbe07ce9ad1;hpb=898d01d4ac5ccaa23621abda0761a893ff8c1074;p=alttp.git diff --git a/app/TwitchBot/IRCMessage.php b/app/TwitchBot/IRCMessage.php index c0acfbb..89aa023 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; @@ -125,6 +127,15 @@ class IRCMessage { return $str; } + public function log() { + ChatLog::create([ + 'command' => $this->command, + 'nick' => $this->nick, + 'params' => $this->params, + 'tags' => $this->tags, + ]); + } + public static function join($channels) { $msg = new IRCMessage(); $msg->command = 'JOIN'; @@ -132,6 +143,28 @@ class IRCMessage { return $msg; } + public static function part($channels) { + $msg = new IRCMessage(); + $msg->command = 'PART'; + $msg->params[] = implode(',', $channels); + 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'; + $msg->params[] = $target; + $msg->params[] = $message; + return $msg; + } + public function getPrivMsgTarget() { if (!empty($this->params)) { return $this->params[0]; @@ -154,10 +187,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';