+<?php
+
+namespace App\TwitchBotCommands;
+
+use App\Models\Channel;
+use App\Models\ChatBotLog;
+use App\Models\TwitchBotCommand;
+use App\TwitchBot\IRCMessage;
+use App\TwitchBot\TwitchBot;
+use React\Promise\Promise;
+
+class RandomChatCommand extends BaseCommand {
+
+ public function __construct(TwitchBot $bot, TwitchBotCommand $cmd) {
+ parent::__construct($bot, $cmd);
+ }
+
+ public function execute() {
+ return new Promise(function($resolve) {
+ $channel = Channel::findOrFail($this->getParameter('channel'));
+ $text = $channel->randomOfClass($this->getParameter('category'));
+ $this->bot->sendIRCMessage(IRCMessage::privmsg($channel->twitch_chat, $text->text_content));
+ $log = new ChatBotLog();
+ $log->channel()->associate($channel);
+ if (is_object($text)) {
+ $log->origin()->associate($text);
+ }
+ $log->text = $text->text_content;
+ $log->save();
+ $resolve();
+ });
+ }
+
+}