namespace vassago.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Reflection; using System.Threading.Tasks; using Discord; public class Channel { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public ulong? ExternalId { get; set; } public string DisplayName { get; set; } public bool IsDM { get; set; } public PermissionSettings Permissions { get; set; } public List SubChannels { get; set; } public Channel ParentChannel { get; set; } public string Protocol { get; set; } public List Messages { get; set; } public List Users { get; set; } //public Dictionary EmoteOverrides{get;set;} [NonSerialized] public Func SendFile; [NonSerialized] public Func SendMessage; public PermissionSettings EffectivePermissions { get { PermissionSettings toReturn = Permissions ?? new PermissionSettings(); return GetEffectivePermissions(ref toReturn); } } private PermissionSettings GetEffectivePermissions(ref PermissionSettings settings) { if(settings == null) throw new ArgumentNullException(); settings.LewdnessFilterLevel = settings.LewdnessFilterLevel ?? Permissions?.LewdnessFilterLevel; settings.MeannessFilterLevel = settings.MeannessFilterLevel ?? Permissions?.MeannessFilterLevel; settings.LinksAllowed = settings.LinksAllowed ?? Permissions?.LinksAllowed; settings.MaxAttachmentBytes = settings.MaxAttachmentBytes ?? Permissions?.MaxAttachmentBytes; settings.MaxTextChars = settings.MaxTextChars ?? Permissions?.MaxTextChars; settings.ReactionsPossible = settings.ReactionsPossible ?? Permissions?.ReactionsPossible; if(this.ParentChannel != null && (settings.LewdnessFilterLevel == null || settings.MeannessFilterLevel == null || settings.LinksAllowed == null || settings.MaxAttachmentBytes == null || settings.MaxTextChars == null || settings.ReactionsPossible == null)) { return this.ParentChannel.GetEffectivePermissions(ref settings); } else { return settings; } } }