]> git.localhorst.tv Git - alttp.git/blob - app/TwitchBot/GuessingSolveCommand.php
b4a877d5b45d8b9378bb0cab431830872d46f6ec
[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                         $msg = $this->channel->getGuessingSetting('not_active_message');
10                         $this->messageChannel($msg);
11                         return;
12                 }
13                 if (empty($args) || !$this->channel->isValidGuess($args)) {
14                         $msg = $this->channel->getGuessingSetting('invalid_solution_message');
15                         $this->messageChannel($msg);
16                         return;
17                 }
18                 $winners = $this->channel->solveGuessing($args);
19                 $names = [];
20                 foreach ($winners as $winner) {
21                         if ($winner->score > 0) {
22                                 $names[] = $winner->uname;
23                         }
24                 }
25                 if (empty($names)) {
26                         $msg = $this->channel->getGuessingSetting('no_winners_message');
27                         $this->messageChannel($msg);
28                 } else {
29                         $msg = $this->channel->getGuessingSetting('winners_message');
30                         $msg = str_replace('{names}', $this->listAnd($names), $msg);
31                         $this->messageChannel($msg);
32                 }
33                 $this->channel->clearGuessing();
34         }
35
36 }
37
38 ?>