From: Daniel Karbach Date: Fri, 12 Apr 2024 16:30:55 +0000 (+0200) Subject: try to respond more appropriately X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=1b9629ce7f600b4aa9c9d51a281e514031871828;p=alttp.git try to respond more appropriately --- diff --git a/app/Models/Channel.php b/app/Models/Channel.php index 8af6a7d..8045a41 100644 --- a/app/Models/Channel.php +++ b/app/Models/Channel.php @@ -32,6 +32,11 @@ class Channel extends Model { } public function randomOfClass($class) { + if (is_array($class)) { + return $this->queryChatlog() + ->whereIn('classification', $class) + ->first(); + } return $this->queryChatlog() ->where('classification', '=', $class) ->first(); diff --git a/app/TwitchBot/TokenizedMessage.php b/app/TwitchBot/TokenizedMessage.php index 61ca5c8..b03e219 100644 --- a/app/TwitchBot/TokenizedMessage.php +++ b/app/TwitchBot/TokenizedMessage.php @@ -215,7 +215,7 @@ class TokenizedMessage { if ($this->containsRaw('horstie')) { return true; } - if ($this->containsRaw(['vielendankfürdenraid', 'thanksfortheraid', 'willkommenaufstarbase47'])) { + if ($this->containsRaw(['folgtjetzt', 'vielendankfürdenraid', 'thanksfortheraid', 'willkommenaufstarbase47'])) { return true; } return false; @@ -228,20 +228,18 @@ class TokenizedMessage { $this->classification = 'unclassified'; } else if ($this->startsWith('!')) { $this->classification = 'cmd'; - } else if (is_numeric($this->raw)) { - $this->classification = 'number'; } else if ($this->hasTokenThatStartsOrEndsWith(['gg']) || $this->hasEmoteThatEndsWith(['gg'])) { $this->classification = 'gg'; } else if ($this->containsRaw(['glgl', 'glhf', 'goodluck', 'hfgl'])) { $this->classification = 'gl'; + } else if ($this->hasToken(['danke', 'thanks', 'thx', 'ty']) && !$this->hasToken(['nah', 'nee', 'nein', 'no'])) { + $this->classification = 'thx'; } else if ($this->startsWithRaw(['ahoi', 'hallo', 'hello', 'hey', 'huhu', 'moin']) || $this->hasEmoteThatEndsWith(['hello', 'heyguys', 'hi', 'vohiyo', 'wave']) || $this->hasToken(['hi', 'hey', 'yo']) || $this->containsRaw(['gutenmorgen', 'gutenabend'])) { $this->classification = 'hi'; } else if ($this->hasTokenThatStartsOrEndsWith(['pog', 'wow'])) { $this->classification = 'pog'; } else if ($this->containsRaw(['hype']) || $this->hasEmoteThatEndsWith(['dance', 'jam', 'party', 'rave', 'troete'])) { $this->classification = 'hype'; - } else if ($this->hasToken(['danke', 'thanks', 'thx', 'ty'])) { - $this->classification = 'thx'; } else if ($this->hasToken(['<3']) || $this->hasEmoteThatEndsWith(['heart', 'herz', 'hug', 'love'])) { $this->classification = 'love'; } else if ($this->hasToken(['nani', 'wat', 'wtf']) || $this->hasEmoteThatEndsWith(['wat', 'wtf'])) { @@ -256,10 +254,18 @@ class TokenizedMessage { $this->classification = 'sweat'; } else if ($this->endsWithEmoteless('?')) { $this->classification = 'question'; + } else if ($this->hasToken(['ja', 'jo', 'yep', 'yes']) || $this->containsRaw('nodders') || $this->hasEmoteThatEndsWith(['nod', 'nodders', 'yea'])) { + $this->classification = 'yes'; + } else if ($this->hasToken(['nah', 'nee', 'nein', 'no']) || $this->containsRaw('nopers') || $this->hasEmoteThatEndsWith(['nay', 'nope', 'nopers'])) { + $this->classification = 'no'; + } else if ($this->hasEmoteThatContains(['kappa', 'keepo'])) { + $this->classification = 'kappa'; } else if ($this->startsOrEndsWithRaw(['o7']) || $this->hasEmoteThatContains('salut')) { $this->classification = 'o7'; } else if ($this->containsRaw(['haha', 'hehe', 'hihi', 'kekw', 'lol', 'lul']) || $this->hasTokenThatStartsWith(['xd']) || $this->hasConsecutiveTokens([':', 'd'])) { $this->classification = 'lol'; + } else if (is_numeric($this->raw)) { + $this->classification = 'number'; } else { $this->classification = 'unclassified'; } diff --git a/app/TwitchBot/TwitchChatBot.php b/app/TwitchBot/TwitchChatBot.php index ebf2b94..a403b0b 100644 --- a/app/TwitchBot/TwitchChatBot.php +++ b/app/TwitchBot/TwitchChatBot.php @@ -94,6 +94,7 @@ class TwitchChatBot extends TwitchBot { 'last_special' => [], 'last_write' => time(), 'latest_msgs' => [], + 'queued_special' => false, 'read_since_last_write' => 0, 'wait_msgs' => $this->randomWaitMsgs($channel), 'wait_time' => $this->randomWaitTime($channel), @@ -132,6 +133,20 @@ class TwitchChatBot extends TwitchBot { } private function contextualMsg(Channel $channel) { + if ($this->hasQueuedSpecial($channel)) { + $classification = $this->getQueuedSpecial($channel); + if (is_string($classification)) { + $this->tagChannelSpecialSent($channel, $classification); + } + $this->clearQueuedSpecial($channel); + if ($classification == 'number') { + return $this->randomContextualNumber($channel); + } + if ($classification == 'lol') { + return $this->randomLaughter($channel); + } + return $channel->randomOfClass($classification); + } $last = $this->getLastSpecialSent($channel); $classifications = $this->collectClassifications($channel); $count_quotas = [ @@ -176,7 +191,7 @@ class TwitchChatBot extends TwitchBot { private function randomChat(Channel $channel) { return $channel->queryChatlog() - ->whereNotIn('classification', ['gg', 'gl', 'o7']) + ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7']) ->first(); } @@ -245,6 +260,25 @@ class TwitchChatBot extends TwitchBot { return random_int($min, $max); } + private function queueSpecial(Channel $channel, $classification) { + $this->getNotes($channel); + $this->notes[$channel->id]['queued_special'] = $classification; + } + + private function hasQueuedSpecial(Channel $channel) { + return !!$this->getQueuedSpecial($channel); + } + + private function getQueuedSpecial(Channel $channel) { + $notes = $this->getNotes($channel); + return $notes['queued_special']; + } + + private function clearQueuedSpecial(Channel $channel) { + $this->getNotes($channel); + $this->notes[$channel->id]['queued_special'] = false; + } + private function tagChannelRead(Channel $channel, IRCMessage $msg) { $this->getNotes($channel); $this->notes[$channel->id]['last_read'] = time(); @@ -260,6 +294,10 @@ class TwitchChatBot extends TwitchBot { if ($this->isDirectedAtMe($msg->getText()) && $this->shouldRespond($channel)) { $this->notes[$channel->id]['wait_msgs'] = 0; $this->notes[$channel->id]['wait_time'] = 0; + $response = $this->getResponseTo($tokenized); + if ($response) { + $this->queueSpecial($channel, $response); + } } } @@ -316,6 +354,28 @@ class TwitchChatBot extends TwitchBot { return false; } + private function getResponseTo(TokenizedMessage $msg) { + switch ($msg->classify()) { + case 'gg': + return ['love', 'eyes', 'thx', 'pog', 'kappa']; + case 'gl': + return ['love', 'eyes', 'thx']; + case 'hi': + return ['hi', 'love', 'eyes', 'hype', 'pog']; + case 'kappa': + return ['kappa', 'lol', 'eyes']; + case 'love': + return ['hi', 'love', 'eyes', 'thx']; + case 'question': + return ['yes', 'no', 'kappa', 'lol', 'wtf', 'number']; + case 'rage': + return ['kappa', 'lol', 'rage']; + case 'wtf': + return ['kappa', 'lol', 'rage']; + } + return false; + } + private $channels; private $notes = []; diff --git a/resources/js/components/twitch-bot/Controls.js b/resources/js/components/twitch-bot/Controls.js index f3f551c..f64ee62 100644 --- a/resources/js/components/twitch-bot/Controls.js +++ b/resources/js/components/twitch-bot/Controls.js @@ -21,12 +21,15 @@ const CHAT_CATEGORIES = [ 'eyes', 'love', 'lol', + 'yes', + 'no', 'rage', 'sad', 'sweat', 'wtf', 'pog', 'hype', + 'kappa', 'o7', 'question', 'thx', diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 2e13f7c..14f18fa 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -692,8 +692,10 @@ export default { gl: 'Good Luck', hi: 'Begrüßung', hype: 'Hype', + kappa: 'Kappa', lol: 'Gelächter', love: 'Love', + no: 'Nein', o7: 'Salutieren', pog: 'Pog', question: 'Frage', @@ -703,6 +705,7 @@ export default { thx: 'Danke', unclassified: 'Generisch', wtf: 'WTF', + yes: 'Ja', }, chatError: 'Fehler beim Senden', chatSettings: 'Chat Bot Einstellungen', diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 8770273..f696504 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -692,8 +692,10 @@ export default { gl: 'Good Luck', hi: 'Greeting', hype: 'Hype', + kappa: 'Kappa', lol: 'Laughter', love: 'Love', + no: 'No', o7: 'Salute', pog: 'Pog', question: 'Question', @@ -703,6 +705,7 @@ export default { thx: 'Thanks', unclassified: 'Generic', wtf: 'WTF', + yes: 'Yes', }, chatError: 'Error sending message', chatSettings: 'Chat Bot Settings', diff --git a/tests/Unit/TwitchBot/TokenizedMessageTest.php b/tests/Unit/TwitchBot/TokenizedMessageTest.php index be38909..b957746 100644 --- a/tests/Unit/TwitchBot/TokenizedMessageTest.php +++ b/tests/Unit/TwitchBot/TokenizedMessageTest.php @@ -35,6 +35,11 @@ class TokenizedMessageTest extends TestCase { $this->assertEquals('hype', TokenizedMessage::fromString('122 Hype!')->classify()); + $this->assertEquals('kappa', TokenizedMessage::fromString('Kappa', ['emotes' => 'blah:0-4'])->classify()); + $this->assertEquals('kappa', TokenizedMessage::fromString('KappaClaus', ['emotes' => 'blah:0-9'])->classify()); + $this->assertEquals('kappa', TokenizedMessage::fromString('Keepo', ['emotes' => 'blah:0-4'])->classify()); + $this->assertNotEquals('kappa', TokenizedMessage::fromString('I keep order')->classify()); + $this->assertEquals('number', TokenizedMessage::fromString('13')->classify()); $this->assertEquals('number', TokenizedMessage::fromString('22')->classify());