@@ -23,10 +23,10 @@ namespace Discord.Interactions | |||||
_fileName = fileName; | _fileName = fileName; | ||||
} | } | ||||
public Task<IDictionary<string, string>> GetAllDescriptionsAsync(IList<string> key, LocalizationTarget destinationType, IServiceProvider serviceProvider) => | |||||
public Task<IDictionary<string, string>> GetAllDescriptionsAsync(IList<string> key, LocalizationTarget destinationType) => | |||||
GetValuesAsync(key, DescriptionIdentifier); | GetValuesAsync(key, DescriptionIdentifier); | ||||
public Task<IDictionary<string, string>> GetAllNamesAsync(IList<string> key, LocalizationTarget destinationType, IServiceProvider serviceProvider) => | |||||
public Task<IDictionary<string, string>> GetAllNamesAsync(IList<string> key, LocalizationTarget destinationType) => | |||||
GetValuesAsync(key, NameIdentifier); | GetValuesAsync(key, NameIdentifier); | ||||
private string[] GetAllFiles() => | private string[] GetAllFiles() => | ||||
@@ -50,7 +50,8 @@ namespace Discord.Interactions | |||||
var obj = await JObject.LoadAsync(jr); | var obj = await JObject.LoadAsync(jr); | ||||
var token = string.Join(".", key) + $".{identifier}"; | var token = string.Join(".", key) + $".{identifier}"; | ||||
var value = (string)obj.SelectToken(token); | var value = (string)obj.SelectToken(token); | ||||
result[locale] = value; | |||||
if (value is not null) | |||||
result[locale] = value; | |||||
} | } | ||||
return result; | return result; | ||||
@@ -25,10 +25,10 @@ namespace Discord.Interactions | |||||
_supportedLocales = supportedLocales; | _supportedLocales = supportedLocales; | ||||
} | } | ||||
public Task<IDictionary<string, string>> GetAllDescriptionsAsync(IList<string> key, LocalizationTarget destinationType, IServiceProvider serviceProvider) => | |||||
public Task<IDictionary<string, string>> GetAllDescriptionsAsync(IList<string> key, LocalizationTarget destinationType) => | |||||
Task.FromResult(GetValues(key, DescriptionIdentifier)); | Task.FromResult(GetValues(key, DescriptionIdentifier)); | ||||
public Task<IDictionary<string, string>> GetAllNamesAsync(IList<string> key, LocalizationTarget destinationType, IServiceProvider serviceProvider) => | |||||
public Task<IDictionary<string, string>> GetAllNamesAsync(IList<string> key, LocalizationTarget destinationType) => | |||||
Task.FromResult(GetValues(key, NameIdentifier)); | Task.FromResult(GetValues(key, NameIdentifier)); | ||||
private IDictionary<string, string> GetValues(IList<string> key, string identifier) | private IDictionary<string, string> GetValues(IList<string> key, string identifier) | ||||
@@ -39,7 +39,11 @@ namespace Discord.Interactions | |||||
var resourceManager = _localizerCache.GetOrAdd(resourceName, new ResourceManager(resourceName, _assembly)); | var resourceManager = _localizerCache.GetOrAdd(resourceName, new ResourceManager(resourceName, _assembly)); | ||||
foreach (var locale in _supportedLocales) | foreach (var locale in _supportedLocales) | ||||
result[locale.Name] = resourceManager.GetString(identifier, locale); | |||||
{ | |||||
var value = resourceManager.GetString(identifier, locale); | |||||
if (value is not null) | |||||
result[locale.Name] = value; | |||||
} | |||||
return result; | return result; | ||||
} | } | ||||
@@ -42,7 +42,7 @@ namespace Discord.Interactions | |||||
public void RemoveCommand(T command) | public void RemoveCommand(T command) | ||||
{ | { | ||||
var key = ParseCommandName(command); | |||||
var key = CommandHierarchy.GetCommandPath(command); | |||||
_root.RemoveCommand(key, 0); | _root.RemoveCommand(key, 0); | ||||
} | } | ||||
@@ -60,28 +60,9 @@ namespace Discord.Interactions | |||||
private void AddCommand(T command) | private void AddCommand(T command) | ||||
{ | { | ||||
var key = ParseCommandName(command); | |||||
var key = CommandHierarchy.GetCommandPath(command); | |||||
_root.AddCommand(key, 0, command); | _root.AddCommand(key, 0, command); | ||||
} | } | ||||
private IList<string> ParseCommandName(T command) | |||||
{ | |||||
var keywords = new List<string>() { command.Name }; | |||||
var currentParent = command.Module; | |||||
while (currentParent != null) | |||||
{ | |||||
if (!string.IsNullOrEmpty(currentParent.SlashGroupName)) | |||||
keywords.Add(currentParent.SlashGroupName); | |||||
currentParent = currentParent.Parent; | |||||
} | |||||
keywords.Reverse(); | |||||
return keywords; | |||||
} | |||||
} | } | ||||
} | } |