command) { case 'adlib-chat': return new AdlibChatCommand($bot, $cmd); case 'chat': return new ChatCommand($bot, $cmd); case 'join': return new JoinCommand($bot, $cmd); case 'part': return new PartCommand($bot, $cmd); case 'random-chat': return new RandomChatCommand($bot, $cmd); default: throw new \Exception('unrecognized command'); } } public abstract function execute(); protected function __construct(TwitchBot $bot, TwitchBotCommand $cmd) { $this->bot = $bot; $this->command = $cmd; if ($cmd->tournament && $cmd->tournament->locale) { App::setLocale($cmd->tournament->locale); } } protected function getParameter($name) { return $this->command->parameters[$name]; } protected function getUser() { if (!$this->hasParameter('user')) { throw new \Exception('no user in parameters'); } return User::findOrFail($this->getParameter('user')); } protected function getExecutingUser() { return $this->command->user; } protected function hasParameter($name) { return array_key_exists($name, $this->command->parameters); } protected $bot; protected $command; }