/// <summary>
        /// The CheckPermissionsAsync is an overriden method from its superclass, which checks
        /// to see if a command can be run by a user through their roles that they have applied.
        /// </summary>
        /// <param name="CommandContext">The Context is used to find the user who has run the command.</param>
        /// <param name="CommandInfo">The Command is used to find the name of the command that has been run.</param>
        /// <param name="ServiceProvider">The Services are used to find the role IDs to get the permission level of the user from the BotConfiguration.</param>
        /// <returns>The result of the checked permission, returning successful if it is able to be run or an error if not.
        /// This error is then thrown to the Command Handler Service to log to the user.</returns>

        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext CommandContext, CommandInfo CommandInfo, IServiceProvider ServiceProvider)
        {
            BotConfiguration BotConfiguration = ServiceProvider.GetService <BotConfiguration>();

            if (ServiceProvider.GetService <HelpAbstraction>() != null)
            {
                BotConfiguration = ServiceProvider.GetService <HelpAbstraction>().BotConfiguration;
            }

            DiscordSocketClient DiscordSocketClient = ServiceProvider.GetService <DiscordSocketClient>();

            if (ServiceProvider.GetService <HelpAbstraction>() != null)
            {
                DiscordSocketClient = ServiceProvider.GetService <HelpAbstraction>().DiscordSocketClient;
            }

            if (BotConfiguration == null)
            {
                return(Task.FromResult(PreconditionResult.FromSuccess()));
            }

            return(Task.FromResult(CommandContext.User.GetPermissionLevel(DiscordSocketClient, BotConfiguration) >= PermissionLevel
                ? PreconditionResult.FromSuccess()
                : PreconditionResult.FromError($"Haiya! To run the `{CommandInfo.Name}` command you need to have the " +
                                               $"`{PermissionLevel}` role! Are you sure you're {LanguageHelper.GuessIndefiniteArticle(PermissionLevel.ToString())} " +
                                               $"`{PermissionLevel.ToString().ToLower()}`? <3")));
        }
示例#2
0
        public DiscordEmbed ToEmbed()
        {
            DiscordEmbedBuilder builder = new DiscordEmbedBuilder();

            builder.Title       = "XanBotMember Info";
            builder.Description = "Member: " + Mention;
            builder.AddField("Basic Information", $"**Display Name:** {DisplayName}\n**Username:** {Username}\n**Discriminator:** {Discriminator}\n**GUID:** {Id}");
            builder.AddField("Parent Context", Context.ToString());
            builder.AddField("Permission Level", PermissionLevel.ToString());
            return(builder.Build());
        }
示例#3
0
        public PermissionGroupCollection GetPermissionGroup(PermissionLevel permissionLevel)
        {
            switch (permissionLevel.ToString())
            {
            case PermissionLevel.AuthorRoleName:
                return(Gma);

            case PermissionLevel.ReaderRoleName:
                return(Gmr);

            case PermissionLevel.ProjectManagerRoleName:
                return(Gpm);

            case PermissionLevel.MapManagerRoleName:
                return(Gmm);

            default:
                return(null);
            }
        }
示例#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);
        }