Пример #1
0
        public async Task VerCargoAsync(CommandContext ctx, DiscordRole cargo = null)
        {
            await ctx.TriggerTypingAsync();

            DiscordEmbedBuilder embed = new DiscordEmbedBuilder();

            if (cargo == null)
            {
                embed.WithColor(Program.Bot.Utilities.HelpCommandsColor())
                .WithAuthor("Como executar este comando:", null, Values.infoLogo)
                .AddField("PC/Mobile", $"{ctx.Prefix}dev vr[ID/Nome entre \"\"]")
                .WithTimestamp(DateTime.Now)
                .WithFooter($"Comando requisitado pelo: {Program.Bot.Utilities.DiscordNick(ctx.Member)}", iconUrl: ctx.Member.AvatarUrl);

                await ctx.RespondAsync(embed : embed.Build());

                return;
            }

            DiscordMessage msgAguarde = await ctx.RespondAsync($"Aguarde... {Program.Bot.Utilities.FindEmoji(ctx, "leofsjal")}");

            List <DiscordMember> membrosUBGE      = (await ctx.Guild.GetAllMembersAsync()).ToList();
            List <DiscordMember> membrosComOCargo = membrosUBGE.FindAll(x => x.Roles.ToList().Contains(cargo));

            await msgAguarde.DeleteAsync();

            embed.AddField("Admin?:", cargo.CheckPermission(Permissions.Administrator) == PermissionLevel.Allowed ? "**Sim**" : "**Não**", false)
            .AddField("Mencionável?:", cargo.IsMentionable ? "**Sim**" : "**Não**", false)
            .AddField("ID:", cargo.Id.ToString(), false)
            .AddField("Quantidade de membros com este cargo:", $"{(membrosComOCargo.Count > 1 ? $"**{membrosComOCargo.Count}** membros." : $"**{membrosComOCargo.Count}** membro.")}", false)
Пример #2
0
 public static async Task GrantPermissions(this DiscordChannel channel, DiscordRole role, Permissions allow, Permissions deny)
 {
     if (role.CheckPermission(allow) != PermissionLevel.Allowed)
     {
         await channel.AddOverwriteAsync(role, allow, deny, $"Setting @{role.Name} role permissions for channel #team_{role.Name}.");
     }
 }
Пример #3
0
        private RolePermissions VanillaApplyMappings(DiscordRole Role)
        {
            PermissionMapping mapping = PermissionMapping.Deserialize("complete");

            foreach (KeyValuePair <Int64, String[]> v in mapping.Mappings)
            {
                if (Role.CheckPermission((DSharpPlus.Permissions)v.Key) == PermissionLevel.Allowed)
                {
                    GrantRolePermissions(Role.Id, v.Value);
                }
            }

            return(RolePermissions.Deserialize(Role.Id));
        }
Пример #4
0
        /// <summary>
        /// Returns a formatted string showing the permission differences for the specified role.<para/>
        /// Intended for use in a <see cref="DiscordMessage"/> or <see cref="DiscordEmbed"/>
        /// </summary>
        /// <param name="oldRole"></param>
        /// <param name="newRole"></param>
        /// <returns></returns>
        public static string GetRolePermissionDiffs(DiscordRole oldRole, DiscordRole newRole)
        {
            StringBuilder diffs = new StringBuilder();

            foreach (DSharpPlus.Permissions permission in Enum.GetValues(typeof(DSharpPlus.Permissions)))
            {
                PermissionLevel oldLvl = oldRole.CheckPermission(permission);
                PermissionLevel newLvl = newRole.CheckPermission(permission);
                if (oldLvl != newLvl)
                {
                    diffs.AppendLine($"**{permission.ToPermissionString()}**: {oldLvl.ToString()} => {newLvl.ToString()}");
                }
            }
            string ret = diffs.ToString();

            if (ret.Length == 0)
            {
                return("No changes");
            }
            return(ret);
        }