NadekoBot Patronage system, Search commands improvements + fixes

This commit is contained in:
Kwoth
2022-06-14 07:24:33 +00:00
parent 18b10b8c6f
commit 7b5145f116
165 changed files with 14920 additions and 1457 deletions

View File

@@ -0,0 +1,10 @@
#nullable disable
using System.Runtime.InteropServices;
namespace NadekoBot.Modules.Permissions;
[StructLayout(LayoutKind.Sequential, Size = 1)]
public readonly struct CleverBotResponseStr
{
public const string CLEVERBOT_RESPONSE = "cleverbot:response";
}

View File

@@ -0,0 +1,15 @@
#nullable disable
using NadekoBot.Common.TypeReaders;
using static NadekoBot.Common.TypeReaders.TypeReaderResult;
namespace NadekoBot.Modules.Permissions;
public class CleverbotResponseCmdCdTypeReader : NadekoTypeReader<CleverBotResponseStr>
{
public override ValueTask<TypeReaderResult<CleverBotResponseStr>> ReadAsync(
ICommandContext ctx,
string input)
=> input.ToLowerInvariant() == CleverBotResponseStr.CLEVERBOT_RESPONSE
? new(FromSuccess(new CleverBotResponseStr()))
: new(FromError<CleverBotResponseStr>(CommandError.ParseFailed, "Not a valid cleverbot"));
}

View File

@@ -27,9 +27,7 @@ public partial class Permissions
_db = db;
}
[Cmd]
[RequireContext(ContextType.Guild)]
public async partial Task CmdCooldown(CommandOrCrInfo command, int secs)
private async Task CmdCooldownInternal(string cmdName, int secs)
{
var channel = (ITextChannel)ctx.Channel;
if (secs is < 0 or > 3600)
@@ -38,7 +36,7 @@ public partial class Permissions
return;
}
var name = command.Name.ToLowerInvariant();
var name = cmdName.ToLowerInvariant();
await using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.CommandCooldowns));
@@ -71,6 +69,18 @@ public partial class Permissions
else
await ReplyConfirmLocalizedAsync(strs.cmdcd_add(Format.Bold(name), Format.Bold(secs.ToString())));
}
[Cmd]
[RequireContext(ContextType.Guild)]
[Priority(0)]
public partial Task CmdCooldown(CleverBotResponseStr command, int secs)
=> CmdCooldownInternal(CleverBotResponseStr.CLEVERBOT_RESPONSE, secs);
[Cmd]
[RequireContext(ContextType.Guild)]
[Priority(1)]
public partial Task CmdCooldown(CommandOrCrInfo command, int secs)
=> CmdCooldownInternal(command.Name, secs);
[Cmd]
[RequireContext(ContextType.Guild)]