5 use Discord\Parts\Channel\Channel;
6 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 use Illuminate\Database\Eloquent\Model;
9 class DiscordChannel extends Model
13 public static function onUpstreamCreate(Channel $channel) {
14 $guild = DiscordGuild::firstWhere('guild_id', $channel->guild_id);
16 static::sync($guild, $channel);
19 public static function onUpstreamUpdate(Channel $channel) {
20 $guild = DiscordGuild::firstWhere('guild_id', $channel->guild_id);
22 static::sync($guild, $channel);
25 public static function onUpstreamDelete($channel) {
26 if (!$channel) return;
27 $model = static::firstWhere('channel_id', $channel->id);
32 public static function sync(DiscordGuild $guild, Channel $channel) {
33 $model = static::firstOrNew([
34 'channel_id' => $channel->id,
35 'discord_guild_id' => $guild->id,
37 $model->name = $channel->name;
38 $model->type = $channel->type;
39 $model->position = $channel->position;
40 $model->private = $channel->is_private;
41 $model->parent_id = $channel->parent_id;
45 public function guild() {
46 return $this->belongsTo(DiscordGuild::class, 'discord_guild_id');
49 protected $fillable = [