]> git.localhorst.tv Git - alttp.git/blobdiff - app/DiscordBotCommands/BaseCommand.php
track twitch category where chats were sent in
[alttp.git] / app / DiscordBotCommands / BaseCommand.php
index eb3a012561c9bdc8f6e6faae8145797fff51e3be..e6861e03dad79666eaaeb726db05b8d48a862165 100644 (file)
@@ -9,6 +9,7 @@ use Discord\Discord;
 use Discord\Parts\Channel\Channel;
 use Discord\Parts\Guild\Guild;
 use Discord\Parts\User\Member;
+use Discord\Parts\User\User as DiscordUser;
 use Illuminate\Support\Facades\App;
 
 abstract class BaseCommand {
@@ -19,6 +20,8 @@ abstract class BaseCommand {
                                return new PresenceCommand($discord, $cmd);
                        case 'result':
                                return new ResultCommand($discord, $cmd);
+                       case 'sync-user':
+                               return new SyncUserCommand($discord, $cmd);
                        default:
                                throw new Exception('unrecognized command');
                }
@@ -30,6 +33,9 @@ abstract class BaseCommand {
        protected function __construct(Discord $discord, DiscordBotCommand $cmd) {
                $this->discord = $discord;
                $this->command = $cmd;
+               if ($cmd->tournament && $cmd->tournament->locale) {
+                       App::setLocale($cmd->tournament->locale);
+               }
        }
 
        protected function fetchGuild() {
@@ -40,7 +46,7 @@ abstract class BaseCommand {
                        ->fetch($this->command->tournament->discord)
                        ->then(function (Guild $guild) {
                                $this->guild = $guild;
-                               if ($guild->preferred_locale) {
+                               if ($guild->preferred_locale && !($this->command->tournament && $this->command->tournament->locale)) {
                                        App::setLocale($guild->preferred_locale);
                                }
                                return $guild;
@@ -83,6 +89,18 @@ abstract class BaseCommand {
                        });
        }
 
+       protected function fetchUser() {
+               if (isset($this->user)) {
+                       return \React\Promise\resolve($this->user);
+               }
+               return $this->discord->users
+                       ->fetch($this->getParameter('user'))
+                       ->then(function (DiscordUser $user) {
+                               $this->user = $user;
+                               return $user;
+                       });
+       }
+
 
        protected function getParameter($name) {
                return $this->command->parameters[$name];
@@ -122,5 +140,6 @@ abstract class BaseCommand {
        protected $guild = null;
        protected $member = null;
        protected $roundChannel = null;
+       protected $user = null;
 
 }