private Permissions GetPermission(User u, Channel c) { if (u.IsBot) { return(Permissions.Blocked); } if (_config.Staff.Contains(u.Id)) { return(Permissions.BotOwner); } if (!c.IsPrivate) { if (u == c.Server.Owner) { return(Permissions.ServerOwner); } if (u.ServerPermissions.Administrator) { return(Permissions.ServerAdmin); } if (u.GetPermissions(c).ManageChannel) { return(Permissions.ChannelAdmin); } } return(Permissions.User); }
internal void Update(APIMessage model) { var channel = Channel; var server = channel.Server; if (model.Attachments != null) { Attachments = model.Attachments .Select(x => new Attachment() { Id = x.Id, Url = x.Url, ProxyUrl = x.ProxyUrl, Width = x.Width, Height = x.Height, Size = x.Size, Filename = x.Filename }) .ToArray(); } if (model.Embeds != null) { Embeds = model.Embeds.Select(x => { EmbedLink author = null, provider = null; File thumbnail = null, video = null; if (x.Author != null) { author = new EmbedLink { Url = x.Author.Url, Name = x.Author.Name } } ; if (x.Provider != null) { provider = new EmbedLink { Url = x.Provider.Url, Name = x.Provider.Name } } ; if (x.Thumbnail != null) { thumbnail = new File { Url = x.Thumbnail.Url, ProxyUrl = x.Thumbnail.ProxyUrl, Width = x.Thumbnail.Width, Height = x.Thumbnail.Height } } ; if (x.Video != null) { video = new File { Url = x.Video.Url, ProxyUrl = null, Width = x.Video.Width, Height = x.Video.Height } } ; return(new Embed { Url = x.Url, Type = x.Type, Title = x.Title, Description = x.Description, Author = author, Provider = provider, Thumbnail = thumbnail, Video = video }); }).ToArray(); } if (model.IsTextToSpeech != null) { IsTTS = model.IsTextToSpeech.Value; } if (model.Timestamp != null) { Timestamp = model.Timestamp.Value; } if (model.EditedTimestamp != null) { EditedTimestamp = model.EditedTimestamp; } if (model.Mentions != null) { MentionedUsers = model.Mentions .Select(x => Channel.GetUserFast(x.Id)) .Where(x => x != null) .ToArray(); } if (model.IsMentioningEveryone != null) { if (model.IsMentioningEveryone.Value && User != null && User.GetPermissions(channel).MentionEveryone) { MentionedRoles = new Role[] { Server.EveryoneRole } } ; else { MentionedRoles = new Role[0]; } } if (model.Content != null) { string text = model.Content; RawText = text; //var mentionedUsers = new List<User>(); var mentionedChannels = new List <Channel>(); //var mentionedRoles = new List<Role>(); text = CleanUserMentions(Channel, text /*, mentionedUsers*/); if (server != null) { text = CleanChannelMentions(Channel, text, mentionedChannels); //text = CleanRoleMentions(_client, User, channel, text, mentionedRoles); } Text = text; //MentionedUsers = mentionedUsers; MentionedChannels = mentionedChannels; //MentionedRoles = mentionedRoles; } }
public static AccessLevel GetPermission(User user, Channel channel) { if (user.IsBot) // Prevent other bots from executing commands return AccessLevel.Blocked; if (_config.Owners.Contains(user.Id)) // Create a specific permission for bot owners return AccessLevel.BotOwner; if (!channel.IsPrivate) // Make sure the command isn't executed in a PM. { if (user == channel.Server.Owner) // Server owner permission for the server owner. return AccessLevel.ServerOwner; if (user.ServerPermissions.Administrator) // Server admin permission for server admins. return AccessLevel.ServerAdmin; if (user.GetPermissions(channel).ManageChannel) // Channel admin permission for channel admins. return AccessLevel.ChannelAdmin; } return AccessLevel.User; // If nothing else fits return a default permission. }
private int PermissionResolver(User user, Channel channel) { if (user.Id == GlobalSettings.Users.DevId) return (int)PermissionLevel.BotOwner; if (user.Server != null) { if (user == channel.Server.Owner) return (int)PermissionLevel.ServerOwner; var serverPerms = user.ServerPermissions; if (serverPerms.ManageRoles) return (int)PermissionLevel.ServerAdmin; if (serverPerms.ManageMessages && serverPerms.KickMembers && serverPerms.BanMembers) return (int)PermissionLevel.ServerModerator; var channelPerms = user.GetPermissions(channel); if (channelPerms.ManagePermissions) return (int)PermissionLevel.ChannelAdmin; if (channelPerms.ManageMessages) return (int)PermissionLevel.ChannelModerator; } return (int)PermissionLevel.User; }
public static bool CanJoinChannel(this Channel voiceChannel, User user) { if (voiceChannel.Type != ChannelType.Voice) throw new ArgumentException(nameof(voiceChannel)); return user.GetPermissions(voiceChannel).Connect; }