]> git.localhorst.tv Git - alttp.git/blobdiff - app/DiscordBotCommands/ResultCommand.php
discord result command
[alttp.git] / app / DiscordBotCommands / ResultCommand.php
diff --git a/app/DiscordBotCommands/ResultCommand.php b/app/DiscordBotCommands/ResultCommand.php
new file mode 100644 (file)
index 0000000..bfe35bd
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+namespace App\DiscordBotCommands;
+
+use App\Models\DiscordBotCommand;
+use Discord\Discord;
+use Discord\Parts\Channel\Channel;
+use Discord\Parts\Channel\Message;
+use Discord\Parts\User\Member;
+
+class ResultCommand extends BaseCommand {
+
+       public function __construct(Discord $discord, DiscordBotCommand $cmd) {
+               parent::__construct($discord, $cmd);
+       }
+
+       public function execute() {
+               if (!$this->hasRoundChannels()) {
+                       return \React\Promise\resolve();
+               }
+               return $this->fetchRoundChannel()
+                       ->then(function (Channel $channel) {
+                               return $this->fetchMember();
+                       })
+                       ->then(function (Member $member) {
+                               return $this->roundChannel->setPermissions($member, [
+                                       'view_channel',
+                               ]);
+                       })
+                       ->then(function () {
+                               $user = $this->getUser();
+                               $round = $this->getRound();
+                               $result = $user->findResult($round);
+                               $msg = '';
+                               if (!$result || $result->forfeit) {
+                                       $msg = __('discord_commands.result.forfeit', ['name' => $user->getName()]);
+                               } else {
+                                       $msg = __('discord_commands.result.finish', ['name' => $user->getName(), 'time' => $result->formatTime()]);
+                               }
+                               return $this->roundChannel->sendMessage($msg);
+                       });
+       }
+
+}