コード例 #1
0
        ApplicationCommandOption getOptionRep(CommandNode node)
        {
            ApplicationCommandOption option = new ApplicationCommandOption();
            option.Name = node.Name;
            option.Description = "Test: " + node.Name;

            if (node is LiteralNode)
            {
                var nodes = node.GetChildNodes().Map(n => n.GetChildNodes()).ToList();
                if (node.EndNode || nodes.All(i => i is IArgumentNode))
                {
                    option.Type = ApplicationCommandOptionType.SubCommand;    
                }
                else
                {
                    option.Type = ApplicationCommandOptionType.SubCommandGroup;
                }
                
            }
            else if (node is ArgumentNode<DiscordUser> userArg)
            {
                option.Type = ApplicationCommandOptionType.User;
                option.Required = true;
            }
            else if(node is ArgumentNode<string> stringArg)
            {
                option.Type = ApplicationCommandOptionType.String;
                option.Required = true;
            }
            else if(node is ArgumentNode<int>)
            {
                option.Type = ApplicationCommandOptionType.Integer;
                option.Required = true;
            }
            
            return option;
        }
コード例 #2
0
        ApplicationCommandOption? GetOption(CommandNode node)
        {
            ApplicationCommandOption option = getOptionRep(node);

            var options = new List<ApplicationCommandOption>();

            //All the sub nodes are arguments, we need to flatten them
            var nodes = node.GetChildNodes().Map(n => n.GetChildNodes()).ToList();
            if (nodes.All(i => i is IArgumentNode))
            {
                options.AddRange(nodes.Select(getOptionRep));
            }
            else
            {
                foreach (var n in node.GetChildNodes())
                {
                    options.Add(GetOption(n));
                }    
            }

            option.Options = options.ToArray();
            
            return option;
        }