3 namespace App\TwitchBot;
5 use App\Models\Channel;
7 abstract class ChatCommand {
9 public static function create(TwitchBot $bot, Channel $channel, $config) {
11 switch ($config['command']) {
13 $cmd = new CrewCommand();
15 case 'guessing-cancel':
16 $cmd = new GuessingCancelCommand();
18 case 'guessing-leaderboard':
19 $cmd = new GuessingLeaderboardCommand();
21 case 'guessing-solve':
22 $cmd = new GuessingSolveCommand();
24 case 'guessing-start':
25 $cmd = new GuessingStartCommand();
28 $cmd = new GuessingStopCommand();
31 $cmd = new RunnerCommand();
34 throw new \Exception('command '.$str.' not found');
37 $cmd->channel = $channel;
38 $cmd->config = $config;
42 public function checkAccess(IRCMessage $msg) {
43 $restrict = $this->getStringConfig('restrict', 'none');
44 if ($restrict == 'owner') {
45 return $msg->isOwner();
47 if ($restrict == 'mod') {
53 public abstract function execute($args);
55 protected function getBooleanConfig($name, $default = false) {
56 return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
59 protected function getStringConfig($name, $default = '') {
60 return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
63 protected function listAnd($entries) {
64 return $this->channel->listAnd($entries);
67 protected function messageChannel($str) {
68 if (empty($str)) return;
69 $msg = IRCMessage::privmsg($this->channel->twitch_chat, $str);
70 $this->bot->sendIRCMessage($msg);