3 namespace App\TwitchBotCommands;
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;
12 class RandomChatCommand extends BaseCommand {
14 public function __construct(TwitchBot $bot, TwitchBotCommand $cmd) {
15 parent::__construct($bot, $cmd);
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);
29 $log->text = $actual_text;
30 $log->user()->associate($this->getExecutingUser());
31 $log->category = $this->getParameter('category');