From: Daniel Karbach Date: Fri, 7 Jun 2024 22:13:13 +0000 (+0200) Subject: add up to 4 player support for zsr sync X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=HEAD;hp=4c72d4b8bec61eba5b3dc43df5eafd890e123d37;p=alttp.git add up to 4 player support for zsr sync --- diff --git a/.editorconfig b/.editorconfig index 1671c9b..49dd9a0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/app/Console/Commands/SyncSpeedGaming.php b/app/Console/Commands/SyncSpeedGaming.php index 41286ce..1b4c80e 100644 --- a/app/Console/Commands/SyncSpeedGaming.php +++ b/app/Console/Commands/SyncSpeedGaming.php @@ -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; diff --git a/app/Console/Commands/SyncZSR.php b/app/Console/Commands/SyncZSR.php index 1d92110..b7719e2 100644 --- a/app/Console/Commands/SyncZSR.php +++ b/app/Console/Commands/SyncZSR.php @@ -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) { diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 32e5c8a..14c7840 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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(); diff --git a/app/Models/ChatLib.php b/app/Models/ChatLib.php index a87c6a7..c7a19b6 100644 --- a/app/Models/ChatLib.php +++ b/app/Models/ChatLib.php @@ -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', diff --git a/app/TwitchBot/TokenizedMessage.php b/app/TwitchBot/TokenizedMessage.php index 4b7d758..b460020 100644 --- a/app/TwitchBot/TokenizedMessage.php +++ b/app/TwitchBot/TokenizedMessage.php @@ -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; diff --git a/resources/js/components/common/ChannelSelect.js b/resources/js/components/common/ChannelSelect.js index a69662f..355b02b 100644 --- a/resources/js/components/common/ChannelSelect.js +++ b/resources/js/components/common/ChannelSelect.js @@ -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); }; }, []); diff --git a/resources/js/components/common/DiscordChannelSelect.js b/resources/js/components/common/DiscordChannelSelect.js index fd5fe8d..01ee3b0 100644 --- a/resources/js/components/common/DiscordChannelSelect.js +++ b/resources/js/components/common/DiscordChannelSelect.js @@ -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); }; }, []); diff --git a/resources/js/components/common/DiscordSelect.js b/resources/js/components/common/DiscordSelect.js index 65c94d6..9ac7b56 100644 --- a/resources/js/components/common/DiscordSelect.js +++ b/resources/js/components/common/DiscordSelect.js @@ -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); }; }, []); diff --git a/resources/js/components/common/UserSelect.js b/resources/js/components/common/UserSelect.js index 03aa097..32bd186 100644 --- a/resources/js/components/common/UserSelect.js +++ b/resources/js/components/common/UserSelect.js @@ -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); }; }, []); diff --git a/tests/Unit/TwitchBot/TokenizedMessageTest.php b/tests/Unit/TwitchBot/TokenizedMessageTest.php index 832b970..be5da8d 100644 --- a/tests/Unit/TwitchBot/TokenizedMessageTest.php +++ b/tests/Unit/TwitchBot/TokenizedMessageTest.php @@ -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());