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 JoinCommand($bot, $cmd);
16 return new PartCommand($bot, $cmd);
18 throw new Exception('unrecognized command');
22 public abstract function execute();
24 protected function __construct(TwitchBot $bot, TwitchBotCommand $cmd) {
26 $this->command = $cmd;
27 if ($cmd->tournament && $cmd->tournament->locale) {
28 App::setLocale($cmd->tournament->locale);
32 protected function getParameter($name) {
33 return $this->command->parameters[$name];
36 protected function getUser() {
37 if (!$this->hasParameter('user')) {
38 throw new \Exception('no user in parameters');
40 return User::findOrFail($this->getParameter('user'));
43 protected function hasParameter($name) {
44 return array_key_exists($name, $this->command->parameters);