]> git.localhorst.tv Git - alttp.git/commitdiff
more classifications
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 11 Apr 2024 12:20:22 +0000 (14:20 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 11 Apr 2024 12:20:22 +0000 (14:20 +0200)
app/TwitchBot/TokenizedMessage.php
app/TwitchBot/TwitchChatBot.php
resources/js/components/twitch-bot/Controls.js
resources/js/i18n/de.js
resources/js/i18n/en.js
tests/Unit/TwitchBot/TokenizedMessageTest.php

index 42d6ca8ca8f08c05cc625e3b32df236ef4683932..61ca5c8dee40d346e575342e7494512ac055a562 100644 (file)
@@ -9,10 +9,10 @@ use Illuminate\Support\Str;
 class TokenizedMessage {
 
        public function __construct($text, $tags = []) {
-               $this->text = $text;
+               $this->text = trim($text);
                $this->tags = $tags;
-               $this->raw = strtolower(preg_replace('/[^\w]/u', '', $text));
-               $this->tokens = array_values(array_map('trim', array_filter(preg_split('/\b/', strtolower($text)))));
+               $this->raw = strtolower(preg_replace('/[^\w]/u', '', $this->text));
+               $this->tokens = array_values(array_map('trim', array_filter(preg_split('/\b/', strtolower($this->text)))));
 
                $this->emoteless = $this->text;
                if (isset($this->tags['emotes']) && !empty($this->tags['emotes'])) {
@@ -224,7 +224,7 @@ class TokenizedMessage {
 
        public function classify() {
                if (is_null($this->classification)) {
-                       if (empty($this->raw)) {
+                       if (empty($this->text)) {
                                $this->classification = 'unclassified';
                        } else if ($this->startsWith('!')) {
                                $this->classification = 'cmd';
@@ -246,6 +246,14 @@ class TokenizedMessage {
                                $this->classification = 'love';
                        } else if ($this->hasToken(['nani', 'wat', 'wtf']) || $this->hasEmoteThatEndsWith(['wat', 'wtf'])) {
                                $this->classification = 'wtf';
+                       } else if ($this->hasConsecutiveTokens([':', 'eyes', ':']) || $this->hasEmoteThatEndsWith(['eyes'])) {
+                               $this->classification = 'eyes';
+                       } else if ($this->hasEmoteThatEndsWith(['angry', 'rage', 'ree'])) {
+                               $this->classification = 'rage';
+                       } else if ($this->hasToken([':(']) || $this->hasEmoteThatEndsWith(['cry', 'sad'])) {
+                               $this->classification = 'sad';
+                       } else if ($this->hasToken(['monkas', 'sweat_smile']) || $this->hasEmoteThatEndsWith(['sweat'])) {
+                               $this->classification = 'sweat';
                        } else if ($this->endsWithEmoteless('?')) {
                                $this->classification = 'question';
                        } else if ($this->startsOrEndsWithRaw(['o7']) || $this->hasEmoteThatContains('salut')) {
index 479a9ab5eef2ebd5e793c2421e5959e9f4f972bc..ebf2b94af14d2da6175f578a55f759c1cd9fd515 100644 (file)
@@ -176,7 +176,7 @@ class TwitchChatBot extends TwitchBot {
 
        private function randomChat(Channel $channel) {
                return $channel->queryChatlog()
-                       ->whereIn('classification', ['hi', 'hype', 'lol', 'pog', 'unclassified'])
+                       ->whereNotIn('classification', ['gg', 'gl', 'o7'])
                        ->first();
        }
 
index 9c5701ef8fb5336eb246ad089a991eed6b45567f..f3f551cb9ca4e1fd8ca4f1ffe320ef162bb9649d 100644 (file)
@@ -18,8 +18,12 @@ const CHAT_CATEGORIES = [
        'hi',
        'gl',
        'gg',
+       'eyes',
        'love',
        'lol',
+       'rage',
+       'sad',
+       'sweat',
        'wtf',
        'pog',
        'hype',
index a88d1505037d11a87b71e3456fd2bb0545039765..2e13f7c561b7fc030bbc26847e8550ed46556c78 100644 (file)
@@ -687,6 +687,7 @@ export default {
                        channel: 'Channel',
                        chat: 'Chat',
                        chatCategories: {
+                               eyes: 'Augen',
                                gg: 'Good Game',
                                gl: 'Good Luck',
                                hi: 'Begrüßung',
@@ -696,6 +697,9 @@ export default {
                                o7: 'Salutieren',
                                pog: 'Pog',
                                question: 'Frage',
+                               rage: 'Zorn',
+                               sad: 'Traurig',
+                               sweat: 'Schwitzen',
                                thx: 'Danke',
                                unclassified: 'Generisch',
                                wtf: 'WTF',
index 9563eedfeaba7f474b2a614a354e4945de1e9b1c..8770273af32ec2dd1beb8cdc9c8deb6d9e2050da 100644 (file)
@@ -687,6 +687,7 @@ export default {
                        channel: 'Channel',
                        chat: 'Chat',
                        chatCategories: {
+                               eyes: 'Eyes',
                                gg: 'Good Game',
                                gl: 'Good Luck',
                                hi: 'Greeting',
@@ -696,6 +697,9 @@ export default {
                                o7: 'Salute',
                                pog: 'Pog',
                                question: 'Question',
+                               rage: 'Rage',
+                               sad: 'Sad',
+                               sweat: 'Sweat',
                                thx: 'Thanks',
                                unclassified: 'Generic',
                                wtf: 'WTF',
index 37e516a032f099c6aea3a977db11252a266a025f..be38909a07d06a9d111fd33b6a6297102d3a4c65 100644 (file)
@@ -10,10 +10,14 @@ class TokenizedMessageTest extends TestCase {
        public function test_classification() {
                $this->assertEquals('cmd', TokenizedMessage::fromString('!start')->classify());
 
+               $this->assertEquals('eyes', TokenizedMessage::fromString(':eyes:')->classify());
+               $this->assertEquals('eyes', TokenizedMessage::fromString('holysm3Eyes', ['emotes' => 'blah:0-11'])->classify());
+
                $this->assertEquals('gg', TokenizedMessage::fromString('gg')->classify());
                $this->assertEquals('gg', TokenizedMessage::fromString('GG')->classify());
                $this->assertEquals('gg', TokenizedMessage::fromString('Gg')->classify());
                $this->assertEquals('gg', TokenizedMessage::fromString('ggs')->classify());
+               $this->assertEquals('gg', TokenizedMessage::fromString('gg monkaS')->classify());
                $this->assertEquals('gg', TokenizedMessage::fromString('ja gg dann, ne')->classify());
                $this->assertEquals('gg', TokenizedMessage::fromString('duden2Gg', ['emotes' => 'blah:0-7'])->classify());
                $this->assertEquals('gg', TokenizedMessage::fromString('ticknaGg2', ['emotes' => 'blah:0-8'])->classify());
@@ -48,8 +52,15 @@ class TokenizedMessageTest extends TestCase {
                $this->assertEquals('pog', TokenizedMessage::fromString('Pog')->classify());
                $this->assertNotEquals('pog', TokenizedMessage::fromString('wo war der')->classify());
 
+               $this->assertEquals('rage', TokenizedMessage::fromString('duden2Rage', ['emotes' => 'blah:0-10'])->classify());
+
                $this->assertEquals('question', TokenizedMessage::fromString('Joaaa geht so ...und selbst?')->classify());
 
+               $this->assertEquals('sad', TokenizedMessage::fromString(':(')->classify());
+               $this->assertEquals('sad', TokenizedMessage::fromString('PoroSad', ['emotes' => 'blah:0-7'])->classify());
+
+               $this->assertEquals('sweat', TokenizedMessage::fromString('monkaS')->classify());
+
                $this->assertEquals('thx', TokenizedMessage::fromString('danke für den tipp')->classify());
 
                $this->assertEquals('wtf', TokenizedMessage::fromString('wtf? lol')->classify());