示例#1
0
        public static string DecodePrecondition(this PreconditionAttribute precondition)
        {
            switch (precondition)
            {
            case RequireNsfwAttribute:
                return("NSFW channel");

            case RequireUserPermissionAttribute attr:
            {
                string decode = attr.ChannelPermission.HasValue
                        ? $"Channel Permission {attr.ChannelPermission.ToString()?.AsCode()}"
                        : string.Empty;
                decode += (string.IsNullOrWhiteSpace(decode) ? string.Empty : ", ") + (attr.GuildPermission.HasValue
                        ? $"Guild Permission {attr.GuildPermission.ToString()?.AsCode()}"
                        : string.Empty);
                return(decode);
            }

            case RequireContextAttribute attr:
                return(string.Join(" or ", attr.Contexts.ToString("G").Split(", ")) + " Context");

            default:
                return(precondition.GetType().Name);
            }
        }
示例#2
0
        Div explainPrecondition(PreconditionAttribute attribute, bool module)
        {
            string summary;
            string type = module ? "This module " : "This command ";

            if (attribute is RequireContextAttribute rca)
            {
                summary = $"must be executed in a {rca.Contexts}";
            }
            else if (attribute is RequireUserPermissionAttribute rupa)
            {
                summary = $"must be executed by a user who has the following permission:<br/>" +
                          htmlListPerms(rupa.ChannelPermission, rupa.GuildPermission);
            }
            else if (attribute is RequireOwnerAttribute)
            {
                summary = $"must be executed by the Owner of the bot";
            }
            else if (attribute is RequireBotPermissionAttribute rbpa)
            {
                summary = $"requires the bot's account to have the following permissions:<br/>" +
                          htmlListPerms(rbpa.ChannelPermission, rbpa.GuildPermission);
            }
            else if (attribute is RequirePermission rp)
            {
                summary = $"must be executed by a user who has the <code>{rp.Node}</code> permission";
            }
            else
            {
                summary = attribute.GetType().Name.Replace("Attribute", "");
            }
            return(warn(type + summary));
        }