X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=app%2FTwitchBot%2FTokenizedMessage.php;fp=app%2FTwitchBot%2FTokenizedMessage.php;h=259cfc6a33f20759f4f6a817e0f10df51232a290;hb=6a643908d58f26272c2095616514a140e7c0b4c0;hp=0000000000000000000000000000000000000000;hpb=29ee4d076868ce530e94a4dcea5d5cf8be772571;p=alttp.git diff --git a/app/TwitchBot/TokenizedMessage.php b/app/TwitchBot/TokenizedMessage.php new file mode 100644 index 0000000..259cfc6 --- /dev/null +++ b/app/TwitchBot/TokenizedMessage.php @@ -0,0 +1,133 @@ +text = $text; + $this->tags = $tags; + $this->raw = strtolower(preg_replace('/[^\w]/', '', $text)); + $this->tokens = preg_split('/\s+/', strtolower(trim($text))); + + $this->emoteless = $this->text; + if (isset($this->tags['emotes']) && !empty($this->tags['emotes'])) { + $emotes = explode('/', $this->tags['emotes']); + foreach ($emotes as $emote) { + $set = explode(':', $emote); + $positions = explode(',', $set[1]); + foreach ($positions as $position) { + $coords = explode('-', $position); + $this->emotes[] = substr($this->text, $coords[0], $coords[1] - $coords[0] + 1); + for ($i = intval($coords[0]); $i <= intval($coords[1]); ++$i) { + $this->emoteless[$i] = ' '; + } + } + } + $this->emoteless = trim(preg_replace('/\s+/', ' ', $this->emoteless)); + } + $this->emoteless_tokens = preg_split('/\s+/', strtolower($this->emoteless)); + } + + public static function fromIRC(IRCMessage $msg) { + return new self($msg->getText(), $msg->tags); + } + + public static function fromLog(ChatLog $log) { + return new self($log->params[1], $log->tags); + } + + public static function fromString($text, $tags = []) { + return new self($text, $tags); + } + + + public function getNumericValue() { + return intval($this->raw); + } + + public function isSpammy() { + if (substr($this->raw, 0, 1) == '!') { + return true; + } + if (strpos($this->raw, '$') !== false) { + return true; + } + if (strpos($this->raw, '€') !== false) { + return true; + } + if (strpos($this->raw, '@') !== false) { + return true; + } + if (strpos($this->raw, '://') !== false) { + return true; + } + if (strpos($this->raw, 'followers') !== false) { + return true; + } + if (strpos($this->raw, 'horstie') !== false) { + return true; + } + if (strpos($this->raw, 'promotion') !== false) { + return true; + } + if (strpos($this->raw, 'viewers') !== false) { + return true; + } + if (strpos($this->raw, 'view ers') !== false) { + return true; + } + if (strpos($this->raw, 'vielen dank für den raid') !== false) { + return true; + } + if (strpos($this->raw, 'willkommen auf starbase 47') !== false) { + return true; + } + return false; + } + + + public function classify() { + if (is_null($this->classification)) { + if (empty($this->raw)) { + $this->classification = 'unclassified'; + } else if (is_numeric($this->raw)) { + $this->classification = 'number'; + } else if (Str::startsWith($this->raw, 'gg') || Str::endsWith($this->raw, 'gg')) { + $this->classification = 'gg'; + } else if (Str::contains($this->raw, ['glgl', 'glhf', 'hfgl'])) { + $this->classification = 'gl'; + } else if (Str::contains($this->raw, ['haha', 'hehe', 'hihi', 'kekw', 'lol', 'lul', 'xd'])) { + $this->classification = 'lol'; + } else if (Str::startsWith($this->raw, ['ahoi', 'hallo', 'hello', 'hi ', 'huhu']) || Str::endsWith($this->raw, ['hi', 'wave'])) { + $this->classification = 'hi'; + } else if (Str::contains($this->raw, ['pog', 'wow'])) { + $this->classification = 'pog'; + } else if (Str::contains($this->raw, ['hype'])) { + $this->classification = 'hype'; + } else if (Str::startsWith($this->raw, 'o7') || Str::endsWith($this->raw, 'o7') || Str::contains($this->raw, 'salut')) { + $this->classification = 'o7'; + } else { + $this->classification = 'unclassified'; + } + } + return $this->classification; + } + + + private $text; + private $tags; + private $raw; + private $tokens; + + private $emotes = []; + private $emoteless = ''; + private $emoteless_tokens = []; + + private $classification = null; + +}