]> 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 b043af2ecd7f06da98e242381ebf3ceda3f7361f..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');
                }
@@ -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;
 
 }