]> git.localhorst.tv Git - alttp.git/commitdiff
add up to 4 player support for zsr sync master
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 7 Jun 2024 22:13:13 +0000 (00:13 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 7 Jun 2024 22:13:13 +0000 (00:13 +0200)
.editorconfig
app/Console/Commands/SyncSpeedGaming.php
app/Console/Commands/SyncZSR.php
app/Console/Kernel.php
app/Models/ChatLib.php
app/TwitchBot/TokenizedMessage.php
resources/js/components/common/ChannelSelect.js
resources/js/components/common/DiscordChannelSelect.js
resources/js/components/common/DiscordSelect.js
resources/js/components/common/UserSelect.js
tests/Unit/TwitchBot/TokenizedMessageTest.php

index 1671c9b9d94ae80b2d39c6b6a64d154b0ac6cb65..49dd9a03b887df8a23ae51087f658488962135f4 100644 (file)
@@ -4,7 +4,7 @@ root = true
 charset = utf-8
 end_of_line = lf
 insert_final_newline = true
-indent_style = space
+indent_style = tab
 indent_size = 4
 trim_trailing_whitespace = true
 
index 41286ce95f2971ece8ce61877f9540214dd9a6e8..1b4c80e9a3ea1c83153eb2a61f40e5ca0e11a800 100644 (file)
@@ -207,7 +207,7 @@ class SyncSpeedGaming extends Command {
                }
                $channel->short_name = $sgChannel['initials'];
                $channel->title = $sgChannel['name'];
-               $channel->stream_link = 'https://twitch.tv/'.strtolower($sgChannel['name']);
+               $channel->stream_link = 'https://twitch.tv/'.strtolower($sgChannel['slug']);
                $channel->languages = [$sgChannel['language']];
                $channel->save();
                return $channel;
index 1d9211025020e204b7f5dd5a725c800d1f0e578b..b7719e25c244f53e0b0452bc785e1b0e4a0cd46c 100644 (file)
@@ -88,17 +88,6 @@ class SyncZSR extends Command {
                } else {
                        $episode->title = $entry['summary'];
                }
-               if (preg_match('/Restream: https?:\/\/(www\.)?twitch\.tv\/(\w+)/u', $entry['description'], $matches)) {
-                       $channel = $this->syncChannel($episode, $matches[2]);
-                       if ($channel) {
-                               $episode->channels()->syncWithoutDetaching([$channel->id]);
-                       }
-               }
-               if (preg_match('/^(.*) - (.*?) vs (.*?)$/u', $episode->title, $matches)) {
-                       $episode->title = $matches[1];
-                       $this->syncPlayer($episode, $matches[2]);
-                       $this->syncPlayer($episode, $matches[3]);
-               }
                $start = Carbon::parse($entry['start']['dateTime'])->setTimezone('UTC');
                if (!$episode->start || $start->ne($episode->start)) {
                        $episode->start = $start;
@@ -106,7 +95,33 @@ class SyncZSR extends Command {
                $end = Carbon::parse($entry['end']['dateTime'])->setTimezone('UTC');
                $episode->estimate = $start->diffInSeconds($end);
                $episode->confirmed = true;
-               $episode->save();
+               if (preg_match('/^(.*) - (.*?) vs\.? (.*?) vs\.? (.*?) vs\.? (.*?)$/u', $episode->title, $matches)) {
+                       $episode->title = $matches[1];
+                       $episode->save();
+                       $this->syncPlayer($episode, $matches[2]);
+                       $this->syncPlayer($episode, $matches[3]);
+                       $this->syncPlayer($episode, $matches[4]);
+                       $this->syncPlayer($episode, $matches[5]);
+               } else if (preg_match('/^(.*) - (.*?) vs\.? (.*?) vs\.? (.*?)$/u', $episode->title, $matches)) {
+                       $episode->title = $matches[1];
+                       $episode->save();
+                       $this->syncPlayer($episode, $matches[2]);
+                       $this->syncPlayer($episode, $matches[3]);
+                       $this->syncPlayer($episode, $matches[4]);
+               } else if (preg_match('/^(.*) - (.*?) vs\.? (.*?)$/u', $episode->title, $matches)) {
+                       $episode->title = $matches[1];
+                       $episode->save();
+                       $this->syncPlayer($episode, $matches[2]);
+                       $this->syncPlayer($episode, $matches[3]);
+               } else {
+                       $episode->save();
+               }
+               if (preg_match('/Restream: https?:\/\/(www\.)?twitch\.tv\/(\w+)/u', $entry['description'], $matches)) {
+                       $channel = $this->syncChannel($episode, $matches[2]);
+                       if ($channel) {
+                               $episode->channels()->syncWithoutDetaching([$channel->id]);
+                       }
+               }
        }
 
        private function syncChannel(Episode $episode, $zsrChannel) {
index 32e5c8a0afad44f0309ebe55e7fb4995c90ddc45..14c784032cf28fd76dd4c181a39510cd73056278 100644 (file)
@@ -19,6 +19,7 @@ class Kernel extends ConsoleKernel
                $schedule->command('sync:ladder')->daily();
                $schedule->command('sync:speedgaming')->everyFiveMinutes();
                $schedule->command('sync:sra')->everyFifteenMinutes();
+               $schedule->command('sync:zsr')->everyFifteenMinutes();
                $schedule->command('sync:avatars')->everyFiveMinutes();
                $schedule->command('sync:racetime')->everyFiveMinutes();
                $schedule->command('chat:evaluate 100')->everyMinute();
index a87c6a7e0b04978e93b78b06ff028af782f9d052..c7a19b6998d7acafc09e4fefb2b708ba8087f02f 100644 (file)
@@ -6,7 +6,7 @@ use Illuminate\Support\Facades\Storage;
 
 class ChatLib {
 
-       public function __construct($size = 7) {
+       public function __construct($size = 6) {
                $this->size = $size;
 
                $converted = [];
@@ -39,16 +39,27 @@ class ChatLib {
                                        if ($end - $i < 5) break;
                                }
                        }
+                       $this->addExample(array_slice($tokens, 0, $num), $token);
                }
        }
 
        public function compile() {
-               foreach ($this->transitions as $key => $value) {
-                       $this->transitions[$key] = $this->index($this->transitions[$key]);
+               foreach ($this->transitions as $key => $values) {
+                       $this->transitions[$key] = $this->index($values, 2);
                        if (empty($this->transitions[$key])) {
                                unset($this->transitions[$key]);
                        }
                }
+               foreach ($this->examples as $key => $values) {
+                       if (in_array($key, ['', ' '])) {
+                               unset($this->examples[$key]);
+                               continue;
+                       }
+                       $this->examples[$key] = $this->index($values, 1);
+                       if (empty($this->examples[$key]) || (count($this->examples[$key]) === 1 && $this->examples[$key][0][0] === $key)) {
+                               unset($this->examples[$key]);
+                       }
+               }
        }
 
        public function generate($limit = 100) {
@@ -67,6 +78,7 @@ class ChatLib {
                $data = [
                        'size' => $this->size,
                        'transitions' => $this->transitions,
+                       'examples' => $this->examples,
                ];
                Storage::disk('chatlib')->put($name.'.json', json_encode($data));
        }
@@ -75,28 +87,17 @@ class ChatLib {
                $data = json_decode(Storage::disk('chatlib')->get($name.'.json'), true);
                $this->size = $data['size'];
                $this->transitions = $data['transitions'];
+               $this->examples = $data['examples'];
        }
 
-       private function index($arr) {
+       private function index($arr, $min_weight = 2) {
                $result = [];
                $sum = 0;
-               foreach ($arr as $key => $entry) {
-                       $weight = $entry[0];
-                       if ($weight == 1) continue;
+               foreach ($arr as $key => $weight) {
+                       if ($weight < $min_weight) continue;
                        $lower = $sum;
                        $sum += $weight;
-                       $examples = [];
-                       if ($key === ' ') {
-                               $examples = [[' ', 0, 1]];
-                       } else {
-                               $subsum = 0;
-                               foreach ($entry[1] as $example => $subweight) {
-                                       $sublower = $subsum;
-                                       $subsum += $subweight;
-                                       $examples[] = [$example, $sublower, $subsum];
-                               }
-                       }
-                       $result[] = [$key, $lower, $sum, $examples];
+                       $result[] = [$key, $lower, $sum];
                }
                return $result;
        }
@@ -108,7 +109,7 @@ class ChatLib {
                        if (isset($this->transitions[$cmb])) {
                                $pick = $this->pick($this->transitions[$cmb]);
                                if (!is_null($pick)) {
-                                       return $this->exampleOf($pick);
+                                       return $this->exampleOf($pick, $tokens);
                                }
                        }
                }
@@ -142,28 +143,27 @@ class ChatLib {
        }
 
        private function addTransition($state, $next) {
-               $cmb = $this->generalize($state);
-               if (!isset($this->transitions[$cmb])) {
-                       $this->transitions[$cmb] = [];
+               $ctx = $this->generalize($state);
+               $cmb = $this->generalize([$next]);
+               if (!isset($this->transitions[$ctx])) {
+                       $this->transitions[$ctx] = [];
+               }
+               if (!isset($this->transitions[$ctx][$cmb])) {
+                       $this->transitions[$ctx][$cmb] = 1;
+               } else {
+                       ++$this->transitions[$ctx][$cmb];
                }
-               $this->increment($this->transitions[$cmb], $next);
        }
 
-       private function increment(&$which, $token) {
-               $generalized = $this->generalize([$token]);
-               if (!isset($which[$generalized])) {
-                       $which[$generalized] = [
-                               1,
-                               [],
-                       ];
-                       $which[$generalized][1][$token] = 1;
+       private function addExample($context, $token) {
+               $cmb = $this->generalize([$token]);
+               if (!isset($this->examples[$cmb])) {
+                       $this->examples[$cmb] = [];
+               }
+               if (!isset($this->examples[$cmb][$token])) {
+                       $this->examples[$cmb][$token] = 1;
                } else {
-                       ++$which[$generalized][0];
-                       if (!isset($which[$generalized][1][$token])) {
-                               $which[$generalized][1][$token] = 1;
-                       } else {
-                               ++$which[$generalized][1][$token];
-                       }
+                       ++$this->examples[$cmb][$token];
                }
        }
 
@@ -199,13 +199,20 @@ class ChatLib {
                return $str;
        }
 
-       private function exampleOf($pick) {
-               $example = $this->pick($pick[3]);
-               return $example[0];
+       private function exampleOf($pick, $context) {
+               if (!isset($this->examples[$pick[0]])) {
+                       return $pick[0];
+               }
+               if (isset($this->examples[$pick[0]])) {
+                       $example = $this->pick($this->examples[$pick[0]]);
+                       return $example[0];
+               }
+               return $pick[0];
        }
 
-       private $size = 7;
+       private $size;
        private $transitions = [];
+       private $examples = [];
 
        private $aliases = [
                'chest' => ['kiste'],
@@ -358,6 +365,7 @@ class ChatLib {
                'wave' => [
                        'dennsenhi',
                        'dergoawave',
+                       'falcnwavehi',
                        'heyguys',
                        'holysm0heyguys',
                        'muftaahey',
index 4b7d758221d71aa9a9a3d9cbfdd9cf3cde77cb73..b460020a3e2e2a42a5683cf7ba78c41f1e01792b 100644 (file)
@@ -259,7 +259,16 @@ class TokenizedMessage {
                if ($this->containsRaw('horsti')) {
                        return true;
                }
-               if ($this->containsRaw(['folgtjetzt', 'vielendankfürdenraid', 'thanksfortheraid', 'willkommenaufstarbase47'])) {
+               if ($this->containsRaw([
+                       'folgtjetzt',
+                       'hatdeinenkanalgeraided',
+                       'isnowlivestreaming',
+                       'stürmtdenladenmit',
+                       'thanksfortheraid',
+                       'verschwindetfürneweileindenlurk',
+                       'vielendankfürdenraid',
+                       'willkommenaufstarbase47',
+               ])) {
                        return true;
                }
                return false;
index a69662f423b34e571255e660d86f8775c21e9219..355b02b50d82824d0a3ff7ec6bc1901289c9ee9d 100644 (file)
@@ -29,10 +29,10 @@ const ChannelSelect = ({
                                setShowResults(false);
                        }
                };
-               document.addEventListener('click', handleEventOutside, true);
+               document.addEventListener('mousedown', handleEventOutside, true);
                document.addEventListener('focus', handleEventOutside, true);
                return () => {
-                       document.removeEventListener('click', handleEventOutside, true);
+                       document.removeEventListener('mousedown', handleEventOutside, true);
                        document.removeEventListener('focus', handleEventOutside, true);
                };
        }, []);
index fd5fe8d1c35a3c97a098f98628711831b20c8fa3..01ee3b0fa534a2c1cc8474ad7f6da775995924e5 100644 (file)
@@ -10,9 +10,7 @@ import debounce from '../../helpers/debounce';
 
 const DiscordChannelSelect = ({
        guild,
-       isInvalid,
        name,
-       onBlur,
        onChange,
        types,
        value,
@@ -31,10 +29,10 @@ const DiscordChannelSelect = ({
                                setShowResults(false);
                        }
                };
-               document.addEventListener('click', handleEventOutside, true);
+               document.addEventListener('mousedown', handleEventOutside, true);
                document.addEventListener('focus', handleEventOutside, true);
                return () => {
-                       document.removeEventListener('click', handleEventOutside, true);
+                       document.removeEventListener('mousedown', handleEventOutside, true);
                        document.removeEventListener('focus', handleEventOutside, true);
                };
        }, []);
index 65c94d63cab503893137052ec61d1ccf20456f0c..9ac7b5689cd41d769d768b6dc87e3f19c12beca7 100644 (file)
@@ -23,10 +23,10 @@ const DiscordSelect = ({ onChange, value }) => {
                                setShowResults(false);
                        }
                };
-               document.addEventListener('click', handleEventOutside, true);
+               document.addEventListener('mousedown', handleEventOutside, true);
                document.addEventListener('focus', handleEventOutside, true);
                return () => {
-                       document.removeEventListener('click', handleEventOutside, true);
+                       document.removeEventListener('mousedown', handleEventOutside, true);
                        document.removeEventListener('focus', handleEventOutside, true);
                };
        }, []);
index 03aa097b42c5f7ad22c4c09a0f1f1071bd51f2a5..32bd186f3e82ecc10c9c84b96ab59cee25f0b4fd 100644 (file)
@@ -21,10 +21,10 @@ const UserSelect = ({ name, onChange, value }) => {
                                setShowResults(false);
                        }
                };
-               document.addEventListener('click', handleEventOutside, true);
+               document.addEventListener('mousedown', handleEventOutside, true);
                document.addEventListener('focus', handleEventOutside, true);
                return () => {
-                       document.removeEventListener('click', handleEventOutside, true);
+                       document.removeEventListener('mousedown', handleEventOutside, true);
                        document.removeEventListener('focus', handleEventOutside, true);
                };
        }, []);
index 832b9702cf2a345b82023f022bc592d4b157cdaa..be5da8d97a6bc7dded646a209384b3c7a9e2c825 100644 (file)
@@ -88,6 +88,8 @@ class TokenizedMessageTest extends TestCase {
                $this->assertTrue(TokenizedMessage::fromString('hello would you like some followers?')->isSpammy());
                $this->assertTrue(TokenizedMessage::fromString('get view ers for free')->isSpammy());
 
+               $this->assertTrue(TokenizedMessage::fromString('yayklaygaming verschwindet für \'ne Weile in den Lurk. Cool, dass Du vorbeigeschaut hast xallggCheers PogChamp')->isSpammy());
+               $this->assertTrue(TokenizedMessage::fromString('XallGG is now live! Streaming The Legend of Zelda: A Link to the Past: Casual Boots Seed zum Spaß/Practice')->isSpammy());
                $this->assertTrue(TokenizedMessage::fromString('also bitte, horstie')->isSpammy());
 
                $this->assertTrue(TokenizedMessage::fromString('hey maengi, vielen dank für den raid')->isSpammy());