From 6159d849884c8b2000941e020419b77ca52834e5 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 13 Apr 2022 18:14:58 +0200 Subject: [PATCH] Fixed an issue with expression settings toggle, closes #353 --- src/NadekoBot/Modules/CustomReactions/NadekoExpressions.cs | 2 +- .../Modules/CustomReactions/NadekoExpressionsService.cs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/NadekoBot/Modules/CustomReactions/NadekoExpressions.cs b/src/NadekoBot/Modules/CustomReactions/NadekoExpressions.cs index 7b4cba1c9..c0e0414d0 100644 --- a/src/NadekoBot/Modules/CustomReactions/NadekoExpressions.cs +++ b/src/NadekoBot/Modules/CustomReactions/NadekoExpressions.cs @@ -241,7 +241,7 @@ public partial class NadekoExpressions : NadekoModule return; } - var (success, newVal) = await _service.ToggleExprOptionAsync(id, option); + var (success, newVal) = await _service.ToggleExprOptionAsync(ctx.Guild?.Id, id, option); if (!success) { await ReplyErrorLocalizedAsync(strs.expr_no_found_id); diff --git a/src/NadekoBot/Modules/CustomReactions/NadekoExpressionsService.cs b/src/NadekoBot/Modules/CustomReactions/NadekoExpressionsService.cs index 8f8811ae3..02bfe93bf 100644 --- a/src/NadekoBot/Modules/CustomReactions/NadekoExpressionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/NadekoExpressionsService.cs @@ -448,14 +448,15 @@ public sealed class NadekoExpressionsService : IEarlyBehavior, IReadyExecutor 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; NadekoExpression expr; await using (var uow = _db.GetDbContext()) { expr = uow.Expressions.GetById(id); - if (expr is null) + + if (expr is null || expr.GuildId != guildId) return (false, false); if (field == ExprField.AutoDelete) newVal = expr.AutoDeleteTrigger = !expr.AutoDeleteTrigger; @@ -469,7 +470,7 @@ public sealed class NadekoExpressionsService : IEarlyBehavior, IReadyExecutor await uow.SaveChangesAsync(); } - await UpdateInternalAsync(expr.GuildId, expr); + await UpdateInternalAsync(guildId, expr); return (true, newVal); }