vassago/Models/Channel.cs

65 lines
2.3 KiB
C#
Raw Normal View History

2023-06-01 00:03:23 -04:00
namespace vassago.Models;
using System;
2023-06-01 00:03:23 -04:00
using System.Collections.Generic;
2023-06-05 14:55:48 -04:00
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
2023-06-01 00:03:23 -04:00
using System.Threading.Tasks;
2023-06-05 14:55:48 -04:00
using Discord;
2023-06-01 00:03:23 -04:00
public class Channel
{
2023-06-05 14:55:48 -04:00
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
2023-06-01 00:03:23 -04:00
public Guid Id { get; set; }
public ulong? ExternalId { get; set; }
public string DisplayName { get; set; }
public bool IsDM { get; set; }
2023-06-19 11:03:06 -04:00
public PermissionSettings Permissions { get; set; }
2023-06-05 14:55:48 -04:00
public List<Channel> SubChannels { get; set; }
2023-06-01 00:03:23 -04:00
public Channel ParentChannel { get; set; }
2023-06-05 14:55:48 -04:00
public string Protocol { get; set; }
public List<Message> Messages { get; set; }
2023-06-19 12:56:40 -04:00
public List<Account> Users { get; set; }
//public Dictionary<string, string> EmoteOverrides{get;set;}
2023-06-01 00:03:23 -04:00
2023-06-05 14:55:48 -04:00
[NonSerialized]
public Func<string, string, Task> SendFile;
[NonSerialized]
public Func<string, Task> SendMessage;
2023-06-19 11:03:06 -04:00
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;
}
}
2023-06-05 14:55:48 -04:00
}