From 42c394f53b2153ffecf3fa1d35be0f182a3ca80b Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 9 Mar 2017 04:00:25 +0100 Subject: [PATCH] .tesar will now really swap roles --- .../Commands/SelfAssignedRolesCommand.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index 7bdfc496..6ac60f21 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -150,11 +150,11 @@ namespace NadekoBot.Modules.Administration var guildUser = (IGuildUser)Context.User; GuildConfig conf; - IEnumerable roles; + SelfAssignedRole[] roles; using (var uow = DbHandler.UnitOfWork()) { conf = uow.GuildConfigs.For(Context.Guild.Id, set => set); - roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id); + roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id).ToArray(); } if (roles.FirstOrDefault(r=>r.RoleId == role.Id) == null) { @@ -167,15 +167,19 @@ namespace NadekoBot.Modules.Administration return; } + var roleIds = roles.Select(x => x.RoleId).ToArray(); if (conf.ExclusiveSelfAssignedRoles) { - var sameRoleId = guildUser.RoleIds.FirstOrDefault(r => roles.Select(sar => sar.RoleId).Contains(r)); + var sameRoleId = guildUser.RoleIds.FirstOrDefault(r => roleIds.Contains(r)); if (sameRoleId != default(ulong)) { var sameRole = Context.Guild.GetRole(sameRoleId); if (sameRole != null) + { await guildUser.RemoveRolesAsync(sameRole).ConfigureAwait(false); + await Task.Delay(500).ConfigureAwait(false); + } //await ReplyErrorLocalized("self_assign_already_excl", Format.Bold(sameRole?.Name)).ConfigureAwait(false); //return; }