]> git.localhorst.tv Git - alttp.git/blobdiff - app/TwitchBotCommands/RandomChatCommand.php
protocol chat bot messages
[alttp.git] / app / TwitchBotCommands / RandomChatCommand.php
diff --git a/app/TwitchBotCommands/RandomChatCommand.php b/app/TwitchBotCommands/RandomChatCommand.php
new file mode 100644 (file)
index 0000000..cc49c00
--- /dev/null
@@ -0,0 +1,34 @@
+<?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();
+               });
+       }
+
+}