3 namespace App\TwitchBotCommands;
5 use App\Models\TwitchBotCommand;
7 use App\TwitchBot\TwitchBot;
9 abstract class BaseCommand {
11 public static function resolve(TwitchBot $bot, TwitchBotCommand $cmd) {
12 switch ($cmd->command) {
14 return new ChatCommand($bot, $cmd);
16 return new JoinCommand($bot, $cmd);
18 return new PartCommand($bot, $cmd);
20 throw new \Exception('unrecognized command');
24 public abstract function execute();
26 protected function __construct(TwitchBot $bot, TwitchBotCommand $cmd) {
28 $this->command = $cmd;
29 if ($cmd->tournament && $cmd->tournament->locale) {
30 App::setLocale($cmd->tournament->locale);
34 protected function getParameter($name) {
35 return $this->command->parameters[$name];
38 protected function getUser() {
39 if (!$this->hasParameter('user')) {
40 throw new \Exception('no user in parameters');
42 return User::findOrFail($this->getParameter('user'));
45 protected function hasParameter($name) {
46 return array_key_exists($name, $this->command->parameters);