]> git.localhorst.tv Git - alttp.git/blobdiff - app/TwitchBot/ChatCommand.php
first simple twitch commands
[alttp.git] / app / TwitchBot / ChatCommand.php
diff --git a/app/TwitchBot/ChatCommand.php b/app/TwitchBot/ChatCommand.php
new file mode 100644 (file)
index 0000000..feea8ab
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+namespace App\TwitchBot;
+
+use App\Models\Channel;
+
+abstract class ChatCommand {
+
+       public static function create(TwitchBot $bot, Channel $channel, $config) {
+               $cmd = null;
+               switch ($config['command']) {
+                       case 'crew':
+                               $cmd = new CrewCommand();
+                               break;
+                       case 'runner':
+                               $cmd = new RunnerCommand();
+                               break;
+                       default:
+                               throw new \Exception('command '.$str.' not found');
+               }
+               $cmd->bot = $bot;
+               $cmd->channel = $channel;
+               $cmd->config = $config;
+               return $cmd;
+       }
+
+       public abstract function execute($args);
+
+       protected function getBooleanConfig($name, $default = false) {
+               return array_key_exists($name, $this->config) ? $this->config[$name] : $default;
+       }
+
+       protected function messageChannel($str) {
+               $msg = IRCMessage::privmsg($this->channel->twitch_chat, $str);
+               $this->bot->sendIRCMessage($msg);
+       }
+
+       protected $bot;
+       protected $channel;
+       protected $config;
+
+}
+
+?>