Beispiel #1
0
 public InfoMatch(ModuleInfo module)
 {
     Type = Check.NotNull(module.Group) ? InfoType.Group : InfoType.Module;
     Name = module.Name;
     Id   = ContextNode.GetId(module);
 }
Beispiel #2
0
        public string GetPanel(string content = null, User user = null, bool drawActions = true, string prefix = "[")
        {
            if (!Check.NotNull(content))
            {
                return(GetMenu(user, drawActions));
            }

            if (Check.NotNullOrEmpty(Guides))
            {
                // TODO: Clean up chapter parsing (Regex).
                bool isGuideName = Guides.Any(x => content.ToLower().StartsWith(x.Id));
                bool hasIndex    = isGuideName && content.Split(' ').Count() == 2;

                if (isGuideName)
                {
                    if (hasIndex)
                    {
                        if (int.TryParse(content.Split(' ')[1], out int index))
                        {
                            return(Guides.First(x => content.ToLower().StartsWith(x.Id)).GetChapter(index));
                        }
                    }
                    else if (Guides.Any(x => x.Id == content.ToLower()))
                    {
                        return(Guides.First(x => x.Id == content.ToLower()).GetChapter(1));
                    }
                }
            }

            ContextNode ctx = Search(content, out string error);

            if (!string.IsNullOrWhiteSpace(error))
            {
                return(error);
            }

            bool allowTooltips = user?.Config?.Tooltips ?? true;
            var  panel         = new StringBuilder();

            if (allowTooltips)
            {
                /*
                 * string tooltip = ctx switch
                 * {
                 *  CommandNode c => $"> Use `help {ctx.Name}+<index>` to learn more about a specific command method.",
                 *  ModuleNode m when ctx.Type == InfoType.Group => $"> Use `help {ctx.Name} <command>` to learn more about a specific command method within a group.",
                 *  _ => ""
                 * };*/

                if (ctx.Type == InfoType.Command)
                {
                    if ((ctx as CommandNode).Overloads.Count > 1)
                    {
                        panel.AppendLine($"> 🛠️ Use `help {ctx.Name}+<index>` to learn more about a specific command overload.\n");
                    }
                }
                else if (ctx.Type == InfoType.Group)
                {
                    panel.AppendLine($"> 🛠️ Use `help {ctx.Name} <command>` to learn more about a specific command method within a group.\n");
                }
                else if (ctx.Type == InfoType.Module)
                {
                    panel.AppendLine("> 🛠️ Use `help <command>` to learn more about a specific command.\n");
                }
            }

            if (ctx is OverloadNode overload)
            {
                if (allowTooltips && overload.Parameters.Count > 0)
                {
                    panel.AppendLine($"> 🛠️ Use `help {ctx.Name}{(overload.Count > 1 ? $"+{overload.Index}" : "")}(<parameter>` to learn more about a specific parameter.\n");
                }

                SetExample(overload, prefix);
                ctx = overload;
            }

            panel.Append(ctx.ToString());
            return(panel.ToString());
        }
Beispiel #3
0
 public InfoMatch(CommandInfo command)
 {
     Type = InfoType.Command;
     Name = command.Name;
     Id   = ContextNode.GetId(command);
 }
Beispiel #4
0
 public static string GetSeverityIcon(ContextNode node)
 => GetSeverityIcon(node.Reports.Count(x => x.State == ReportState.Open));