.tesar will now really swap roles

This commit is contained in:
Kwoth 2017-03-09 04:00:25 +01:00
parent 1814936125
commit 42c394f53b

View File

@ -150,11 +150,11 @@ namespace NadekoBot.Modules.Administration
var guildUser = (IGuildUser)Context.User;
GuildConfig conf;
IEnumerable<SelfAssignedRole> 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;
}