From 13ffde5b2abcf831af9c794044350737066c5933 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 11 Apr 2024 12:04:54 +0200 Subject: [PATCH] more classification --- .../Commands/ReevaluateChatCommand.php | 61 +++++++++++++++++++ app/TwitchBot/TokenizedMessage.php | 2 +- app/TwitchBot/TwitchChatBot.php | 4 ++ .../js/components/twitch-bot/Controls.js | 15 ++++- resources/js/i18n/de.js | 4 ++ resources/js/i18n/en.js | 4 ++ tests/Unit/TwitchBot/TokenizedMessageTest.php | 1 + 7 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 app/Console/Commands/ReevaluateChatCommand.php diff --git a/app/Console/Commands/ReevaluateChatCommand.php b/app/Console/Commands/ReevaluateChatCommand.php new file mode 100644 index 0000000..69a8374 --- /dev/null +++ b/app/Console/Commands/ReevaluateChatCommand.php @@ -0,0 +1,61 @@ +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; + } + +} diff --git a/app/TwitchBot/TokenizedMessage.php b/app/TwitchBot/TokenizedMessage.php index 0e241d5..82b4d47 100644 --- a/app/TwitchBot/TokenizedMessage.php +++ b/app/TwitchBot/TokenizedMessage.php @@ -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'; diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index 5b067a6..479a9ab 100644 --- a/app/TwitchBot/TwitchChatBot.php +++ b/app/TwitchBot/TwitchChatBot.php @@ -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; diff --git a/resources/js/components/twitch-bot/Controls.js b/resources/js/components/twitch-bot/Controls.js index 51f0633..9c5701e 100644 --- a/resources/js/components/twitch-bot/Controls.js +++ b/resources/js/components/twitch-bot/Controls.js @@ -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); diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 8a24991..a88d150 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -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', diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index f33d4f0..9563eed 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -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', diff --git a/tests/Unit/TwitchBot/TokenizedMessageTest.php b/tests/Unit/TwitchBot/TokenizedMessageTest.php index 6fe2e0d..37e516a 100644 --- a/tests/Unit/TwitchBot/TokenizedMessageTest.php +++ b/tests/Unit/TwitchBot/TokenizedMessageTest.php @@ -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()); -- 2.39.2