]> git.localhorst.tv Git - alttp.git/blob - app/TwitchBotCommands/RandomChatCommand.php
cc49c00e62a788757ae267732d8680d59e344bd7
[alttp.git] / app / TwitchBotCommands / RandomChatCommand.php
1 <?php
2
3 namespace App\TwitchBotCommands;
4
5 use App\Models\Channel;
6 use App\Models\ChatBotLog;
7 use App\Models\TwitchBotCommand;
8 use App\TwitchBot\IRCMessage;
9 use App\TwitchBot\TwitchBot;
10 use React\Promise\Promise;
11
12 class RandomChatCommand extends BaseCommand {
13
14         public function __construct(TwitchBot $bot, TwitchBotCommand $cmd) {
15                 parent::__construct($bot, $cmd);
16         }
17
18         public function execute() {
19                 return new Promise(function($resolve) {
20                         $channel = Channel::findOrFail($this->getParameter('channel'));
21                         $text = $channel->randomOfClass($this->getParameter('category'));
22                         $this->bot->sendIRCMessage(IRCMessage::privmsg($channel->twitch_chat, $text->text_content));
23                         $log = new ChatBotLog();
24                         $log->channel()->associate($channel);
25                         if (is_object($text)) {
26                                 $log->origin()->associate($text);
27                         }
28                         $log->text = $text->text_content;
29                         $log->save();
30                         $resolve();
31                 });
32         }
33
34 }