command = 'adlib-chat'; $cmd->parameters = [ 'channel' => $channel->id, ]; $cmd->status = 'pending'; $cmd->user()->associate($user); $cmd->bot_nick = 'horstiebot'; $cmd->save(); } public static function chat($channel, $text, User $user = null, $nick = 'localhorsttv') { $cmd = new TwitchBotCommand(); $cmd->command = 'chat'; $cmd->parameters = [ 'channel' => $channel, 'text' => $text, ]; $cmd->status = 'pending'; $cmd->user()->associate($user); $cmd->bot_nick = $nick; $cmd->save(); } public static function join($channel, User $user = null, $nick = 'localhorsttv') { $cmd = new TwitchBotCommand(); $cmd->command = 'join'; $cmd->parameters = [ 'channel' => $channel, ]; $cmd->status = 'pending'; $cmd->user()->associate($user); $cmd->bot_nick = $nick; $cmd->save(); } public static function part($channel, User $user = null, $nick = 'localhorsttv') { $cmd = new TwitchBotCommand(); $cmd->command = 'part'; $cmd->parameters = [ 'channel' => $channel, ]; $cmd->status = 'pending'; $cmd->user()->associate($user); $cmd->bot_nick = $nick; $cmd->save(); } public static function randomChat(Channel $channel, $category, User $user = null, $nick = 'localhorsttv') { $cmd = new TwitchBotCommand(); $cmd->command = 'random-chat'; $cmd->parameters = [ 'channel' => $channel->id, 'category' => $category, ]; $cmd->status = 'pending'; $cmd->user()->associate($user); $cmd->bot_nick = $nick; $cmd->save(); } public function tournament() { return $this->belongsTo(Tournament::class); } public function user() { return $this->belongsTo(User::class); } public function execute(TwitchBot $bot) { $this->setExecuting(); try { BaseCommand::resolve($bot, $this) ->execute() ->otherwise(function (\Throwable $e) { $this->setException($e); }) ->done(function($v = null) { $this->setDone(); }); } catch (\Exception $e) { $this->setException($e); } } private function setDone() { $this->status = 'done'; $this->save(); } private function setExecuting() { $this->status = 'executing'; $this->executed_at = now(); $this->save(); } private function setException(\Throwable $e) { $this->status = 'exception'; $this->result = [ 'type' => get_class($e), 'file' => $e->getFile(), 'line' => $e->getLine(), 'message' => $e->getMessage(), ]; $this->save(); } protected $casts = [ 'parameters' => 'array', 'result' => 'array', 'executed_at' => 'datetime', ]; }