From b1e43611de6948aa6a68b78dcaf72f5608ddab75 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Tue, 24 Jan 2023 12:36:53 +0500 Subject: [PATCH] Resync roles when restarting bot Signed-off-by: Octol1ttle --- Data/GuildData.cs | 6 ++++++ EventHandler.cs | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Data/GuildData.cs b/Data/GuildData.cs index 41947d6..42959b0 100644 --- a/Data/GuildData.cs +++ b/Data/GuildData.cs @@ -1,6 +1,7 @@ using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using System.Text.Json; +using Discord; using Discord.WebSocket; namespace Boyfriend.Data; @@ -86,6 +87,11 @@ public record GuildData { MemberData.Remove(memberData.Id); } + if (memberData.MutedUntil is null) { + memberData.Roles = ((IGuildUser)member).RoleIds.ToList(); + memberData.Roles.Remove(guild.Id); + } + continue; } diff --git a/EventHandler.cs b/EventHandler.cs index e91f228..88a4e9c 100644 --- a/EventHandler.cs +++ b/EventHandler.cs @@ -141,7 +141,7 @@ public static class EventHandler { } if (memberData.MutedUntil < DateTimeOffset.Now) { - if (data.MuteRole is not null) + if (data.MuteRole is not null && !user.TimedOutUntil.HasValue) await user.AddRoleAsync(data.MuteRole); if (config["RemoveRolesOnMute"] is "false" && config["ReturnRolesOnRejoin"] is "true") await user.AddRolesAsync(memberData.Roles); @@ -149,6 +149,7 @@ public static class EventHandler { } private static Task UserLeftEvent(SocketGuild guild, SocketUser user) { + if (user.IsBot) return Task.CompletedTask; var data = GuildData.Get(guild).MemberData[user.Id]; data.IsInGuild = false; data.LeftAt.Add(DateTimeOffset.Now);