Using generic attributes for NadekoOptions now. Updated packages

This commit is contained in:
Kwoth
2023-01-21 02:21:08 +01:00
parent f0ac087fdb
commit affaaf2fab
26 changed files with 92 additions and 422 deletions

View File

@@ -88,7 +88,7 @@ public partial class Help : NadekoModule<HelpService>
embed = embed.WithOkColor().WithDescription(GetText(strs.module_page_empty));
return embed;
}
localModules.OrderBy(module => module.Name)
.ToList()
.ForEach(module => embed.AddField($"{GetModuleEmoji(module.Name)} {module.Name}",
@@ -111,10 +111,11 @@ public partial class Help : NadekoModule<HelpService>
if (key.Key == strs.module_description_missing.Key)
{
var desc = _medusae
.GetLoadedMedusae(Culture)
.FirstOrDefault(m => m.Sneks
.Any(x => x.Name.Equals(moduleName, StringComparison.InvariantCultureIgnoreCase)))
?.Description;
.GetLoadedMedusae(Culture)
.FirstOrDefault(m => m.Sneks
.Any(x => x.Name.Equals(moduleName,
StringComparison.InvariantCultureIgnoreCase)))
?.Description;
if (desc is not null)
return desc;
@@ -122,7 +123,7 @@ public partial class Help : NadekoModule<HelpService>
return GetText(key);
}
private LocStr GetModuleLocStr(string moduleName)
{
switch (moduleName.ToLowerInvariant())
@@ -189,7 +190,7 @@ public partial class Help : NadekoModule<HelpService>
}
[Cmd]
[NadekoOptions(typeof(CommandsOptions))]
[NadekoOptions<CommandsOptions>]
public async Task Commands(string module = null, params string[] args)
{
module = module?.Trim().ToUpperInvariant();
@@ -374,9 +375,8 @@ public partial class Help : NadekoModule<HelpService>
.Select(com =>
{
List<string> optHelpStr = null;
var opt = ((NadekoOptionsAttribute)com.Attributes.FirstOrDefault(static x
=> x is NadekoOptionsAttribute))
?.OptionType;
var opt = HelpService.GetNadekoOptionType(com.Attributes);
if (opt is not null)
optHelpStr = HelpService.GetCommandOptionHelpList(opt);
@@ -512,7 +512,7 @@ public partial class Help : NadekoModule<HelpService>
customId: "donate:selfhosting",
label: "Selfhosting"),
SelfhostAction));
var eb = _eb.Create(ctx)
.WithOkColor()
.WithTitle("Thank you for considering to donate to the NadekoBot project!");

View File

@@ -86,7 +86,7 @@ public class HelpService : IExecNoCommand, INService
.WithFooter(GetText(strs.module(com.Module.GetTopLevelModule().Name), guild))
.WithOkColor();
var opt = ((NadekoOptionsAttribute)com.Attributes.FirstOrDefault(x => x is NadekoOptionsAttribute))?.OptionType;
var opt = GetNadekoOptionType(com.Attributes);
if (opt is not null)
{
var hs = GetCommandOptionHelp(opt);
@@ -97,6 +97,14 @@ public class HelpService : IExecNoCommand, INService
return em;
}
public static Type GetNadekoOptionType(IEnumerable<Attribute> attributes)
=> attributes
.Select(a => a.GetType())
.Where(a => a.IsGenericType
&& a.GetGenericTypeDefinition() == typeof(NadekoOptionsAttribute<>))
.Select(a => a.GenericTypeArguments[0])
.FirstOrDefault();
public static string GetCommandOptionHelp(Type opt)
{
var strs = GetCommandOptionHelpList(opt);