namespace App\TwitchBot;
+use App\Models\ChatLog;
+
class IRCMessage {
public $command = null;
$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;
}
while (strlen($processed)) {
if ($processed[0] == ':') {
- $msg->params[] = ltrim($processed, ':');
+ $msg->params[] = substr($processed, 1);
break;
}
$e = explode(' ', $processed, 2);
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';
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';
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';