2022-03-20 01:10:10 +00:00
|
|
|
|
namespace BirthdayBot.Data;
|
|
|
|
|
internal static class Extensions {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the corresponding <see cref="GuildConfig"/> for this guild, or a new one if one does not exist.
|
|
|
|
|
/// If it doesn't exist in the database, <see cref="GuildConfig.IsNew"/> returns true.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static GuildConfig GetConfigOrNew(this SocketGuild guild, BotDatabaseContext db)
|
2024-04-28 08:51:58 +00:00
|
|
|
|
=> db.GuildConfigurations.Where(g => g.GuildId == guild.Id).FirstOrDefault()
|
2022-11-23 07:19:37 +00:00
|
|
|
|
?? new GuildConfig() { IsNew = true, GuildId = guild.Id };
|
2022-03-20 01:10:10 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the corresponding <see cref="UserEntry"/> for this user in this guild, or a new one if one does not exist.
|
|
|
|
|
/// If it doesn't exist in the database, <see cref="UserEntry.IsNew"/> returns true.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static UserEntry GetUserEntryOrNew(this SocketGuildUser user, BotDatabaseContext db)
|
2022-11-23 07:19:37 +00:00
|
|
|
|
=> db.UserEntries.Where(u => u.GuildId == user.Guild.Id && u.UserId == user.Id).FirstOrDefault()
|
|
|
|
|
?? new UserEntry() { IsNew = true, GuildId = user.Guild.Id, UserId = user.Id };
|
2022-03-20 01:10:10 +00:00
|
|
|
|
}
|