X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=app%2FModels%2FDiscordChannel.php;fp=app%2FModels%2FDiscordChannel.php;h=ba3d3176710608e5996bdbaec253c0dcdab3e825;hb=d566d913c251fbb05e6bd314cc51f8b5ca49fe57;hp=0000000000000000000000000000000000000000;hpb=684ad09eaf505f39749a001fd8b23fc30fdf8b3f;p=alttp.git diff --git a/app/Models/DiscordChannel.php b/app/Models/DiscordChannel.php new file mode 100644 index 0000000..ba3d317 --- /dev/null +++ b/app/Models/DiscordChannel.php @@ -0,0 +1,53 @@ +guild_id); + if (!$guild) return; + static::sync($guild, $channel); + } + + public static function onUpstreamUpdate(Channel $channel) { + $guild = DiscordGuild::firstWhere('guild_id', $channel->guild_id); + if (!$guild) return; + static::sync($guild, $channel); + } + + public static function onUpstreamDelete($channel) { + if (!$channel) return; + $model = static::firstWhere('channel_id', $channel->id); + if (!$model) return; + $model->delete(); + } + + public static function sync(DiscordGuild $guild, Channel $channel) { + $model = static::firstOrNew([ + 'channel_id' => $channel->id, + 'discord_guild_id' => $guild->id, + ]); + $model->name = $channel->name; + $model->type = $channel->type; + $model->position = $channel->position; + $model->private = $channel->is_private; + $model->save(); + } + + public function guild() { + return $this->belongsTo(DiscordGuild::class); + } + + protected $fillable = [ + 'channel_id', + 'discord_guild_id', + ]; + +}