Browse Source

add utils class for getting command paths

pull/2211/head
Cenngo 3 years ago
parent
commit
13fddbf4ab
1 changed files with 53 additions and 0 deletions
  1. +53
    -0
      src/Discord.Net.Interactions/Utilities/CommandHierarchy.cs

+ 53
- 0
src/Discord.Net.Interactions/Utilities/CommandHierarchy.cs View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;

namespace Discord.Interactions
{
internal static class CommandHierarchy
{
public const char EscapeChar = '$';

public static IList<string> GetModulePath(this ModuleInfo moduleInfo)
{
var result = new List<string>();

var current = moduleInfo;
while (current is not null)
{
if (current.IsSlashGroup)
result.Insert(0, current.SlashGroupName);

current = current.Parent;
}

return result;
}

public static IList<string> GetCommandPath(this ICommandInfo commandInfo)
{
if (commandInfo.IgnoreGroupNames)
return new string[] { commandInfo.Name };

var path = commandInfo.Module.GetModulePath();
path.Insert(0, commandInfo.Name);
return path;
}

public static IList<string> GetParameterPath(this IParameterInfo parameterInfo)
{
var path = parameterInfo.Command.GetCommandPath();
path.Insert(0, parameterInfo.Name);
return path;
}

public static IList<string> GetChoicePath(this IParameterInfo parameterInfo, ParameterChoice choice)
{
var path = parameterInfo.GetParameterPath();
path.Insert(0, choice.Name);
return path;
}

public static IList<string> GetTypePath(Type type) =>
new string[] { EscapeChar + type.FullName };
}
}

Loading…
Cancel
Save