X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FDiscordBotCommands%2FBaseCommand.php;h=e6861e03dad79666eaaeb726db05b8d48a862165;hb=17d105b4d07ce544e94b7f90ff7f50feb86b244f;hp=b043af2ecd7f06da98e242381ebf3ceda3f7361f;hpb=e3880b3664a3916242a8a774a188686dd5c5297f;p=alttp.git diff --git a/app/DiscordBotCommands/BaseCommand.php b/app/DiscordBotCommands/BaseCommand.php index b043af2..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'); } @@ -86,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]; @@ -125,5 +140,6 @@ abstract class BaseCommand { protected $guild = null; protected $member = null; protected $roundChannel = null; + protected $user = null; }