2017-04-09 20:28:42 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using NadekoBot.Extensions;
|
|
|
|
|
using NadekoBot.Services;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Common.TypeReaders;
|
|
|
|
|
using NadekoBot.Modules.Permissions.Services;
|
|
|
|
|
using NadekoBot.Services.Database.Models;
|
2017-04-09 20:28:42 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Permissions
|
|
|
|
|
{
|
|
|
|
|
public partial class Permissions
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
|
|
|
|
public class GlobalPermissionCommands : NadekoSubmodule
|
|
|
|
|
{
|
2017-05-27 23:51:22 +00:00
|
|
|
|
private GlobalPermissionService _service;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly DbService _db;
|
2017-04-09 20:28:42 +00:00
|
|
|
|
|
2017-05-29 04:13:22 +00:00
|
|
|
|
public GlobalPermissionCommands(GlobalPermissionService service, DbService db)
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
2017-05-27 23:51:22 +00:00
|
|
|
|
_service = service;
|
|
|
|
|
_db = db;
|
2017-04-09 20:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task Lgp()
|
|
|
|
|
{
|
2017-05-27 23:51:22 +00:00
|
|
|
|
if (!_service.BlockedModules.Any() && !_service.BlockedCommands.Any())
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
await ReplyErrorLocalized("lgp_none").ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var embed = new EmbedBuilder().WithOkColor();
|
|
|
|
|
|
2017-05-27 23:51:22 +00:00
|
|
|
|
if (_service.BlockedModules.Any())
|
|
|
|
|
embed.AddField(efb => efb.WithName(GetText("blocked_modules")).WithValue(string.Join("\n", _service.BlockedModules)).WithIsInline(false));
|
2017-04-09 20:28:42 +00:00
|
|
|
|
|
2017-05-27 23:51:22 +00:00
|
|
|
|
if (_service.BlockedCommands.Any())
|
|
|
|
|
embed.AddField(efb => efb.WithName(GetText("blocked_commands")).WithValue(string.Join("\n", _service.BlockedCommands)).WithIsInline(false));
|
2017-04-09 20:28:42 +00:00
|
|
|
|
|
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
2017-04-10 17:56:10 +00:00
|
|
|
|
public async Task Gmod(ModuleOrCrInfo module)
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
var moduleName = module.Name.ToLowerInvariant();
|
2017-05-27 23:51:22 +00:00
|
|
|
|
if (_service.BlockedModules.Add(moduleName))
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
2017-05-27 23:51:22 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
var bc = uow.BotConfig.GetOrCreate();
|
2017-07-17 19:42:36 +00:00
|
|
|
|
bc.BlockedModules.Add(new BlockedCmdOrMdl
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
Name = moduleName,
|
|
|
|
|
});
|
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
|
|
|
|
await ReplyConfirmLocalized("gmod_add", Format.Bold(module.Name)).ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-27 23:51:22 +00:00
|
|
|
|
else if (_service.BlockedModules.TryRemove(moduleName))
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
2017-05-27 23:51:22 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
var bc = uow.BotConfig.GetOrCreate();
|
|
|
|
|
bc.BlockedModules.RemoveWhere(x => x.Name == moduleName);
|
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
|
|
|
|
await ReplyConfirmLocalized("gmod_remove", Format.Bold(module.Name)).ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task Gcmd(CommandOrCrInfo cmd)
|
|
|
|
|
{
|
|
|
|
|
var commandName = cmd.Name.ToLowerInvariant();
|
2017-05-27 23:51:22 +00:00
|
|
|
|
if (_service.BlockedCommands.Add(commandName))
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
2017-05-27 23:51:22 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
var bc = uow.BotConfig.GetOrCreate();
|
2017-07-17 19:42:36 +00:00
|
|
|
|
bc.BlockedCommands.Add(new BlockedCmdOrMdl
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
Name = commandName,
|
|
|
|
|
});
|
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
|
|
|
|
await ReplyConfirmLocalized("gcmd_add", Format.Bold(cmd.Name)).ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-27 23:51:22 +00:00
|
|
|
|
else if (_service.BlockedCommands.TryRemove(commandName))
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
2017-05-27 23:51:22 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-04-09 20:28:42 +00:00
|
|
|
|
{
|
|
|
|
|
var bc = uow.BotConfig.GetOrCreate();
|
|
|
|
|
bc.BlockedCommands.RemoveWhere(x => x.Name == commandName);
|
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
|
|
|
|
await ReplyConfirmLocalized("gcmd_remove", Format.Bold(cmd.Name)).ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|