public bool UpdateGuildProperties(GuildProperties guildProperties) { bool isSuccess = GuildProperties.Update(guildProperties); if (isSuccess) { _db.Checkpoint(); } return(isSuccess); }
public GuildProperties EnsureGuildProperties(ulong guildId) { GuildProperties guildProperties = GuildProperties.FindById(guildId.ToString()); if (guildProperties == null) { guildProperties = new GuildProperties() { GuildId = guildId }; string id = GuildProperties.Insert(guildProperties); if (!string.IsNullOrEmpty(id)) { _db.Checkpoint(); } } return(guildProperties); }
//General /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> public static async Task <Model> ModifyAsync(IGuild guild, BaseDiscordClient client, Action <GuildProperties> func, RequestOptions options) { if (func == null) { throw new ArgumentNullException(nameof(func)); } var args = new GuildProperties(); func(args); var apiArgs = new API.Rest.ModifyGuildParams { AfkChannelId = args.AfkChannelId, AfkTimeout = args.AfkTimeout, SystemChannelId = args.SystemChannelId, DefaultMessageNotifications = args.DefaultMessageNotifications, Icon = args.Icon.IsSpecified ? args.Icon.Value?.ToModel() : Optional.Create <ImageModel?>(), Name = args.Name, Splash = args.Splash.IsSpecified ? args.Splash.Value?.ToModel() : Optional.Create <ImageModel?>(), VerificationLevel = args.VerificationLevel, ExplicitContentFilter = args.ExplicitContentFilter }; if (args.AfkChannel.IsSpecified) { apiArgs.AfkChannelId = args.AfkChannel.Value.Id; } else if (args.AfkChannelId.IsSpecified) { apiArgs.AfkChannelId = args.AfkChannelId.Value; } if (args.SystemChannel.IsSpecified) { apiArgs.SystemChannelId = args.SystemChannel.Value.Id; } else if (args.SystemChannelId.IsSpecified) { apiArgs.SystemChannelId = args.SystemChannelId.Value; } if (args.Owner.IsSpecified) { apiArgs.OwnerId = args.Owner.Value.Id; } else if (args.OwnerId.IsSpecified) { apiArgs.OwnerId = args.OwnerId.Value; } if (args.Region.IsSpecified) { apiArgs.RegionId = args.Region.Value.Id; } else if (args.RegionId.IsSpecified) { apiArgs.RegionId = args.RegionId.Value; } if (!apiArgs.Splash.IsSpecified && guild.SplashId != null) { apiArgs.Splash = new ImageModel(guild.SplashId); } if (!apiArgs.Icon.IsSpecified && guild.IconId != null) { apiArgs.Icon = new ImageModel(guild.IconId); } if (args.ExplicitContentFilter.IsSpecified) { apiArgs.ExplicitContentFilter = args.ExplicitContentFilter.Value; } return(await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false)); }