X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FDiscordBotCommands%2FBaseCommand.php;h=e6861e03dad79666eaaeb726db05b8d48a862165;hb=07a88747f8a252b41b739185fcb68bdee3a60f9a;hp=eb3a012561c9bdc8f6e6faae8145797fff51e3be;hpb=66e57699b8055ef8a65a1be55b05301c811090bb;p=alttp.git diff --git a/app/DiscordBotCommands/BaseCommand.php b/app/DiscordBotCommands/BaseCommand.php index eb3a012..e6861e0 100644 --- a/app/DiscordBotCommands/BaseCommand.php +++ b/app/DiscordBotCommands/BaseCommand.php @@ -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; }