forked from TeamInklings/Octobot
Resync roles before removing them during a mute
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
8ca4b83b9c
commit
1c13f0a310
1 changed files with 9 additions and 4 deletions
|
@ -28,16 +28,20 @@ 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, IGuildUser toMute,
|
private static async Task MuteMemberAsync(
|
||||||
TimeSpan duration, GuildData data, string reason) {
|
CommandProcessor cmd, IGuildUser toMute,
|
||||||
|
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];
|
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") {
|
||||||
|
memberData.Roles = toMute.RoleIds.ToList();
|
||||||
|
memberData.Roles.Remove(cmd.Context.Guild.Id);
|
||||||
await toMute.RemoveRolesAsync(memberData.Roles, requestOptions);
|
await toMute.RemoveRolesAsync(memberData.Roles, requestOptions);
|
||||||
|
}
|
||||||
|
|
||||||
await toMute.AddRoleAsync(role, requestOptions);
|
await toMute.AddRoleAsync(role, requestOptions);
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,7 +61,8 @@ public sealed class MuteCommand : ICommand {
|
||||||
memberData.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,
|
||||||
Utils.GetHumanizedTimeSpan(duration),
|
Utils.GetHumanizedTimeSpan(duration),
|
||||||
Utils.Wrap(reason));
|
Utils.Wrap(reason));
|
||||||
cmd.Reply(feedback, ReplyEmojis.Muted);
|
cmd.Reply(feedback, ReplyEmojis.Muted);
|
||||||
|
|
Reference in a new issue