5 use App\TwitchBot\TwitchBot;
6 use App\TwitchBotCommands\BaseCommand;
7 use Illuminate\Database\Eloquent\Factories\HasFactory;
8 use Illuminate\Database\Eloquent\Model;
10 class TwitchBotCommand extends Model
14 public static function join($channel) {
15 $cmd = new TwitchBotCommand();
16 $cmd->command = 'join';
18 'channel' => $channel,
20 $cmd->status = 'pending';
24 public static function part($channel) {
25 $cmd = new TwitchBotCommand();
26 $cmd->command = 'part';
28 'channel' => $channel,
30 $cmd->status = 'pending';
34 public function tournament() {
35 return $this->belongsTo(Tournament::class);
38 public function user() {
39 return $this->belongsTo(User::class);
42 public function execute(TwitchBot $bot) {
43 $this->setExecuting();
46 BaseCommand::resolve($bot, $this)
48 ->otherwise(function (\Throwable $e) {
49 $this->setException($e);
51 ->done(function($v = null) {
54 } catch (\Exception $e) {
55 $this->setException($e);
60 private function setDone() {
61 $this->status = 'done';
65 private function setExecuting() {
66 $this->status = 'executing';
67 $this->executed_at = now();
71 private function setException(\Throwable $e) {
72 $this->status = 'exception';
74 'type' => get_class($e),
75 'file' => $e->getFile(),
76 'line' => $e->getLine(),
77 'message' => $e->getMessage(),
84 'parameters' => 'array',
86 'executed_at' => 'datetime',