Fix removed roles store being overwritten

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-02-02 23:04:29 +05:00
parent 620c706c97
commit 7f0fd6ffb5
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
2 changed files with 8 additions and 5 deletions

View file

@ -37,6 +37,7 @@ public sealed class MuteCommand : ICommand {
var memberData = data.MemberData[toMute.Id]; var memberData = data.MemberData[toMute.Id];
if (role is not null) { if (role is not null) {
memberData.MutedUntil = DateTimeOffset.Now.Add(duration);
if (data.Preferences["RemoveRolesOnMute"] is "true") { if (data.Preferences["RemoveRolesOnMute"] is "true") {
memberData.Roles = toMute.RoleIds.ToList(); memberData.Roles = toMute.RoleIds.ToList();
memberData.Roles.Remove(cmd.Context.Guild.Id); memberData.Roles.Remove(cmd.Context.Guild.Id);
@ -58,7 +59,6 @@ public sealed class MuteCommand : ICommand {
await toMute.SetTimeOutAsync(duration, requestOptions); await toMute.SetTimeOutAsync(duration, requestOptions);
} }
memberData.MutedUntil = DateTimeOffset.Now.Add(duration);
cmd.ConfigWriteScheduled = true; cmd.ConfigWriteScheduled = true;
var feedback = string.Format( var feedback = string.Format(

View file

@ -7,8 +7,8 @@ using Discord.WebSocket;
namespace Boyfriend; namespace Boyfriend;
public static class EventHandler { public static class EventHandler {
private static readonly DiscordSocketClient Client = Boyfriend.Client; private static readonly DiscordSocketClient Client = Boyfriend.Client;
private static bool _sendReadyMessages = true; private static bool _sendReadyMessages = true;
public static void InitEvents() { public static void InitEvents() {
Client.Ready += ReadyEvent; Client.Ready += ReadyEvent;
@ -26,8 +26,11 @@ public static class EventHandler {
private static Task MemberRolesUpdatedEvent(Cacheable<SocketGuildUser, ulong> oldUser, SocketGuildUser newUser) { private static Task MemberRolesUpdatedEvent(Cacheable<SocketGuildUser, ulong> oldUser, SocketGuildUser newUser) {
var data = GuildData.Get(newUser.Guild).MemberData[newUser.Id]; var data = GuildData.Get(newUser.Guild).MemberData[newUser.Id];
data.Roles = ((IGuildUser)newUser).RoleIds.ToList(); if (data.MutedUntil is null) {
data.Roles.Remove(newUser.Guild.Id); data.Roles = ((IGuildUser)newUser).RoleIds.ToList();
data.Roles.Remove(newUser.Guild.Id);
}
return Task.CompletedTask; return Task.CompletedTask;
} }