mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Using generic attributes for NadekoOptions now. Updated packages
This commit is contained in:
@@ -27,10 +27,10 @@ public partial class Administration
|
||||
//deletes her own messages, no perm required
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptions(typeof(PruneOptions))]
|
||||
[NadekoOptions<PruneOptions>]
|
||||
public async Task Prune(params string[] args)
|
||||
{
|
||||
var (opts, _) = OptionsParser.ParseFrom<PruneOptions>(new PruneOptions(), args);
|
||||
var (opts, _) = OptionsParser.ParseFrom(new PruneOptions(), args);
|
||||
|
||||
var user = await ctx.Guild.GetCurrentUserAsync();
|
||||
|
||||
@@ -47,7 +47,7 @@ public partial class Administration
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(ChannelPerm.ManageMessages)]
|
||||
[BotPerm(ChannelPerm.ManageMessages)]
|
||||
[NadekoOptions(typeof(PruneOptions))]
|
||||
[NadekoOptions<PruneOptions>]
|
||||
[Priority(1)]
|
||||
public async Task Prune(int count, params string[] args)
|
||||
{
|
||||
@@ -70,7 +70,7 @@ public partial class Administration
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(ChannelPerm.ManageMessages)]
|
||||
[BotPerm(ChannelPerm.ManageMessages)]
|
||||
[NadekoOptions(typeof(PruneOptions))]
|
||||
[NadekoOptions<PruneOptions>]
|
||||
[Priority(0)]
|
||||
public Task Prune(IGuildUser user, int count = 100, params string[] args)
|
||||
=> Prune(user.Id, count, args);
|
||||
@@ -80,7 +80,7 @@ public partial class Administration
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(ChannelPerm.ManageMessages)]
|
||||
[BotPerm(ChannelPerm.ManageMessages)]
|
||||
[NadekoOptions(typeof(PruneOptions))]
|
||||
[NadekoOptions<PruneOptions>]
|
||||
[Priority(0)]
|
||||
public async Task Prune(ulong userId, int count = 100, params string[] args)
|
||||
{
|
||||
|
@@ -97,7 +97,7 @@ public partial class Administration
|
||||
{
|
||||
var logSetting = _service.GetGuildLogSettings(ctx.Guild.Id);
|
||||
var str = string.Join("\n",
|
||||
Enum.GetNames(typeof(LogType))
|
||||
Enum.GetNames<LogType>()
|
||||
.Select(x =>
|
||||
{
|
||||
var val = logSetting is null ? null : GetLogProperty(logSetting, Enum.Parse<LogType>(x));
|
||||
|
@@ -114,7 +114,7 @@ public partial class Administration
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
[NadekoOptions(typeof(WarnExpireOptions))]
|
||||
[NadekoOptions<WarnExpireOptions>]
|
||||
[Priority(1)]
|
||||
public async Task WarnExpire()
|
||||
{
|
||||
@@ -129,7 +129,7 @@ public partial class Administration
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
[NadekoOptions(typeof(WarnExpireOptions))]
|
||||
[NadekoOptions<WarnExpireOptions>]
|
||||
[Priority(2)]
|
||||
public async Task WarnExpire(int days, params string[] args)
|
||||
{
|
||||
|
@@ -34,7 +34,7 @@ public partial class Gambling
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptionsAttribute(typeof(RaceOptions))]
|
||||
[NadekoOptions<RaceOptions>]
|
||||
public Task Race(params string[] args)
|
||||
{
|
||||
var (options, _) = OptionsParser.ParseFrom(new RaceOptions(), args);
|
||||
|
@@ -44,7 +44,7 @@ public partial class Gambling
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptionsAttribute(typeof(Connect4Game.Options))]
|
||||
[NadekoOptions<Connect4Game.Options>]
|
||||
public async Task Connect4(params string[] args)
|
||||
{
|
||||
var (options, _) = OptionsParser.ParseFrom(new Connect4Game.Options(), args);
|
||||
|
@@ -18,7 +18,7 @@ public partial class Gambling
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptionsAttribute(typeof(EventOptions))]
|
||||
[NadekoOptions<EventOptions>]
|
||||
[OwnerOnly]
|
||||
public async Task EventStart(CurrencyEvent.Type ev, params string[] options)
|
||||
{
|
||||
|
@@ -710,13 +710,13 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[NadekoOptions(typeof(LbOpts))]
|
||||
[NadekoOptions<LbOpts>]
|
||||
[Priority(0)]
|
||||
public Task Leaderboard(params string[] args)
|
||||
=> Leaderboard(1, args);
|
||||
|
||||
[Cmd]
|
||||
[NadekoOptions(typeof(LbOpts))]
|
||||
[NadekoOptions<LbOpts>]
|
||||
[Priority(1)]
|
||||
public async Task Leaderboard(int page = 1, params string[] args)
|
||||
{
|
||||
|
@@ -17,7 +17,7 @@ public partial class Games
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptions(typeof(AcrophobiaGame.Options))]
|
||||
[NadekoOptions<AcrophobiaGame.Options>]
|
||||
public async Task Acrophobia(params string[] args)
|
||||
{
|
||||
var (options, _) = OptionsParser.ParseFrom(new AcrophobiaGame.Options(), args);
|
||||
|
@@ -20,7 +20,7 @@ public partial class Games
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptionsAttribute(typeof(TypingGame.Options))]
|
||||
[NadekoOptions<TypingGame.Options>]
|
||||
public async Task TypeStart(params string[] args)
|
||||
{
|
||||
var (options, _) = OptionsParser.ParseFrom(new TypingGame.Options(), args);
|
||||
|
@@ -17,7 +17,7 @@ public partial class Games
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptions(typeof(TicTacToe.Options))]
|
||||
[NadekoOptions<TicTacToe.Options>]
|
||||
public async Task TicTacToe(params string[] args)
|
||||
{
|
||||
var (options, _) = OptionsParser.ParseFrom(new TicTacToe.Options(), args);
|
||||
|
@@ -30,7 +30,7 @@ public partial class Games
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Priority(0)]
|
||||
[NadekoOptions(typeof(TriviaOptions))]
|
||||
[NadekoOptions<TriviaOptions>]
|
||||
public async Task Trivia(params string[] args)
|
||||
{
|
||||
var (opts, _) = OptionsParser.ParseFrom(new TriviaOptions(), args);
|
||||
|
@@ -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!");
|
||||
|
@@ -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);
|
||||
|
@@ -18,7 +18,7 @@ public partial class Searches
|
||||
Xoart //http://xoart.link
|
||||
}
|
||||
|
||||
private static readonly string _typesStr = string.Join(", ", Enum.GetNames(typeof(PlaceType)));
|
||||
private static readonly string _typesStr = string.Join(", ", Enum.GetNames<PlaceType>());
|
||||
|
||||
[Cmd]
|
||||
public async Task Placelist()
|
||||
|
@@ -12,7 +12,7 @@ public partial class Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[BotPerm(ChannelPerm.CreateInstantInvite)]
|
||||
[UserPerm(ChannelPerm.CreateInstantInvite)]
|
||||
[NadekoOptions(typeof(InviteService.Options))]
|
||||
[NadekoOptions<InviteService.Options>]
|
||||
public async Task InviteCreate(params string[] args)
|
||||
{
|
||||
var (opts, success) = OptionsParser.ParseFrom(new InviteService.Options(), args);
|
||||
|
@@ -155,14 +155,14 @@ public partial class Xp : NadekoModule<XpService>
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[NadekoOptions(typeof(LbOpts))]
|
||||
[NadekoOptions<LbOpts>]
|
||||
[Priority(0)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task XpLeaderboard(params string[] args)
|
||||
=> XpLeaderboard(1, args);
|
||||
|
||||
[Cmd]
|
||||
[NadekoOptions(typeof(LbOpts))]
|
||||
[NadekoOptions<LbOpts>]
|
||||
[Priority(1)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task XpLeaderboard(int page = 1, params string[] args)
|
||||
|
Reference in New Issue
Block a user