Exemplo n.º 1
0
        public string Display(bool allowTooltips = true)
        {
            var result = new StringBuilder();

            List <PropertyInfo> properties = GetType()
                                             .GetProperties()
                                             .Where(x => x.GetCustomAttribute <IgnoreAttribute>() == null)
                                             .ToList();

            if (allowTooltips && properties.Any())
            {
                var tooltips = new List <string>
                {
                    "If an ID is unspecified, you can use their name instead as input.",
                    "Type `config <id>` to view more details about a specific option.",
                    "Type `config <id> <value>` to update the value of a specific option."
                };

                result.AppendLine(Format.Tooltip(tooltips));
                result.AppendLine();
            }

            result.AppendLine("> 🔩 **Guild Configuration**");

            if (!properties.Any())
            {
                result.AppendLine("> There are no options to configure at this time.");
                return(result.ToString());
            }

            foreach (PropertyInfo option in properties)
            {
                string id      = option.GetCustomAttribute <IdAttribute>()?.Id;
                string title   = option.GetCustomAttribute <TitleAttribute>()?.Name ?? option.Name;
                string summary = option.GetCustomAttribute <DescriptionAttribute>()?.Content;
                string value   = WriteOptionValue(option.GetValue(this, null));

                result.AppendLine();

                if (!string.IsNullOrWhiteSpace(id))
                {
                    result.AppendLine($"> `{id}`");
                }

                result.AppendLine($"> **{title}**: `{value}`");

                if (!string.IsNullOrWhiteSpace(summary))
                {
                    result.AppendLine($"> {summary}");
                }
            }

            return(result.ToString());
        }
Exemplo n.º 2
0
        public string ViewOption(PropertyInfo option, bool allowTooltips = true)
        {
            var            result    = new StringBuilder();
            ClampAttribute clamp     = option.GetCustomAttribute <ClampAttribute>();
            string         id        = option.GetCustomAttribute <IdAttribute>()?.Id ?? option.Name.ToLower();
            string         title     = option.GetCustomAttribute <TitleAttribute>()?.Name ?? option.Name;
            string         summary   = option.GetCustomAttribute <DescriptionAttribute>()?.Content;
            string         value     = WriteOptionValue(option.GetValue(this, null));
            string         valueType = WriteOptionType(option);

            Type type = option.GetValue(this, null)?.GetType();

            if (allowTooltips)
            {
                string        tipBase  = $"config {id}";
                List <string> tooltips = option.GetCustomAttribute <TooltipAttribute>()?.Tips.ToList() ?? new List <string>();

                bool useFlags = type?.GetCustomAttribute <FlagsAttribute>() != null;

                if (clamp != null && type != null && type == typeof(int))
                {
                    if (clamp.HasMin)
                    {
                        tooltips.Add($"Type `{tipBase} --min` to set the lowest possible value.");
                    }

                    tooltips.Add($"Type `{tipBase} --max` to set the highest possible value.");
                }

                if (type != null && type.IsEnum)
                {
                    if (useFlags)
                    {
                        tooltips.Add($"Type `{tipBase} --clear` to clear all specified values.");
                        tooltips.Add($"Type `{tipBase} --all` to set all possible values.");
                        tooltips.Add($"You can chain values together by typing the sum of each flag you want to toggle.");
                        tooltips.Add($"Specifying an active flag will disable it.");
                    }
                }

                tooltips.Add($"Type `{tipBase} --default` to revert to its default value.");
                tooltips.Add($"Type `{tipBase} <value>` to update its current value.");

                result.AppendLine(Format.Tooltip(tooltips));
                result.AppendLine();
            }

            result.AppendLine($"> **{title}**");

            if (!string.IsNullOrWhiteSpace(summary))
            {
                result.AppendLine($"> {summary}");
            }

            result.AppendLine($"> Current Value: `{value}`");
            result.AppendLine($"> Value Type: `{valueType}`");

            if (clamp != null)
            {
                if (!clamp.HasMin)
                {
                    if (type == typeof(string))
                    {
                        result.AppendLine($"> Max Allowed Length: `{clamp.Max}`");
                    }
                    else
                    {
                        result.AppendLine($"> Limit: `{clamp.Max}`");
                    }
                }
                else
                {
                    result.AppendLine($"> Value Range: `{clamp.Min} to {clamp.Max}`");
                }
            }

            if (type != null && type.IsEnum)
            {
                List <string> names  = type.GetEnumNames().ToList();
                List <long>   values = type.GetEnumValues().Cast <object>().Select(Convert.ToInt64).ToList();

                IEnumerable <string> groups = names.Join(values,
                                                         a => names.IndexOf(a),
                                                         b => values.IndexOf(b),
                                                         (a, b) => $"{a} = {b}");

                if (groups.Any())
                {
                    result.AppendLine($"\n> **Values**\n```cs");
                    result.AppendJoin(",\n", groups);
                    result.Append("```");
                }
            }

            if (allowTooltips)
            {
                IEnumerable <string> details = option.GetCustomAttribute <DetailsAttribute>()?.Details;

                if (details?.Any() ?? false)
                {
                    result.AppendLine($"\n> 🛠️ **Details**");
                    result.AppendJoin("\n", details.Select(x => $"• {x}"));
                }
            }

            return(result.ToString());
        }