2016-09-16 17:20:37 +00:00
|
|
|
|
using NadekoBot.Attributes;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using NadekoBot.Services;
|
|
|
|
|
using Discord;
|
2016-09-20 01:08:28 +00:00
|
|
|
|
using NadekoBot.Services.Database.Models;
|
2016-10-14 22:03:52 +00:00
|
|
|
|
using System.Collections.Concurrent;
|
2017-03-08 23:58:58 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-12-18 00:52:53 +00:00
|
|
|
|
using Discord.WebSocket;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
using System.Diagnostics;
|
2017-03-08 23:58:58 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using NadekoBot.DataStructures;
|
2017-03-14 07:08:13 +00:00
|
|
|
|
using NadekoBot.TypeReaders;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
using NLog;
|
2016-09-16 17:20:37 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Permissions
|
|
|
|
|
{
|
|
|
|
|
[NadekoModule("Permissions", ";")]
|
2017-02-20 22:46:34 +00:00
|
|
|
|
public partial class Permissions : NadekoTopLevelModule
|
2016-09-16 17:20:37 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
public class OldPermissionCache
|
2016-10-14 22:03:52 +00:00
|
|
|
|
{
|
|
|
|
|
public string PermRole { get; set; }
|
|
|
|
|
public bool Verbose { get; set; } = true;
|
|
|
|
|
public Permission RootPermission { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
public class PermissionCache
|
|
|
|
|
{
|
|
|
|
|
public string PermRole { get; set; }
|
|
|
|
|
public bool Verbose { get; set; } = true;
|
|
|
|
|
public PermissionsCollection<Permissionv2> Permissions { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 22:03:52 +00:00
|
|
|
|
//guildid, root permission
|
2017-03-08 23:58:58 +00:00
|
|
|
|
public static ConcurrentDictionary<ulong, PermissionCache> Cache { get; } =
|
|
|
|
|
new ConcurrentDictionary<ulong, PermissionCache>();
|
2016-10-14 22:03:52 +00:00
|
|
|
|
|
|
|
|
|
static Permissions()
|
|
|
|
|
{
|
2017-02-24 09:53:42 +00:00
|
|
|
|
var log = LogManager.GetCurrentClassLogger();
|
2016-12-29 13:56:15 +00:00
|
|
|
|
var sw = Stopwatch.StartNew();
|
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
TryMigratePermissions();
|
|
|
|
|
|
2016-10-14 22:03:52 +00:00
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
foreach (var x in uow.GuildConfigs.Permissionsv2ForAll())
|
|
|
|
|
{
|
|
|
|
|
Cache.TryAdd(x.GuildId, new PermissionCache()
|
|
|
|
|
{
|
|
|
|
|
Verbose = x.VerbosePermissions,
|
|
|
|
|
PermRole = x.PermissionRole,
|
|
|
|
|
Permissions = new PermissionsCollection<Permissionv2>(x.Permissions)
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-10-14 22:03:52 +00:00
|
|
|
|
}
|
2016-12-29 13:56:15 +00:00
|
|
|
|
|
|
|
|
|
sw.Stop();
|
2017-02-24 09:53:42 +00:00
|
|
|
|
log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s");
|
2016-10-14 22:03:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
private static void TryMigratePermissions()
|
|
|
|
|
{
|
|
|
|
|
var log = LogManager.GetCurrentClassLogger();
|
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
|
|
|
|
var oldCache = new ConcurrentDictionary<ulong, OldPermissionCache>(uow.GuildConfigs
|
|
|
|
|
.OldPermissionsForAll()
|
|
|
|
|
.Where(x => x.RootPermission != null) // there is a check inside already, but just in case
|
|
|
|
|
.ToDictionary(k => k.GuildId,
|
|
|
|
|
v => new OldPermissionCache()
|
|
|
|
|
{
|
|
|
|
|
RootPermission = v.RootPermission,
|
|
|
|
|
Verbose = v.VerbosePermissions,
|
|
|
|
|
PermRole = v.PermissionRole
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
if (oldCache.Any())
|
|
|
|
|
{
|
|
|
|
|
log.Info("Old permissions found. Performing one-time migration to v2.");
|
|
|
|
|
var i = 0;
|
|
|
|
|
foreach (var oc in oldCache)
|
|
|
|
|
{
|
|
|
|
|
if (i % 3 == 0)
|
2017-03-09 00:22:17 +00:00
|
|
|
|
log.Info("Migrating Permissions #" + i + " - GuildId: " + oc.Key);
|
|
|
|
|
i++;
|
2017-03-08 23:58:58 +00:00
|
|
|
|
var gc = uow.GuildConfigs.For(oc.Key, set => set.Include(x => x.Permissions));
|
|
|
|
|
|
|
|
|
|
var oldPerms = oc.Value.RootPermission.AsEnumerable().Reverse().ToList();
|
2017-03-14 07:08:13 +00:00
|
|
|
|
uow._context.Set<Permission>().RemoveRange(oldPerms);
|
2017-03-08 23:58:58 +00:00
|
|
|
|
gc.RootPermission = null;
|
|
|
|
|
if (oldPerms.Count > 2)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var newPerms = oldPerms.Take(oldPerms.Count - 1)
|
|
|
|
|
.Select(x => x.Tov2())
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var allowPerm = Permissionv2.AllowAllPerm;
|
|
|
|
|
var firstPerm = newPerms[0];
|
|
|
|
|
if (allowPerm.State != firstPerm.State ||
|
|
|
|
|
allowPerm.PrimaryTarget != firstPerm.PrimaryTarget ||
|
|
|
|
|
allowPerm.SecondaryTarget != firstPerm.SecondaryTarget ||
|
|
|
|
|
allowPerm.PrimaryTargetId != firstPerm.PrimaryTargetId ||
|
|
|
|
|
allowPerm.SecondaryTargetName != firstPerm.SecondaryTargetName)
|
|
|
|
|
newPerms.Insert(0, Permissionv2.AllowAllPerm);
|
|
|
|
|
Cache.TryAdd(oc.Key, new PermissionCache
|
|
|
|
|
{
|
|
|
|
|
Permissions = new PermissionsCollection<Permissionv2>(newPerms),
|
|
|
|
|
Verbose = gc.VerbosePermissions,
|
|
|
|
|
PermRole = gc.PermissionRole,
|
|
|
|
|
});
|
|
|
|
|
gc.Permissions = newPerms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.Info("Permission migration to v2 is done.");
|
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async Task AddPermissions(ulong guildId, params Permissionv2[] perms)
|
|
|
|
|
{
|
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
|
|
|
|
var config = uow.GuildConfigs.For(guildId, set => set.Include(x => x.Permissions));
|
|
|
|
|
//var orderedPerms = new PermissionsCollection<Permissionv2>(config.Permissions);
|
|
|
|
|
var max = config.Permissions.Max(x => x.Index); //have to set its index to be the highest
|
|
|
|
|
foreach (var perm in perms)
|
|
|
|
|
{
|
|
|
|
|
perm.Index = ++max;
|
|
|
|
|
config.Permissions.Add(perm);
|
|
|
|
|
}
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
UpdateCache(config);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void UpdateCache(GuildConfig config)
|
|
|
|
|
{
|
|
|
|
|
Cache.AddOrUpdate(config.GuildId, new PermissionCache()
|
|
|
|
|
{
|
|
|
|
|
Permissions = new PermissionsCollection<Permissionv2>(config.Permissions),
|
|
|
|
|
PermRole = config.PermissionRole,
|
|
|
|
|
Verbose = config.VerbosePermissions
|
|
|
|
|
}, (id, old) =>
|
|
|
|
|
{
|
|
|
|
|
old.Permissions = new PermissionsCollection<Permissionv2>(config.Permissions);
|
|
|
|
|
old.PermRole = config.PermissionRole;
|
|
|
|
|
old.Verbose = config.VerbosePermissions;
|
|
|
|
|
return old;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-30 00:40:33 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task Verbose(PermissionAction action)
|
2016-09-30 00:40:33 +00:00
|
|
|
|
{
|
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
2017-03-16 11:31:57 +00:00
|
|
|
|
var config = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.Permissions));
|
2016-09-30 00:40:33 +00:00
|
|
|
|
config.VerbosePermissions = action.Value;
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
2017-03-08 23:58:58 +00:00
|
|
|
|
UpdateCache(config);
|
2016-09-30 00:40:33 +00:00
|
|
|
|
}
|
2017-02-24 09:53:42 +00:00
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("verbose_true").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("verbose_false").ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-30 00:40:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-30 02:20:09 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task PermRole([Remainder] IRole role = null)
|
2016-09-30 02:20:09 +00:00
|
|
|
|
{
|
2017-01-04 16:06:22 +00:00
|
|
|
|
if (role != null && role == role.Guild.EveryoneRole)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-09-30 02:20:09 +00:00
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
2016-12-17 00:16:14 +00:00
|
|
|
|
var config = uow.GuildConfigs.For(Context.Guild.Id, set => set);
|
2016-09-30 02:20:09 +00:00
|
|
|
|
if (role == null)
|
|
|
|
|
{
|
2017-02-24 09:53:42 +00:00
|
|
|
|
await ReplyConfirmLocalized("permrole", Format.Bold(config.PermissionRole)).ConfigureAwait(false);
|
2016-09-30 02:20:09 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-02-24 09:53:42 +00:00
|
|
|
|
config.PermissionRole = role.Name.Trim();
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
2017-03-08 23:58:58 +00:00
|
|
|
|
UpdateCache(config);
|
2016-09-30 02:20:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-24 09:53:42 +00:00
|
|
|
|
await ReplyConfirmLocalized("permrole_changed", Format.Bold(role.Name)).ConfigureAwait(false);
|
2016-09-30 02:20:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-22 18:53:49 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task ListPerms(int page = 1)
|
2016-09-22 18:53:49 +00:00
|
|
|
|
{
|
2016-10-09 01:22:54 +00:00
|
|
|
|
if (page < 1 || page > 4)
|
|
|
|
|
return;
|
2017-03-08 23:58:58 +00:00
|
|
|
|
|
|
|
|
|
PermissionCache permCache;
|
|
|
|
|
IList<Permissionv2> perms;
|
|
|
|
|
|
|
|
|
|
if (Cache.TryGetValue(Context.Guild.Id, out permCache))
|
2016-09-22 18:53:49 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
perms = permCache.Permissions.Source.ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
perms = Permissionv2.GetDefaultPermlist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var startPos = 20 * (page - 1);
|
|
|
|
|
var toSend = Format.Bold(GetText("page", page)) + "\n\n" + string.Join("\n",
|
|
|
|
|
perms.Reverse()
|
2017-03-09 15:30:34 +00:00
|
|
|
|
.Skip(startPos)
|
2017-02-24 09:53:42 +00:00
|
|
|
|
.Take(20)
|
2017-03-08 23:58:58 +00:00
|
|
|
|
.Select(p =>
|
|
|
|
|
{
|
|
|
|
|
var str =
|
2017-03-09 16:51:31 +00:00
|
|
|
|
$"`{p.Index + 1}.` {Format.Bold(p.GetCommand((SocketGuild) Context.Guild))}";
|
2017-03-08 23:58:58 +00:00
|
|
|
|
if (p.Index == 0)
|
|
|
|
|
str += $" [{GetText("uneditable")}]";
|
|
|
|
|
return str;
|
|
|
|
|
}));
|
2016-09-22 18:53:49 +00:00
|
|
|
|
|
2016-12-17 00:16:14 +00:00
|
|
|
|
await Context.Channel.SendMessageAsync(toSend).ConfigureAwait(false);
|
2016-09-22 18:53:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-26 17:23:01 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task RemovePerm(int index)
|
2016-09-26 17:23:01 +00:00
|
|
|
|
{
|
2016-09-30 00:40:33 +00:00
|
|
|
|
index -= 1;
|
2017-03-08 23:58:58 +00:00
|
|
|
|
if (index < 0)
|
|
|
|
|
return;
|
2016-09-26 17:23:01 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
Permissionv2 p;
|
2016-09-26 17:23:01 +00:00
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
var config = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.Permissions));
|
|
|
|
|
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
|
|
|
|
|
p = permsCol[index];
|
|
|
|
|
permsCol.RemoveAt(index);
|
|
|
|
|
uow._context.Remove(p);
|
2016-09-26 17:23:01 +00:00
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
2017-03-08 23:58:58 +00:00
|
|
|
|
UpdateCache(config);
|
2016-09-26 17:23:01 +00:00
|
|
|
|
}
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await ReplyConfirmLocalized("removed",
|
|
|
|
|
index + 1,
|
|
|
|
|
Format.Code(p.GetCommand((SocketGuild) Context.Guild))).ConfigureAwait(false);
|
2016-09-26 17:23:01 +00:00
|
|
|
|
}
|
2017-02-24 09:53:42 +00:00
|
|
|
|
catch (IndexOutOfRangeException)
|
2016-09-26 17:23:01 +00:00
|
|
|
|
{
|
2017-02-24 09:53:42 +00:00
|
|
|
|
await ReplyErrorLocalized("perm_out_of_range").ConfigureAwait(false);
|
2016-09-26 17:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-26 17:23:01 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task MovePerm(int from, int to)
|
2016-09-26 17:23:01 +00:00
|
|
|
|
{
|
2016-09-30 00:40:33 +00:00
|
|
|
|
from -= 1;
|
|
|
|
|
to -= 1;
|
|
|
|
|
if (!(from == to || from < 0 || to < 0))
|
2016-09-26 17:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
Permissionv2 fromPerm;
|
2016-09-26 17:23:01 +00:00
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
var config = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.Permissions));
|
|
|
|
|
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
|
2016-10-07 18:13:03 +00:00
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
var fromFound = from < permsCol.Count;
|
|
|
|
|
var toFound = to < permsCol.Count;
|
2016-10-07 16:53:04 +00:00
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
if (!fromFound)
|
2016-10-07 16:53:04 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await ReplyErrorLocalized("not_found", ++from).ConfigureAwait(false);
|
|
|
|
|
return;
|
2016-10-07 16:53:04 +00:00
|
|
|
|
}
|
2016-10-07 19:52:56 +00:00
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
if (!toFound)
|
2016-10-07 13:00:42 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await ReplyErrorLocalized("not_found", ++to).ConfigureAwait(false);
|
|
|
|
|
return;
|
2016-10-07 13:00:42 +00:00
|
|
|
|
}
|
2017-03-08 23:58:58 +00:00
|
|
|
|
fromPerm = permsCol[from];
|
2016-10-07 19:52:56 +00:00
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
permsCol.RemoveAt(from);
|
|
|
|
|
permsCol.Insert(to, fromPerm);
|
2016-09-26 17:23:01 +00:00
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
2017-03-08 23:58:58 +00:00
|
|
|
|
UpdateCache(config);
|
2016-09-26 17:23:01 +00:00
|
|
|
|
}
|
2017-02-24 09:53:42 +00:00
|
|
|
|
await ReplyConfirmLocalized("moved_permission",
|
2017-03-08 23:58:58 +00:00
|
|
|
|
Format.Code(fromPerm.GetCommand((SocketGuild) Context.Guild)),
|
|
|
|
|
++from,
|
2017-02-24 09:53:42 +00:00
|
|
|
|
++to)
|
|
|
|
|
.ConfigureAwait(false);
|
2016-09-26 17:23:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) when (e is ArgumentOutOfRangeException || e is IndexOutOfRangeException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-24 09:53:42 +00:00
|
|
|
|
await ReplyErrorLocalized("perm_out_of_range").ConfigureAwait(false);
|
2016-09-26 17:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-30 00:40:33 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-03-14 07:08:13 +00:00
|
|
|
|
public async Task SrvrCmd(CommandOrCrInfo command, PermissionAction action)
|
2016-09-30 00:40:33 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-30 00:40:33 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Server,
|
|
|
|
|
PrimaryTargetId = 0,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.Command,
|
2017-03-14 07:08:13 +00:00
|
|
|
|
SecondaryTargetName = command.Name.ToLowerInvariant(),
|
2017-03-08 23:58:58 +00:00
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await ReplyConfirmLocalized("sx_enable",
|
2017-03-14 07:08:13 +00:00
|
|
|
|
Format.Code(command.Name),
|
2017-02-24 09:53:42 +00:00
|
|
|
|
GetText("of_command")).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await ReplyConfirmLocalized("sx_disable",
|
2017-03-14 07:08:13 +00:00
|
|
|
|
Format.Code(command.Name),
|
2017-02-24 09:53:42 +00:00
|
|
|
|
GetText("of_command")).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-30 00:40:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-30 00:40:33 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task SrvrMdl(ModuleInfo module, PermissionAction action)
|
2016-09-30 00:40:33 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-30 00:40:33 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Server,
|
|
|
|
|
PrimaryTargetId = 0,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.Module,
|
|
|
|
|
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("sx_enable",
|
|
|
|
|
Format.Code(module.Name),
|
|
|
|
|
GetText("of_module")).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("sx_disable",
|
|
|
|
|
Format.Code(module.Name),
|
|
|
|
|
GetText("of_module")).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-30 00:40:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-16 17:20:37 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-03-14 07:08:13 +00:00
|
|
|
|
public async Task UsrCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] IGuildUser user)
|
2016-09-16 17:20:37 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-20 01:08:28 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.User,
|
|
|
|
|
PrimaryTargetId = user.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.Command,
|
2017-03-14 07:08:13 +00:00
|
|
|
|
SecondaryTargetName = command.Name.ToLowerInvariant(),
|
2017-03-08 23:58:58 +00:00
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await ReplyConfirmLocalized("ux_enable",
|
2017-03-14 07:08:13 +00:00
|
|
|
|
Format.Code(command.Name),
|
2017-02-24 09:53:42 +00:00
|
|
|
|
GetText("of_command"),
|
|
|
|
|
Format.Code(user.ToString())).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await ReplyConfirmLocalized("ux_disable",
|
2017-03-14 07:08:13 +00:00
|
|
|
|
Format.Code(command.Name),
|
2017-02-24 09:53:42 +00:00
|
|
|
|
GetText("of_command"),
|
|
|
|
|
Format.Code(user.ToString())).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-16 17:20:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-16 17:20:37 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task UsrMdl(ModuleInfo module, PermissionAction action, [Remainder] IGuildUser user)
|
2016-09-16 17:20:37 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-20 01:08:28 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.User,
|
|
|
|
|
PrimaryTargetId = user.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.Module,
|
|
|
|
|
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("ux_enable",
|
|
|
|
|
Format.Code(module.Name),
|
|
|
|
|
GetText("of_module"),
|
|
|
|
|
Format.Code(user.ToString())).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("ux_disable",
|
|
|
|
|
Format.Code(module.Name),
|
|
|
|
|
GetText("of_module"),
|
|
|
|
|
Format.Code(user.ToString())).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-16 17:20:37 +00:00
|
|
|
|
}
|
2016-09-23 08:23:54 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-23 08:23:54 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-03-14 07:08:13 +00:00
|
|
|
|
public async Task RoleCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] IRole role)
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-01-04 16:06:22 +00:00
|
|
|
|
if (role == role.Guild.EveryoneRole)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Role,
|
|
|
|
|
PrimaryTargetId = role.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.Command,
|
2017-03-14 07:08:13 +00:00
|
|
|
|
SecondaryTargetName = command.Name.ToLowerInvariant(),
|
2017-03-08 23:58:58 +00:00
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("rx_enable",
|
2017-03-14 07:08:13 +00:00
|
|
|
|
Format.Code(command.Name),
|
2017-02-24 09:53:42 +00:00
|
|
|
|
GetText("of_command"),
|
|
|
|
|
Format.Code(role.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("rx_disable",
|
2017-03-14 07:08:13 +00:00
|
|
|
|
Format.Code(command.Name),
|
2017-02-24 09:53:42 +00:00
|
|
|
|
GetText("of_command"),
|
|
|
|
|
Format.Code(role.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-23 08:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-23 08:23:54 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task RoleMdl(ModuleInfo module, PermissionAction action, [Remainder] IRole role)
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-01-04 16:06:22 +00:00
|
|
|
|
if (role == role.Guild.EveryoneRole)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Role,
|
|
|
|
|
PrimaryTargetId = role.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.Module,
|
|
|
|
|
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("rx_enable",
|
|
|
|
|
Format.Code(module.Name),
|
|
|
|
|
GetText("of_module"),
|
|
|
|
|
Format.Code(role.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("rx_disable",
|
|
|
|
|
Format.Code(module.Name),
|
|
|
|
|
GetText("of_module"),
|
|
|
|
|
Format.Code(role.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-23 08:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-23 08:23:54 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-03-14 07:08:13 +00:00
|
|
|
|
public async Task ChnlCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] ITextChannel chnl)
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Channel,
|
|
|
|
|
PrimaryTargetId = chnl.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.Command,
|
2017-03-14 07:08:13 +00:00
|
|
|
|
SecondaryTargetName = command.Name.ToLowerInvariant(),
|
2017-03-08 23:58:58 +00:00
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("cx_enable",
|
2017-03-14 07:08:13 +00:00
|
|
|
|
Format.Code(command.Name),
|
2017-02-24 09:53:42 +00:00
|
|
|
|
GetText("of_command"),
|
|
|
|
|
Format.Code(chnl.Name)).ConfigureAwait(false);
|
2016-09-30 00:40:33 +00:00
|
|
|
|
}
|
2017-02-24 09:53:42 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("cx_disable",
|
2017-03-14 07:08:13 +00:00
|
|
|
|
Format.Code(command.Name),
|
2017-02-24 09:53:42 +00:00
|
|
|
|
GetText("of_command"),
|
|
|
|
|
Format.Code(chnl.Name)).ConfigureAwait(false);
|
2016-09-23 08:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-23 08:23:54 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task ChnlMdl(ModuleInfo module, PermissionAction action, [Remainder] ITextChannel chnl)
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Channel,
|
|
|
|
|
PrimaryTargetId = chnl.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.Module,
|
|
|
|
|
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("cx_enable",
|
|
|
|
|
Format.Code(module.Name),
|
|
|
|
|
GetText("of_module"),
|
|
|
|
|
Format.Code(chnl.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("cx_disable",
|
|
|
|
|
Format.Code(module.Name),
|
|
|
|
|
GetText("of_module"),
|
|
|
|
|
Format.Code(chnl.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-23 08:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-23 08:23:54 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task AllChnlMdls(PermissionAction action, [Remainder] ITextChannel chnl)
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Channel,
|
|
|
|
|
PrimaryTargetId = chnl.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.AllModules,
|
|
|
|
|
SecondaryTargetName = "*",
|
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("acm_enable",
|
|
|
|
|
Format.Code(chnl.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("acm_disable",
|
|
|
|
|
Format.Code(chnl.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-23 08:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-23 08:23:54 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task AllRoleMdls(PermissionAction action, [Remainder] IRole role)
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-01-04 16:06:22 +00:00
|
|
|
|
if (role == role.Guild.EveryoneRole)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Role,
|
|
|
|
|
PrimaryTargetId = role.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.AllModules,
|
|
|
|
|
SecondaryTargetName = "*",
|
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("arm_enable",
|
|
|
|
|
Format.Code(role.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("arm_disable",
|
|
|
|
|
Format.Code(role.Name)).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-23 08:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-23 08:23:54 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task AllUsrMdls(PermissionAction action, [Remainder] IUser user)
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
await AddPermissions(Context.Guild.Id, new Permissionv2
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.User,
|
|
|
|
|
PrimaryTargetId = user.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.AllModules,
|
|
|
|
|
SecondaryTargetName = "*",
|
|
|
|
|
State = action.Value,
|
|
|
|
|
});
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("aum_enable",
|
|
|
|
|
Format.Code(user.ToString())).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("aum_disable",
|
|
|
|
|
Format.Code(user.ToString())).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-23 08:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-23 08:23:54 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task AllSrvrMdls(PermissionAction action)
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
var newPerm = new Permissionv2
|
2016-09-23 08:23:54 +00:00
|
|
|
|
{
|
2017-03-08 23:58:58 +00:00
|
|
|
|
PrimaryTarget = PrimaryPermissionType.Server,
|
|
|
|
|
PrimaryTargetId = 0,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.AllModules,
|
|
|
|
|
SecondaryTargetName = "*",
|
|
|
|
|
State = action.Value,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var allowUser = new Permissionv2
|
|
|
|
|
{
|
|
|
|
|
PrimaryTarget = PrimaryPermissionType.User,
|
|
|
|
|
PrimaryTargetId = Context.User.Id,
|
|
|
|
|
SecondaryTarget = SecondaryPermissionType.AllModules,
|
|
|
|
|
SecondaryTargetName = "*",
|
|
|
|
|
State = true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await AddPermissions(Context.Guild.Id,
|
|
|
|
|
newPerm,
|
|
|
|
|
allowUser);
|
2017-02-24 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
if (action.Value)
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("asm_enable").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("asm_disable").ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-23 08:23:54 +00:00
|
|
|
|
}
|
2016-09-16 17:20:37 +00:00
|
|
|
|
}
|
2017-03-08 23:58:58 +00:00
|
|
|
|
}
|