]> git.localhorst.tv Git - alttp.git/blob - app/TwitchBot/ChatCommand.php
first simple twitch commands
[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 'runner':
16                                 $cmd = new RunnerCommand();
17                                 break;
18                         default:
19                                 throw new \Exception('command '.$str.' not found');
20                 }
21                 $cmd->bot = $bot;
22                 $cmd->channel = $channel;
23                 $cmd->config = $config;
24                 return $cmd;
25         }
26
27         public abstract function execute($args);
28
29         protected function getBooleanConfig($name, $default = false) {
30                 return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
31         }
32
33         protected function messageChannel($str) {
34                 $msg = IRCMessage::privmsg($this->channel->twitch_chat, $str);
35                 $this->bot->sendIRCMessage($msg);
36         }
37
38         protected $bot;
39         protected $channel;
40         protected $config;
41
42 }
43
44 ?>