3 namespace App\TwitchBot;
5 use App\Models\Channel;
6 use Illuminate\Support\Arr;
8 abstract class ChatCommand {
10 public static function create(TwitchBot $bot, Channel $channel, $config) {
12 switch ($config['command']) {
14 $cmd = new CrewCommand();
16 case 'guessing-cancel':
17 $cmd = new GuessingCancelCommand();
19 case 'guessing-solve':
20 $cmd = new GuessingSolveCommand();
22 case 'guessing-start':
23 $cmd = new GuessingStartCommand();
26 $cmd = new GuessingStopCommand();
29 $cmd = new RunnerCommand();
32 throw new \Exception('command '.$str.' not found');
35 $cmd->channel = $channel;
36 $cmd->config = $config;
40 public function checkAccess(IRCMessage $msg) {
41 $restrict = $this->getStringConfig('restrict', 'none');
42 if ($restrict == 'owner') {
43 return $msg->isOwner();
45 if ($restrict == 'mod') {
51 public abstract function execute($args);
53 protected function getBooleanConfig($name, $default = false) {
54 return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
57 protected function getStringConfig($name, $default = '') {
58 return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
61 protected function listAnd($entries) {
62 return Arr::join($entries, ', ', ' and ');
65 protected function messageChannel($str) {
66 $msg = IRCMessage::privmsg($this->channel->twitch_chat, $str);
67 $this->bot->sendIRCMessage($msg);