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 return new RandomChatCommand($bot, $cmd);
22 throw new \Exception('unrecognized command');
26 public abstract function execute();
28 protected function __construct(TwitchBot $bot, TwitchBotCommand $cmd) {
30 $this->command = $cmd;
31 if ($cmd->tournament && $cmd->tournament->locale) {
32 App::setLocale($cmd->tournament->locale);
36 protected function getParameter($name) {
37 return $this->command->parameters[$name];
40 protected function getUser() {
41 if (!$this->hasParameter('user')) {
42 throw new \Exception('no user in parameters');
44 return User::findOrFail($this->getParameter('user'));
47 protected function getExecutingUser() {
48 return $this->command->user;
51 protected function hasParameter($name) {
52 return array_key_exists($name, $this->command->parameters);