X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FDiscordBotCommand.php;fp=app%2FModels%2FDiscordBotCommand.php;h=aec2f56988997ec01f666fbacfbd659a55aa46f7;hb=12f64085fd212a9744db01790cefad53c970e8d9;hp=0000000000000000000000000000000000000000;hpb=04eb1ab6316aba62b5cbf6f9b729782df1fe5015;p=alttp.git diff --git a/app/Models/DiscordBotCommand.php b/app/Models/DiscordBotCommand.php new file mode 100644 index 0000000..aec2f56 --- /dev/null +++ b/app/Models/DiscordBotCommand.php @@ -0,0 +1,72 @@ +status = 'executing'; + $this->executed_at = now(); + $this->save(); + + try { + switch ($this->command) { + case 'presence': + $this->executePresence($discord); + break; + default: + throw new Exception('unrecognized command'); + } + $this->status = 'done'; + $this->save(); + } catch (\Exception $e) { + $this->status = 'exception'; + $this->result = [ + 'type' => get_class($e), + 'message' => $e->getMessage(), + ]; + $this->save(); + } + } + + protected function executePresence(Discord $discord) { + $activity = null; + $idle = false; + $status = 'online'; + $afk = false; + if (isset($this->parameters['activity'])) { + $activity = new Activity($discord); + $activity->type = $this->parameters['activity']; + if (isset($this->parameters['name'])) { + $activity->name = $this->parameters['name']; + } + if (isset($this->parameters['url'])) { + $activity->url = $this->parameters['url']; + } + } + if (isset($this->parameters['idle'])) { + $idle = $this->parameters['idle']; + } + if (isset($this->parameters['status'])) { + $status = $this->parameters['status']; + } + if (isset($this->parameters['afk'])) { + $afk = $this->parameters['afk']; + } + $discord->updatePresence($activity, $idle, $status, $afk); + } + + protected $casts = [ + 'parameters' => 'array', + 'result' => 'array', + 'executed_at' => 'datetime', + ]; + +}