->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);
}
return $this->belongsTo(Organization::class);
}
+ public function winners() {
+ return $this->hasMany(GuessingWinner::class);
+ }
+
protected $casts = [
'chat' => 'boolean',
'chat_commands' => 'array',
case 'guessing-cancel':
$cmd = new GuessingCancelCommand();
break;
+ case 'guessing-leaderboard':
+ $cmd = new GuessingLeaderboardCommand();
+ break;
case 'guessing-solve':
$cmd = new GuessingSolveCommand();
break;
--- /dev/null
+<?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);
+ }
+
+}
+
+?>
'guessing-stop',
'guessing-solve',
'guessing-cancel',
+ 'guessing-leaderboard',
];
const RESTRICTIONS = [
'none',
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',
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',