]> git.localhorst.tv Git - alttp.git/blob - app/DiscordBotCommands/ResultCommand.php
fix reevaluate command class name
[alttp.git] / app / DiscordBotCommands / ResultCommand.php
1 <?php
2
3 namespace App\DiscordBotCommands;
4
5 use App\Models\DiscordBotCommand;
6 use Discord\Discord;
7 use Discord\Parts\Channel\Channel;
8 use Discord\Parts\Channel\Message;
9 use Discord\Parts\User\Member;
10
11 class ResultCommand extends BaseCommand {
12
13         public function __construct(Discord $discord, DiscordBotCommand $cmd) {
14                 parent::__construct($discord, $cmd);
15         }
16
17         public function execute() {
18                 if (!$this->hasRoundChannels()) {
19                         return \React\Promise\resolve();
20                 }
21                 return $this->fetchRoundChannel()
22                         ->then(function (Channel $channel) {
23                                 return $this->fetchMember();
24                         })
25                         ->then(function (Member $member) {
26                                 return $this->roundChannel->setPermissions($member, [
27                                         'view_channel',
28                                 ]);
29                         })
30                         ->then(function () {
31                                 $user = $this->getUser();
32                                 $round = $this->getRound();
33                                 $result = $user->findResult($round);
34                                 $msg = '';
35                                 if (!$result || $result->forfeit) {
36                                         $msg = __('discord_commands.result.forfeit', ['name' => $user->getName()]);
37                                 } else {
38                                         $msg = __('discord_commands.result.finish', ['name' => $user->getName(), 'time' => $result->formatTime()]);
39                                 }
40                                 return $this->roundChannel->sendMessage($msg);
41                         });
42         }
43
44 }