Merge pull request #933 from 13xforever/vnext

fix !filters add without argument
This commit is contained in:
clienthax 2023-05-05 23:42:44 +01:00 committed by GitHub
commit 0dbd833838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,21 +99,25 @@ internal sealed class ContentFilters: BaseCommandModuleCustom
[Command("add"), Aliases("create")] [Command("add"), Aliases("create")]
[Description("Adds a new content filter")] [Description("Adds a new content filter")]
public async Task Add(CommandContext ctx, [RemainingText, Description("A plain string to match")] string trigger) public async Task Add(CommandContext ctx, [RemainingText, Description("A plain string to match")] string? trigger)
{ {
trigger ??= "";
await using var db = new BotDb(); await using var db = new BotDb();
Piracystring? filter; Piracystring? filter;
var isNewFilter = true;
if (string.IsNullOrEmpty(trigger)) if (string.IsNullOrEmpty(trigger))
filter = new Piracystring(); filter = new() {String = trigger};
else else
{ {
filter = await db.Piracystring.FirstOrDefaultAsync(ps => ps.String == trigger && ps.Disabled).ConfigureAwait(false); filter = await db.Piracystring.FirstOrDefaultAsync(ps => ps.String == trigger && ps.Disabled).ConfigureAwait(false);
if (filter == null) if (filter == null)
filter = new Piracystring {String = trigger}; filter = new() {String = trigger};
else else
{
filter.Disabled = false; filter.Disabled = false;
isNewFilter = false;
}
} }
var isNewFilter = filter.Id == default;
if (isNewFilter) if (isNewFilter)
{ {
filter.Context = FilterContext.Chat | FilterContext.Log; filter.Context = FilterContext.Chat | FilterContext.Log;