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 AdlibChatCommand($bot, $cmd);
16 return new ChatCommand($bot, $cmd);
18 return new JoinCommand($bot, $cmd);
20 return new PartCommand($bot, $cmd);
22 return new RandomChatCommand($bot, $cmd);
24 throw new \Exception('unrecognized command');
28 public abstract function execute();
30 protected function __construct(TwitchBot $bot, TwitchBotCommand $cmd) {
32 $this->command = $cmd;
33 if ($cmd->tournament && $cmd->tournament->locale) {
34 App::setLocale($cmd->tournament->locale);
38 protected function getParameter($name) {
39 return $this->command->parameters[$name];
42 protected function getUser() {
43 if (!$this->hasParameter('user')) {
44 throw new \Exception('no user in parameters');
46 return User::findOrFail($this->getParameter('user'));
49 protected function getExecutingUser() {
50 return $this->command->user;
53 protected function hasParameter($name) {
54 return array_key_exists($name, $this->command->parameters);