]> git.localhorst.tv Git - alttp.git/commitdiff
guessing game leaderboard
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 29 Feb 2024 16:01:37 +0000 (17:01 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 29 Feb 2024 16:01:37 +0000 (17:01 +0100)
app/Models/Channel.php
app/TwitchBot/ChatCommand.php
app/TwitchBot/GuessingLeaderboardCommand.php [new file with mode: 0644]
resources/js/components/twitch-bot/CommandForm.js
resources/js/i18n/de.js
resources/js/i18n/en.js

index 738312dc3e82a60d6725a0289f2886a11b3dcc2e..edc2ba8664be682bc3638fbb16e485b905ca55a1 100644 (file)
@@ -16,6 +16,10 @@ class Channel extends Model
                        ->first();
        }
 
+       public function getGuessingLeaderboard() {
+               return $this->winners()->selectRaw('(select t2.uname from guessing_winners t2 where t2.uid = guessing_winners.uid order by created_at desc limit 1) as name, sum(score) as score')->groupBy('uid')->orderBy('score', 'desc')->limit(10)->get();
+       }
+
        public function hasActiveGuessing() {
                return !is_null($this->guessing_start);
        }
@@ -149,6 +153,10 @@ class Channel extends Model
                return $this->belongsTo(Organization::class);
        }
 
+       public function winners() {
+               return $this->hasMany(GuessingWinner::class);
+       }
+
        protected $casts = [
                'chat' => 'boolean',
                'chat_commands' => 'array',
index 8e6fbe1e7f1fa9c7b1c09b2e6e1552417c9079df..b00f0cf17d845b858544dde6aac76f9361475d21 100644 (file)
@@ -16,6 +16,9 @@ abstract class ChatCommand {
                        case 'guessing-cancel':
                                $cmd = new GuessingCancelCommand();
                                break;
+                       case 'guessing-leaderboard':
+                               $cmd = new GuessingLeaderboardCommand();
+                               break;
                        case 'guessing-solve':
                                $cmd = new GuessingSolveCommand();
                                break;
diff --git a/app/TwitchBot/GuessingLeaderboardCommand.php b/app/TwitchBot/GuessingLeaderboardCommand.php
new file mode 100644 (file)
index 0000000..2b12109
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+namespace App\TwitchBot;
+
+class GuessingLeaderboardCommand extends ChatCommand {
+
+       public function execute($args) {
+               $leaderboard = $this->channel->getGuessingLeaderboard();
+               $msg = '';
+               foreach ($leaderboard as $entry) {
+                       if (!empty($msg)) {
+                               $msg .= ', ';
+                       }
+                       $msg .= $entry->name.' ('.$entry->score.')';
+               }
+               $this->messageChannel($msg);
+       }
+
+}
+
+?>
index 9e9586a62197bb559ce1c54f671083d6cb8a367f..d9221708f486bcbe77477220c01e3d15b4683fd8 100644 (file)
@@ -27,6 +27,7 @@ const CommandForm = ({
                'guessing-stop',
                'guessing-solve',
                'guessing-cancel',
+               'guessing-leaderboard',
        ];
        const RESTRICTIONS = [
                'none',
index b9496952887c60f601dfcc08d83f8c80d6c0eaa1..9b7a0f33531afbc9b42646c141fec6489008cd84 100644 (file)
@@ -516,6 +516,7 @@ export default {
                        commandTypes: {
                                crew: 'Crew Liste',
                                'guessing-cancel': 'Guessing Game abbrechen',
+                               'guessing-leaderboard': 'Guessing Game Leaderboard',
                                'guessing-solve': 'Guessing Game auflösen',
                                'guessing-start': 'Guessing Game starten',
                                'guessing-stop': 'Guessing Game stoppen',
index 695530d9ccb133051bd67e3cbd8e1a23a8e66ff1..2bcbe91cea3af81444c507eaba3fa718c1505478 100644 (file)
@@ -516,6 +516,7 @@ export default {
                        commandTypes: {
                                crew: 'Crew list',
                                'guessing-cancel': 'Cancel guessing game',
+                               'guessing-leaderboard': 'Guessing game leaderboard',
                                'guessing-solve': 'Solve guessing game',
                                'guessing-start': 'Start guessing game',
                                'guessing-stop': 'Stop guessing game',