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-leaderboard':
20 $cmd = new GuessingLeaderboardCommand();
22 case 'guessing-solve':
23 $cmd = new GuessingSolveCommand();
25 case 'guessing-start':
26 $cmd = new GuessingStartCommand();
29 $cmd = new GuessingStopCommand();
32 $cmd = new RunnerCommand();
35 throw new \Exception('command '.$str.' not found');
38 $cmd->channel = $channel;
39 $cmd->config = $config;
43 public function checkAccess(IRCMessage $msg) {
44 $restrict = $this->getStringConfig('restrict', 'none');
45 if ($restrict == 'owner') {
46 return $msg->isOwner();
48 if ($restrict == 'mod') {
54 public abstract function execute($args);
56 protected function getBooleanConfig($name, $default = false) {
57 return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
60 protected function getStringConfig($name, $default = '') {
61 return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
64 protected function listAnd($entries) {
65 $lang = empty($this->channels->languages) ? 'en' : $this->channel->languages[0];
67 return Arr::join($entries, ', ', ' und ');
69 return Arr::join($entries, ', ', ' and ');
72 protected function messageChannel($str) {
73 if (empty($str)) return;
74 $msg = IRCMessage::privmsg($this->channel->twitch_chat, $str);
75 $this->bot->sendIRCMessage($msg);