]> git.localhorst.tv Git - alttp.git/blobdiff - app/TwitchBot/IRCMessage.php
full stepladder schedule sync command
[alttp.git] / app / TwitchBot / IRCMessage.php
index 4fb54c670b7a8890e89af029f6dc9b649efb42cc..35ac2783910f5f5a5c0bd0d6c3e85eaed94a4a78 100644 (file)
@@ -35,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;
                        }
@@ -67,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);
@@ -93,6 +93,7 @@ class IRCMessage {
                                } else {
                                        $str .= ';';
                                }
+                               // TODO: this may need some kind of encoding?
                                $str .= $name.'=';
                                if (!empty($value)) {
                                        $str .= $value;
@@ -136,6 +137,17 @@ class IRCMessage {
                ]);
        }
 
+       public function tokenize() {
+               return TokenizedMessage::fromIRC($this);
+       }
+
+       public static function capReq($cap) {
+               $msg = new IRCMessage();
+               $msg->command = 'CAP REQ';
+               $msg->params[] = $cap;
+               return $msg;
+       }
+
        public static function join($channels) {
                $msg = new IRCMessage();
                $msg->command = 'JOIN';
@@ -195,12 +207,28 @@ class IRCMessage {
                return $this->command == 'PRIVMSG';
        }
 
+       public function isRoomstate() {
+               return $this->command == 'ROOMSTATE';
+       }
+
+       public function isWhisper() {
+               return $this->command == 'WHISPER';
+       }
+
        public function isOwner() {
                return substr($this->getPrivMsgTarget(), 1) == $this->nick;
        }
 
        public function isMod() {
-               return $this->isOwner() || (isset($this->tags['mod']) && $this->tags['mod'] = '1');
+               return $this->isOwner() || (isset($this->tags['mod']) && $this->tags['mod'] == '1');
+       }
+
+       public function hasTag($name) {
+               return array_key_exists($name, $this->tags);
+       }
+
+       public function getTag($name) {
+               return $this->tags[$name];
        }
 
        public function makePong() {