]> git.localhorst.tv Git - alttp.git/blob - app/TwitchBotCommands/RandomChatCommand.php
log who sent manual random chats
[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                         $actual_text = is_object($text) ? $text->text_content : $text;
23                         $this->bot->sendIRCMessage(IRCMessage::privmsg($channel->twitch_chat, $actual_text));
24                         $log = new ChatBotLog();
25                         $log->channel()->associate($channel);
26                         if (is_object($text)) {
27                                 $log->origin()->associate($text);
28                         }
29                         $log->text = $actual_text;
30                         $log->user()->associate($this->getExecutingUser());
31                         $log->category = $this->getParameter('category');
32                         $log->save();
33                         $resolve();
34                 });
35         }
36
37 }