public async Task ExemptAsync(ulong gid, ExemptedEntityType type, IEnumerable <ulong> ids) { using TheGodfatherDbContext db = this.dbb.CreateContext(); db.ExemptsMention.AddExemptions(gid, type, ids); await db.SaveChangesAsync(); this.UpdateExemptsForGuildAsync(gid); }
public async Task UnexemptAsync(ulong gid, ExemptedEntityType type, IEnumerable <ulong> ids) { using TheGodfatherDbContext db = this.dbb.CreateContext(); db.ExemptsMention.RemoveRange( db.ExemptsMention.Where(ex => ex.GuildId == gid && ex.Type == type && ids.Any(id => id == ex.Id)) ); await db.SaveChangesAsync(); this.UpdateExemptsForGuildAsync(gid); }
public static string ToUserFriendlyString(this ExemptedEntityType entity) { switch (entity) { case ExemptedEntityType.Channel: return("Channel"); case ExemptedEntityType.Member: return("User"); case ExemptedEntityType.Role: return("Role"); default: return("Unknown"); } }
public static char ToFlag(this ExemptedEntityType entity) { switch (entity) { case ExemptedEntityType.Channel: return('c'); case ExemptedEntityType.Member: return('m'); case ExemptedEntityType.Role: return('r'); default: return('?'); } }
public static void AddExemptions <TEntity>(this DbSet <TEntity> set, ulong gid, ExemptedEntityType type, IEnumerable <ulong> ids) where TEntity : ExemptedEntity, new() { set.AddRange(ids .Where(id => !set.Where(dbe => dbe.GuildIdDb == (long)gid).Any(dbe => dbe.Type == type && dbe.IdDb == (long)id)) .Select(id => new TEntity { GuildId = gid, Id = id, Type = type }) ); }
public static void AddExemptions <TEntity, TExempt>(this DbSet <TEntity> set, ulong gid, IEnumerable <TExempt> exempts, ExemptedEntityType type) where TEntity : DatabaseExemptedEntity, new() where TExempt : SnowflakeObject { set.AddRange(exempts .Where(e => !set.Where(dbe => dbe.GuildId == gid).Any(dbe => dbe.Type == type && dbe.Id == e.Id)) .Select(e => new TEntity { GuildId = gid, Id = e.Id, Type = type }) ); }
public static string ToTypeString(this ExemptedEntityType type) => Enum.GetName(typeof(ExemptedEntityType), type) ?? "Unknown";