2017-07-17 19:42:36 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services;
|
|
|
|
|
using NadekoBot.Core.Services.Database.Models;
|
2017-07-15 13:08:34 +00:00
|
|
|
|
|
2017-07-17 19:42:36 +00:00
|
|
|
|
namespace NadekoBot.Modules.Permissions.Services
|
2017-07-15 13:08:34 +00:00
|
|
|
|
{
|
|
|
|
|
public class ResetPermissionsService : INService
|
|
|
|
|
{
|
|
|
|
|
private readonly PermissionService _perms;
|
|
|
|
|
private readonly GlobalPermissionService _globalPerms;
|
|
|
|
|
private readonly DbService _db;
|
|
|
|
|
|
|
|
|
|
public ResetPermissionsService(PermissionService perms, GlobalPermissionService globalPerms, DbService db)
|
|
|
|
|
{
|
|
|
|
|
_perms = perms;
|
|
|
|
|
_globalPerms = globalPerms;
|
|
|
|
|
_db = db;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ResetPermissions(ulong guildId)
|
|
|
|
|
{
|
|
|
|
|
using (var uow = _db.UnitOfWork)
|
|
|
|
|
{
|
|
|
|
|
var config = uow.GuildConfigs.GcWithPermissionsv2For(guildId);
|
|
|
|
|
config.Permissions = Permissionv2.GetDefaultPermlist;
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
_perms.UpdateCache(config);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ResetGlobalPermissions()
|
|
|
|
|
{
|
|
|
|
|
using (var uow = _db.UnitOfWork)
|
|
|
|
|
{
|
|
|
|
|
var gc = uow.BotConfig.GetOrCreate();
|
|
|
|
|
gc.BlockedCommands.Clear();
|
|
|
|
|
gc.BlockedModules.Clear();
|
|
|
|
|
|
|
|
|
|
_globalPerms.BlockedCommands.Clear();
|
|
|
|
|
_globalPerms.BlockedModules.Clear();
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|