private DiscordOverwrite ConstructDiscordOverwriteFromList(
            List <UIElement> list,
            DiscordChannel channel,
            DiscordNamedObject overwriteName,
            bool isRole
            )
        {
            var overwrite = new DiscordOverwrite(
                overwriteName.Id,
                isRole,
                channel.Type);

            var index = 2;

            foreach (DiscordPermission perm in Enum.GetValues(typeof(DiscordPermission)))
            {
                if (overwrite.Permission.ContainsKey(perm))
                {
                    var border = (Border)list.Find(e => Grid.GetColumn(e) == index);
                    overwrite.Permission[perm] = ((ToggleButton)border?.Child).IsChecked;
                }

                index++;
            }

            return(overwrite);
        }
示例#2
0
        public async Task PrintPermsAsync(CommandContext ctx,
                                          [Description("Role.")] DiscordRole role,
                                          [Description("Channel.")] DiscordChannel channel = null)
        {
            if (role.Position > ctx.Member.Hierarchy)
            {
                throw new CommandFailedException("You cannot view permissions for roles which have position above your highest role position.");
            }

            channel = channel ?? ctx.Channel;

            DiscordOverwrite overwrite = null;

            foreach (var o in channel.PermissionOverwrites.Where(o => o.Type == OverwriteType.Role))
            {
                var r = await o.GetRoleAsync();

                if (r.Id == role.Id)
                {
                    overwrite = o;
                    break;
                }
            }

            var emb = new DiscordEmbedBuilder
            {
                Title = $"Permissions for {role.ToString()} in {channel.ToString()}:",
                Color = this.ModuleColor
            };

            if (!(overwrite is null))
            {
                emb.AddField("Allowed", overwrite.Allowed.ToPermissionString())
                .AddField("Denied", overwrite.Denied.ToPermissionString());
            }
示例#3
0
 public Overwrite(DiscordOverwrite ov, DiscordGuild guild)
 {
     this.Type  = ov.Type;
     this.Allow = ov.Allowed;
     this.Deny  = ov.Denied;
     this.Id    = ov.Id;
     _guild     = guild;
 }
示例#4
0
        private void CalculateChangedOverwrite(DiscordOverwrite owsB, DiscordOverwrite owsA)
        {
            var deniedBefore  = Array.ConvertAll(owsB.Denied.ToPermissionString().Split(','), x => x.Trim());
            var allowedBefore = Array.ConvertAll(owsB.Allowed.ToPermissionString().Split(','), x => x.Trim());
            var deniedAfter   = Array.ConvertAll(owsA.Denied.ToPermissionString().Split(','), x => x.Trim());
            var allowedAfter  = Array.ConvertAll(owsA.Allowed.ToPermissionString().Split(','), x => x.Trim());

            Changes = new List <string>();

            foreach (string allPermA in allowedAfter) //calc allowed
            {
                if (allowedBefore.Contains(allPermA))
                {
                    continue;
                }

                //we have overwrite(a or d or n) we need to find where he has before
                if (deniedBefore.Contains(allPermA)) // d -> a
                {
                    Changes.Add($"{allPermA}: :x: -> :white_check_mark:");
                }
                else //n -> a
                {
                    Changes.Add($"{allPermA}: :white_large_square: -> :white_check_mark:");
                }
            }
            foreach (string denPermA in deniedAfter) // calc denied
            {
                if (deniedBefore.Contains(denPermA))
                {
                    continue;
                }

                if (allowedBefore.Contains(denPermA)) // a -> d
                {
                    Changes.Add($"{denPermA}: :white_check_mark: -> :x:");
                }
                else // d -> a
                {
                    Changes.Add($"{denPermA}: :white_large_square: -> :x:");
                }
            }
            foreach (string denPermB in deniedBefore)
            {
                if (!deniedAfter.Contains(denPermB) && !allowedAfter.Contains(denPermB)) //den
                {
                    Changes.Add($"{denPermB}: :x: -> :white_large_square:");
                }
            }
            foreach (string allPermB in allowedBefore)
            {
                if (!deniedAfter.Contains(allPermB) && !allowedAfter.Contains(allPermB)) //den
                {
                    Changes.Add($"{allPermB}: :white_check_mark: -> :white_large_square:");
                }
            }
        }
示例#5
0
        public ChannelPermissionViewModel(Permissions permission, DiscordOverwrite overwrite, ResourceLoader loader)
        {
            _overwrite = overwrite;

            Permission = permission;
            Title      = loader.GetString($"{permission}Title");
            Subtitle   = loader.GetString($"{permission}Subtitle");
            Allowed    = overwrite.Allowed;
            Denied     = overwrite.Denied;
        }
示例#6
0
        public OverwriteUpdateInformation(IReadOnlyList <DiscordOverwrite> rolesOwsBefore, IReadOnlyList <DiscordOverwrite> rolesOwsAfter)
        {
            if (TryFindDistinctOverwrite(rolesOwsBefore, rolesOwsAfter, out AffectedOverwrite))
            {
                Action = "Удаление"; return;
            }
            else if (TryFindDistinctOverwrite(rolesOwsAfter, rolesOwsBefore, out AffectedOverwrite))
            {
                Action = "Добавление"; return;
            }


            foreach (var owsB in rolesOwsBefore)                                                                                           //Initializing array of permissions for some roles
            {
                var rawOverwrite = rolesOwsAfter.Where((x) => owsB.Id == x.Id && !(owsB.Allowed == x.Allowed && owsB.Denied == x.Denied)); // no elements
                if (rawOverwrite.Count() > 0)
                {
                    AffectedOverwrite = rawOverwrite.First();
                    CalculateChangedOverwrite(owsB, AffectedOverwrite);
                    Action = "Изменение";
                    return;
                }
            }
        }
示例#7
0
 /// <summary>
 /// Finds SINGLE value in this list that distinct from otherList
 /// </summary>
 /// <param name=""></param>
 /// <param name=""></param>
 /// <returns></returns>
 private bool TryFindDistinctOverwrite(IReadOnlyList <DiscordOverwrite> firstList, IReadOnlyList <DiscordOverwrite> secondList, out DiscordOverwrite distinctValue)
 {
     distinctValue = null;
     foreach (var v in firstList)
     {
         if (!secondList.Any((x) => x.Id == v.Id)) //if no values from other list does not match potentially new value(v), then returns true
         {
             distinctValue = v;
             return(true);
         }
     }
     return(false);
 }