Example #1
0
            public static ChannelPermissions CalculatePermissions(IGuild guild, IGuildChannel channel, IMember member, IEnumerable <IRole> roles)
            {
                if (channel == null)
                {
                    throw new ArgumentNullException(nameof(channel));
                }

                var guildPermissions = CalculatePermissions(guild, member, roles);

                if (guildPermissions.Administrator)
                {
                    return(ChannelPermissions.All);
                }

                var permissions = ChannelPermissions.Mask(guildPermissions, channel);

                foreach (var role in roles.OrderBy(x => x.Position))
                {
                    for (var i = 0; i < channel.Overwrites.Count; i++)
                    {
                        var overwrite = channel.Overwrites[i];
                        if (overwrite.TargetId != role.Id)
                        {
                            continue;
                        }

                        permissions -= overwrite.Permissions.Denied;
                        permissions += overwrite.Permissions.Allowed;
                    }
                }

                for (var i = 0; i < channel.Overwrites.Count; i++)
                {
                    var overwrite = channel.Overwrites[i];
                    if (overwrite.TargetId != member.Id)
                    {
                        continue;
                    }

                    permissions -= overwrite.Permissions.Denied;
                    permissions += overwrite.Permissions.Allowed;
                }

                if (!permissions.ViewChannel)
                {
                    return(ChannelPermissions.None);
                }

                if (channel is ITextChannel && !permissions.SendMessages)
                {
                    permissions -= Permission.AttachFiles |
                                   Permission.EmbedLinks |
                                   Permission.MentionEveryone |
                                   Permission.SendTtsMessages;
                }

                return(permissions);
            }
Example #2
0
 public bool Equals(ChannelPermissions other)
 => RawValue == other.RawValue;