.aar cleanup, will disable itself if not enough permissions or when role gets deleted.

This commit is contained in:
Master Kwoth
2017-10-30 14:38:50 +01:00
parent 2c2b58ff99
commit 0f3004dce7
4 changed files with 109 additions and 50 deletions

View File

@ -31,29 +31,14 @@ namespace NadekoBot.Modules.Administration
if (Context.User.Id != guser.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= role.Position)
return;
using (var uow = _db.UnitOfWork)
{
var conf = uow.GuildConfigs.For(Context.Guild.Id, set => set);
if (role == null)
{
conf.AutoAssignRoleId = 0;
_service.AutoAssignedRoles.TryRemove(Context.Guild.Id, out _);
}
else
{
conf.AutoAssignRoleId = role.Id;
_service.AutoAssignedRoles.AddOrUpdate(Context.Guild.Id, role.Id, (key, val) => role.Id);
}
await uow.CompleteAsync().ConfigureAwait(false);
}
if (role == null)
{
_service.DisableAar(Context.Guild.Id);
await ReplyConfirmLocalized("aar_disabled").ConfigureAwait(false);
return;
}
_service.EnableAar(Context.Guild.Id, role.Id);
await ReplyConfirmLocalized("aar_enabled").ConfigureAwait(false);
}
}