]> git.localhorst.tv Git - alttp.git/blobdiff - app/TwitchBotCommands/AdlibChatCommand.php
adlib chat
[alttp.git] / app / TwitchBotCommands / AdlibChatCommand.php
diff --git a/app/TwitchBotCommands/AdlibChatCommand.php b/app/TwitchBotCommands/AdlibChatCommand.php
new file mode 100644 (file)
index 0000000..8079b8c
--- /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 AdlibChatCommand 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'));
+                       $db = $this->bot->getChatlibDatabase($channel);
+                       $text = $db->generate();
+                       $this->bot->sendIRCMessage(IRCMessage::privmsg($channel->twitch_chat, $text));
+                       $log = new ChatBotLog();
+                       $log->channel()->associate($channel);
+                       $log->text = $text;
+                       $log->user()->associate($this->getExecutingUser());
+                       $log->category = 'adlib';
+                       $log->save();
+                       $resolve();
+               });
+       }
+
+}