Fixed an issue with expression settings toggle, closes #353

This commit is contained in:
Kwoth
2022-04-13 18:14:58 +02:00
parent e4b98a0c07
commit 6159d84988
2 changed files with 5 additions and 4 deletions

View File

@@ -241,7 +241,7 @@ public partial class NadekoExpressions : NadekoModule<NadekoExpressionsService>
return; return;
} }
var (success, newVal) = await _service.ToggleExprOptionAsync(id, option); var (success, newVal) = await _service.ToggleExprOptionAsync(ctx.Guild?.Id, id, option);
if (!success) if (!success)
{ {
await ReplyErrorLocalizedAsync(strs.expr_no_found_id); await ReplyErrorLocalizedAsync(strs.expr_no_found_id);

View File

@@ -448,14 +448,15 @@ public sealed class NadekoExpressionsService : IEarlyBehavior, IReadyExecutor
await UpdateInternalAsync(guildId, expr); await UpdateInternalAsync(guildId, expr);
} }
public async Task<(bool Sucess, bool NewValue)> ToggleExprOptionAsync(int id, ExprField field) public async Task<(bool Sucess, bool NewValue)> ToggleExprOptionAsync(ulong? guildId, int id, ExprField field)
{ {
var newVal = false; var newVal = false;
NadekoExpression expr; NadekoExpression expr;
await using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
expr = uow.Expressions.GetById(id); expr = uow.Expressions.GetById(id);
if (expr is null)
if (expr is null || expr.GuildId != guildId)
return (false, false); return (false, false);
if (field == ExprField.AutoDelete) if (field == ExprField.AutoDelete)
newVal = expr.AutoDeleteTrigger = !expr.AutoDeleteTrigger; newVal = expr.AutoDeleteTrigger = !expr.AutoDeleteTrigger;
@@ -469,7 +470,7 @@ public sealed class NadekoExpressionsService : IEarlyBehavior, IReadyExecutor
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
await UpdateInternalAsync(expr.GuildId, expr); await UpdateInternalAsync(guildId, expr);
return (true, newVal); return (true, newVal);
} }