From 7f0fd6ffb59c8ad56040a45de4108872185d081d Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 2 Feb 2023 23:04:29 +0500 Subject: [PATCH] Fix removed roles store being overwritten Signed-off-by: Octol1ttle --- Commands/MuteCommand.cs | 2 +- EventHandler.cs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Commands/MuteCommand.cs b/Commands/MuteCommand.cs index 650ff02..82a0e7e 100644 --- a/Commands/MuteCommand.cs +++ b/Commands/MuteCommand.cs @@ -37,6 +37,7 @@ public sealed class MuteCommand : ICommand { var memberData = data.MemberData[toMute.Id]; if (role is not null) { + memberData.MutedUntil = DateTimeOffset.Now.Add(duration); if (data.Preferences["RemoveRolesOnMute"] is "true") { memberData.Roles = toMute.RoleIds.ToList(); memberData.Roles.Remove(cmd.Context.Guild.Id); @@ -58,7 +59,6 @@ public sealed class MuteCommand : ICommand { await toMute.SetTimeOutAsync(duration, requestOptions); } - memberData.MutedUntil = DateTimeOffset.Now.Add(duration); cmd.ConfigWriteScheduled = true; var feedback = string.Format( diff --git a/EventHandler.cs b/EventHandler.cs index ba4ba79..2ab3664 100644 --- a/EventHandler.cs +++ b/EventHandler.cs @@ -7,8 +7,8 @@ using Discord.WebSocket; namespace Boyfriend; public static class EventHandler { - private static readonly DiscordSocketClient Client = Boyfriend.Client; - private static bool _sendReadyMessages = true; + private static readonly DiscordSocketClient Client = Boyfriend.Client; + private static bool _sendReadyMessages = true; public static void InitEvents() { Client.Ready += ReadyEvent; @@ -26,8 +26,11 @@ public static class EventHandler { private static Task MemberRolesUpdatedEvent(Cacheable oldUser, SocketGuildUser newUser) { var data = GuildData.Get(newUser.Guild).MemberData[newUser.Id]; - data.Roles = ((IGuildUser)newUser).RoleIds.ToList(); - data.Roles.Remove(newUser.Guild.Id); + if (data.MutedUntil is null) { + data.Roles = ((IGuildUser)newUser).RoleIds.ToList(); + data.Roles.Remove(newUser.Guild.Id); + } + return Task.CompletedTask; }