]> git.localhorst.tv Git - alttp.git/commitdiff
more classification
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 11 Apr 2024 10:04:54 +0000 (12:04 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 11 Apr 2024 10:04:54 +0000 (12:04 +0200)
app/Console/Commands/ReevaluateChatCommand.php [new file with mode: 0644]
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

diff --git a/app/Console/Commands/ReevaluateChatCommand.php b/app/Console/Commands/ReevaluateChatCommand.php
new file mode 100644 (file)
index 0000000..69a8374
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\ChatLog;
+use Illuminate\Console\Command;
+
+class EvaluateChatCommand extends Command {
+
+       /**
+        * The name and signature of the console command.
+        *
+        * @var string
+        */
+       protected $signature = 'chat:reevaluate';
+
+       /**
+        * The console command description.
+        *
+        * @var string
+        */
+       protected $description = 'Reevaluate chat log entries';
+
+       /**
+        * Execute the console command.
+        *
+        * @return int
+        */
+       public function handle() {
+               $good = 0;
+               $bad = 0;
+               ChatLog::where('type', '=', 'chat')
+                       ->where('banned', false)
+                       ->orderBy('created_at')
+                       ->chunk(10000, function ($logs) use (&$good, &$bad) {
+                               foreach ($logs as $line) {
+                                       try {
+                                               $line->evaluate();
+                                               $line->evaluated_at = now();
+                                               $line->save();
+                                               ++$good;
+                                       } catch (\Exception $e) {
+                                               ++$bad;
+                                               $this->error('unable to evaluate line '.$line->id.': '.$e->getMessage());
+                                               $line->type = 'error';
+                                               $line->text_content = $e->getMessage();
+                                               $line->evaluated_at = now();
+                                               $line->save();
+                                       }
+                               }
+                               echo $good;
+                               if ($bad) {
+                                       echo ' +', $bad, ' errors';
+                               }
+                               echo PHP_EOL;
+                       });
+
+               return Command::SUCCESS;
+       }
+
+}
index 0e241d5cd804c490e72f761d01cba7ae70357e5d..82b4d473f1c0761c8b14ac36c2861681561fdabe 100644 (file)
@@ -234,7 +234,7 @@ class TokenizedMessage {
                                $this->classification = 'thx';
                        } else if ($this->hasToken(['<3']) || $this->hasEmoteThatEndsWith(['herz', 'hug', 'love'])) {
                                $this->classification = 'love';
-                       } else if ($this->hasTokenThatStartsWith(['wat', 'wtf']) || $this->hasEmoteThatStartsWith(['wat', 'wtf'])) {
+                       } else if ($this->hasToken(['wat', 'wat?']) || $this->hasTokenThatStartsWith(['wtf']) || $this->hasEmoteThatEndsWith(['wat', 'wtf'])) {
                                $this->classification = 'wtf';
                        } else if ($this->endsWithEmoteless('?')) {
                                $this->classification = 'question';
index 5b067a67bccc7eaf76c2e15031da2df04c3fff8f..479a9ab5eef2ebd5e793c2421e5959e9f4f972bc 100644 (file)
@@ -140,9 +140,11 @@ class TwitchChatBot extends TwitchBot {
                        'hi' => 2,
                        'hype' => 2,
                        'lol' => 2,
+                       'love' => 2,
                        'number' => 2,
                        'pog' => 2,
                        'o7' => 2,
+                       'wtf' => 2,
                ];
                $time_quotas = [
                        'gg' => 600,
@@ -150,9 +152,11 @@ class TwitchChatBot extends TwitchBot {
                        'hi' => 60,
                        'hype' => 60,
                        'lol' => 60,
+                       'love' => 60,
                        'number' => 300,
                        'pog' => 60,
                        'o7' => 300,
+                       'wtf' => 60,
                ];
                foreach ($classifications as $classification => $count) {
                        if ($classification == $last) continue;
index 51f0633a226bdc1f5626a47ee9778ba77d160ac2..9c5701ef8fb5336eb246ad089a991eed6b45567f 100644 (file)
@@ -13,7 +13,20 @@ import ChannelSelect from '../common/ChannelSelect';
 import Icon from '../common/Icon';
 import ToggleSwitch from '../common/ToggleSwitch';
 
-const CHAT_CATEGORIES = ['unclassified', 'hi', 'gl', 'gg', 'lol', 'pog', 'hype', 'o7'];
+const CHAT_CATEGORIES = [
+       'unclassified',
+       'hi',
+       'gl',
+       'gg',
+       'love',
+       'lol',
+       'wtf',
+       'pog',
+       'hype',
+       'o7',
+       'question',
+       'thx',
+];
 
 const Controls = () => {
        const [channel, setChannel] = React.useState(null);
index 8a249913a34d220c6571273280800fed5fc8c906..a88d1505037d11a87b71e3456fd2bb0545039765 100644 (file)
@@ -692,9 +692,13 @@ export default {
                                hi: 'Begrüßung',
                                hype: 'Hype',
                                lol: 'Gelächter',
+                               love: 'Love',
                                o7: 'Salutieren',
                                pog: 'Pog',
+                               question: 'Frage',
+                               thx: 'Danke',
                                unclassified: 'Generisch',
+                               wtf: 'WTF',
                        },
                        chatError: 'Fehler beim Senden',
                        chatSettings: 'Chat Bot Einstellungen',
index f33d4f023cb37e0cb83c136b344d9927285e8cdd..9563eedfeaba7f474b2a614a354e4945de1e9b1c 100644 (file)
@@ -692,9 +692,13 @@ export default {
                                hi: 'Greeting',
                                hype: 'Hype',
                                lol: 'Laughter',
+                               love: 'Love',
                                o7: 'Salute',
                                pog: 'Pog',
+                               question: 'Question',
+                               thx: 'Thanks',
                                unclassified: 'Generic',
+                               wtf: 'WTF',
                        },
                        chatError: 'Error sending message',
                        chatSettings: 'Chat Bot Settings',
index 6fe2e0dd9916583b1d8590819678ada2ca3f2ae8..37e516a032f099c6aea3a977db11252a266a025f 100644 (file)
@@ -53,6 +53,7 @@ class TokenizedMessageTest extends TestCase {
                $this->assertEquals('thx', TokenizedMessage::fromString('danke für den tipp')->classify());
 
                $this->assertEquals('wtf', TokenizedMessage::fromString('wtf? lol')->classify());
+               $this->assertNotEquals('wtf', TokenizedMessage::fromString('ein waterwalk aufgesetzt')->classify());
 
                $this->assertEquals('unclassified', TokenizedMessage::fromString('')->classify());
                $this->assertEquals('unclassified', TokenizedMessage::fromString('bitte boots locked in desert und bib')->classify());