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 $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);
28 $log->text = $text->text_content;