]> git.localhorst.tv Git - alttp.git/blob - app/TwitchBot/GuessingSolveCommand.php
simple guessing game
[alttp.git] / app / TwitchBot / GuessingSolveCommand.php
1 <?php
2
3 namespace App\TwitchBot;
4
5 class GuessingSolveCommand extends ChatCommand {
6
7         public function execute($args) {
8                 if (!$this->channel->hasActiveGuessing()) {
9                         $this->messageChannel('Channel has no active guessing game');
10                         return;
11                 }
12                 if (empty($args)) {
13                         $this->messageChannel('Please provide a solution to the guessing game');
14                         return;
15                 }
16                 if (!$this->channel->isValidGuess($args)) {
17                         $this->messageChannel('Please provide a valid solution to the guessing game');
18                         return;
19                 }
20                 $winners = $this->channel->solveGuessing($args);
21                 $names = [];
22                 foreach ($winners as $winner) {
23                         if ($winner->score > 0) {
24                                 $names[] = $winner->uname;
25                         }
26                 }
27                 if (empty($names)) {
28                         $this->messageChannel('nobody wins :(');
29                 } else {
30                         $this->messageChannel('Congrats '.$this->listAnd($names));
31                 }
32                 $this->channel->clearGuessing();
33         }
34
35 }
36
37 ?>