]> git.localhorst.tv Git - alttp.git/blob - app/TwitchBot/ChatCommand.php
remove some useless svg groups
[alttp.git] / app / TwitchBot / ChatCommand.php
1 <?php
2
3 namespace App\TwitchBot;
4
5 use App\Models\Channel;
6
7 abstract class ChatCommand {
8
9         public static function create(TwitchBot $bot, Channel $channel, $config) {
10                 $cmd = null;
11                 switch ($config['command']) {
12                         case 'crew':
13                                 $cmd = new CrewCommand();
14                                 break;
15                         case 'guessing-cancel':
16                                 $cmd = new GuessingCancelCommand();
17                                 break;
18                         case 'guessing-leaderboard':
19                                 $cmd = new GuessingLeaderboardCommand();
20                                 break;
21                         case 'guessing-solve':
22                                 $cmd = new GuessingSolveCommand();
23                                 break;
24                         case 'guessing-start':
25                                 $cmd = new GuessingStartCommand();
26                                 break;
27                         case 'guessing-stop':
28                                 $cmd = new GuessingStopCommand();
29                                 break;
30                         case 'runner':
31                                 $cmd = new RunnerCommand();
32                                 break;
33                         default:
34                                 throw new \Exception('command '.$str.' not found');
35                 }
36                 $cmd->bot = $bot;
37                 $cmd->channel = $channel;
38                 $cmd->config = $config;
39                 return $cmd;
40         }
41
42         public function checkAccess(IRCMessage $msg) {
43                 $restrict = $this->getStringConfig('restrict', 'none');
44                 if ($restrict == 'owner') {
45                         return $msg->isOwner();
46                 }
47                 if ($restrict == 'mod') {
48                         return $msg->isMod();
49                 }
50                 return true;
51         }
52
53         public abstract function execute($args);
54
55         protected function getBooleanConfig($name, $default = false) {
56                 return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
57         }
58
59         protected function getStringConfig($name, $default = '') {
60                 return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
61         }
62
63         protected function listAnd($entries) {
64                 return $this->channel->listAnd($entries);
65         }
66
67         protected function messageChannel($str) {
68                 if (empty($str)) return;
69                 $msg = IRCMessage::privmsg($this->channel->twitch_chat, $str);
70                 $this->bot->sendIRCMessage($msg);
71         }
72
73         protected $bot;
74         protected $channel;
75         protected $config;
76
77 }
78
79 ?>