use HasFactory;
+ public static function onUpstreamCreate(Guild $guild) {
+ static::sync($guild);
+ }
+
+ public static function onUpstreamUpdate(Guild $guild) {
+ static::sync($guild);
+ }
+
public static function sync(Guild $guild) {
$model = static::firstOrNew([
'guild_id' => $guild->id,
$model->owner = $guild->owner_id;
$model->locale = $guild->preferred_locale;
$model->save();
+
+ $role_ids = [];
+ foreach ($guild->roles as $role) {
+ DiscordRole::sync($model, $role);
+ $role_ids[] = $role->id;
+ }
+ $model->roles()->whereNotIn('role_id', $role_ids)->delete();
+
+ $channel_ids = [];
+ foreach ($guild->channels as $channel) {
+ DiscordChannel::sync($model, $channel);
+ $channel_ids[] = $channel->id;
+ }
+ $model->channels()->whereNotIn('channel_id', $channel_ids)->delete();
+ }
+
+ public function channels() {
+ return $this->hasMany(DiscordChannel::class)->orderBy('position');
+ }
+
+ public function roles() {
+ return $this->hasMany(DiscordRole::class)->orderBy('position');
}
protected $fillable = [