5 use App\DiscordBotCommands\BaseCommand;
7 use Discord\Parts\Channel\Channel;
8 use Discord\Parts\Guild\Guild;
9 use Illuminate\Database\Eloquent\Factories\HasFactory;
10 use Illuminate\Database\Eloquent\Model;
12 class DiscordBotCommand extends Model
16 public function tournament() {
17 return $this->belongsTo(Tournament::class);
20 public function user() {
21 return $this->belongsTo(User::class);
24 public function execute(Discord $discord) {
25 $this->setExecuting();
28 BaseCommand::resolve($discord, $this)
30 ->otherwise(function (\Throwable $e) {
31 $this->setException($e);
33 ->done(function($v = null) {
36 } catch (\Exception $e) {
37 $this->setException($e);
42 private function setDone() {
43 $this->status = 'done';
47 private function setExecuting() {
48 $this->status = 'executing';
49 $this->executed_at = now();
53 private function setException(\Throwable $e) {
54 $this->status = 'exception';
56 'type' => get_class($e),
57 'file' => $e->getFile(),
58 'line' => $e->getLine(),
59 'message' => $e->getMessage(),
66 'parameters' => 'array',
68 'executed_at' => 'datetime',