]> git.localhorst.tv Git - alttp.git/blobdiff - app/TwitchBot/IRCMessage.php
fix reevaluate command class name
[alttp.git] / app / TwitchBot / IRCMessage.php
index 1e64bd9b6de7c12c0674ce7966e06adbd914f0b0..0f73c06797a79b4694215dbe09a380392e56620f 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);
@@ -136,6 +136,10 @@ class IRCMessage {
                ]);
        }
 
+       public function tokenize() {
+               return TokenizedMessage::fromIRC($this);
+       }
+
        public static function join($channels) {
                $msg = new IRCMessage();
                $msg->command = 'JOIN';
@@ -195,6 +199,14 @@ class IRCMessage {
                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';