From: Daniel Karbach Date: Thu, 11 Apr 2024 12:20:22 +0000 (+0200) Subject: more classifications X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=a45390fd150b79014088b343591dc701dfe89c13;p=alttp.git more classifications --- diff --git a/app/TwitchBot/TokenizedMessage.php b/app/TwitchBot/TokenizedMessage.php index 42d6ca8..61ca5c8 100644 --- a/app/TwitchBot/TokenizedMessage.php +++ b/app/TwitchBot/TokenizedMessage.php @@ -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')) { diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index 479a9ab..ebf2b94 100644 --- a/app/TwitchBot/TwitchChatBot.php +++ b/app/TwitchBot/TwitchChatBot.php @@ -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(); } diff --git a/resources/js/components/twitch-bot/Controls.js b/resources/js/components/twitch-bot/Controls.js index 9c5701e..f3f551c 100644 --- a/resources/js/components/twitch-bot/Controls.js +++ b/resources/js/components/twitch-bot/Controls.js @@ -18,8 +18,12 @@ const CHAT_CATEGORIES = [ 'hi', 'gl', 'gg', + 'eyes', 'love', 'lol', + 'rage', + 'sad', + 'sweat', 'wtf', 'pog', 'hype', diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index a88d150..2e13f7c 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -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', diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 9563eed..8770273 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -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', diff --git a/tests/Unit/TwitchBot/TokenizedMessageTest.php b/tests/Unit/TwitchBot/TokenizedMessageTest.php index 37e516a..be38909 100644 --- a/tests/Unit/TwitchBot/TokenizedMessageTest.php +++ b/tests/Unit/TwitchBot/TokenizedMessageTest.php @@ -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());