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