1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +03:00

Fix removing everyone role while muting (#23)

Co-authored-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Macintxsh 2023-01-27 07:46:03 +03:00 committed by GitHub
parent 482d7ea91f
commit 00f5fa0d8d
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,5 @@
using Boyfriend.Data; using Boyfriend.Data;
using Discord; using Discord;
using Discord.WebSocket;
namespace Boyfriend.Commands; namespace Boyfriend.Commands;
@ -29,15 +28,16 @@ public sealed class MuteCommand : ICommand {
await MuteMemberAsync(cmd, toMute, duration, guildData, reason); await MuteMemberAsync(cmd, toMute, duration, guildData, reason);
} }
private static async Task MuteMemberAsync(CommandProcessor cmd, SocketGuildUser toMute, private static async Task MuteMemberAsync(CommandProcessor cmd, IGuildUser toMute,
TimeSpan duration, GuildData data, string reason) { TimeSpan duration, GuildData data, string reason) {
var requestOptions = Utils.GetRequestOptions($"({cmd.Context.User}) {reason}"); var requestOptions = Utils.GetRequestOptions($"({cmd.Context.User}) {reason}");
var role = data.MuteRole; var role = data.MuteRole;
var hasDuration = duration.TotalSeconds > 0; var hasDuration = duration.TotalSeconds > 0;
var memberData = data.MemberData[toMute.Id];
if (role is not null) { if (role is not null) {
if (data.Preferences["RemoveRolesOnMute"] is "true") if (data.Preferences["RemoveRolesOnMute"] is "true")
await toMute.RemoveRolesAsync(toMute.Roles, requestOptions); await toMute.RemoveRolesAsync(memberData.Roles, requestOptions);
await toMute.AddRoleAsync(role, requestOptions); await toMute.AddRoleAsync(role, requestOptions);
} else { } else {
@ -54,7 +54,7 @@ public sealed class MuteCommand : ICommand {
await toMute.SetTimeOutAsync(duration, requestOptions); await toMute.SetTimeOutAsync(duration, requestOptions);
} }
data.MemberData[toMute.Id].MutedUntil = DateTimeOffset.Now.Add(duration); memberData.MutedUntil = DateTimeOffset.Now.Add(duration);
cmd.ConfigWriteScheduled = true; cmd.ConfigWriteScheduled = true;
var feedback = string.Format(Messages.FeedbackMemberMuted, toMute.Mention, var feedback = string.Format(Messages.FeedbackMemberMuted, toMute.Mention,