Made permission saving async

This commit is contained in:
Kwoth 2016-07-23 22:33:34 +02:00
parent 566cef82ba
commit 92123fc95a
4 changed files with 82 additions and 82 deletions

View File

@ -135,8 +135,8 @@ namespace NadekoBot.Modules.Music.Classes
}
finally
{
await Task.Delay(300).ConfigureAwait(false);
CurrentSong = null;
await Task.Delay(300).ConfigureAwait(false);
}
}
}

View File

@ -150,21 +150,21 @@ namespace NadekoBot.Modules.Permissions.Classes
return PermissionBanType.None;
}
private static void WriteServerToJson(ServerPermissions serverPerms)
private static Task WriteServerToJson(ServerPermissions serverPerms) => Task.Run(() =>
{
string pathToFile = $"data/permissions/{serverPerms.Id}.json";
File.WriteAllText(pathToFile,
Newtonsoft.Json.JsonConvert.SerializeObject(serverPerms, Newtonsoft.Json.Formatting.Indented));
}
});
public static void WriteToJson()
public static Task WriteToJson() => Task.Run(() =>
{
Directory.CreateDirectory("data/permissions/");
foreach (var kvp in PermissionsDict)
{
WriteServerToJson(kvp.Value);
}
}
});
public static string GetServerPermissionsRoleName(Server server)
{
@ -174,25 +174,25 @@ namespace NadekoBot.Modules.Permissions.Classes
return serverPerms.PermissionsControllerRole;
}
internal static void SetPermissionsRole(Server server, string roleName)
internal static async Task SetPermissionsRole(Server server, string roleName)
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
serverPerms.PermissionsControllerRole = roleName;
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
internal static void SetVerbosity(Server server, bool val)
internal static async Task SetVerbosity(Server server, bool val)
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
serverPerms.Verbose = val;
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
internal static void CopyRolePermissions(Role fromRole, Role toRole)
internal static async Task CopyRolePermissions(Role fromRole, Role toRole)
{
var server = fromRole.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -207,10 +207,10 @@ namespace NadekoBot.Modules.Permissions.Classes
to.CopyFrom(from);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
internal static void CopyChannelPermissions(Channel fromChannel, Channel toChannel)
internal static async Task CopyChannelPermissions(Channel fromChannel, Channel toChannel)
{
var server = fromChannel.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -225,10 +225,10 @@ namespace NadekoBot.Modules.Permissions.Classes
to.CopyFrom(from);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
internal static void CopyUserPermissions(User fromUser, User toUser)
internal static async Task CopyUserPermissions(User fromUser, User toUser)
{
var server = fromUser.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -243,10 +243,10 @@ namespace NadekoBot.Modules.Permissions.Classes
to.CopyFrom(from);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetServerModulePermission(Server server, string moduleName, bool value)
public static async Task SetServerModulePermission(Server server, string moduleName, bool value)
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
@ -256,10 +256,10 @@ namespace NadekoBot.Modules.Permissions.Classes
modules[moduleName] = value;
else
modules.TryAdd(moduleName, value);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetServerCommandPermission(Server server, string commandName, bool value)
public static async Task SetServerCommandPermission(Server server, string commandName, bool value)
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
@ -269,10 +269,10 @@ namespace NadekoBot.Modules.Permissions.Classes
commands[commandName] = value;
else
commands.TryAdd(commandName, value);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetChannelModulePermission(Channel channel, string moduleName, bool value)
public static async Task SetChannelModulePermission(Channel channel, string moduleName, bool value)
{
var server = channel.Server;
@ -288,10 +288,10 @@ namespace NadekoBot.Modules.Permissions.Classes
modules[moduleName] = value;
else
modules.TryAdd(moduleName, value);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetChannelCommandPermission(Channel channel, string commandName, bool value)
public static async Task SetChannelCommandPermission(Channel channel, string commandName, bool value)
{
var server = channel.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -306,10 +306,10 @@ namespace NadekoBot.Modules.Permissions.Classes
commands[commandName] = value;
else
commands.TryAdd(commandName, value);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetRoleModulePermission(Role role, string moduleName, bool value)
public static async Task SetRoleModulePermission(Role role, string moduleName, bool value)
{
var server = role.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -324,10 +324,10 @@ namespace NadekoBot.Modules.Permissions.Classes
modules[moduleName] = value;
else
modules.TryAdd(moduleName, value);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetRoleCommandPermission(Role role, string commandName, bool value)
public static async Task SetRoleCommandPermission(Role role, string commandName, bool value)
{
var server = role.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -342,10 +342,10 @@ namespace NadekoBot.Modules.Permissions.Classes
commands[commandName] = value;
else
commands.TryAdd(commandName, value);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetUserModulePermission(User user, string moduleName, bool value)
public static async Task SetUserModulePermission(User user, string moduleName, bool value)
{
var server = user.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -360,10 +360,10 @@ namespace NadekoBot.Modules.Permissions.Classes
modules[moduleName] = value;
else
modules.TryAdd(moduleName, value);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetUserCommandPermission(User user, string commandName, bool value)
public static async Task SetUserCommandPermission(User user, string commandName, bool value)
{
var server = user.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -377,19 +377,19 @@ namespace NadekoBot.Modules.Permissions.Classes
commands[commandName] = value;
else
commands.TryAdd(commandName, value);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetServerWordPermission(Server server, bool value)
public static async Task SetServerWordPermission(Server server, bool value)
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
serverPerms.Permissions.FilterWords = value;
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetChannelWordPermission(Channel channel, bool value)
public static async Task SetChannelWordPermission(Channel channel, bool value)
{
var server = channel.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -399,19 +399,19 @@ namespace NadekoBot.Modules.Permissions.Classes
serverPerms.ChannelPermissions.Add(channel.Id, new Permissions(channel.Name));
serverPerms.ChannelPermissions[channel.Id].FilterWords = value;
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetServerFilterInvitesPermission(Server server, bool value)
public static async Task SetServerFilterInvitesPermission(Server server, bool value)
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
serverPerms.Permissions.FilterInvites = value;
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetChannelFilterInvitesPermission(Channel channel, bool value)
public static async Task SetChannelFilterInvitesPermission(Channel channel, bool value)
{
var server = channel.Server;
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
@ -421,10 +421,10 @@ namespace NadekoBot.Modules.Permissions.Classes
serverPerms.ChannelPermissions.Add(channel.Id, new Permissions(channel.Name));
serverPerms.ChannelPermissions[channel.Id].FilterInvites = value;
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void SetCommandCooldown(Server server, string commandName, int value)
public static async Task SetCommandCooldown(Server server, string commandName, int value)
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
@ -436,26 +436,26 @@ namespace NadekoBot.Modules.Permissions.Classes
serverPerms.CommandCooldowns.AddOrUpdate(commandName, value, (str, v) => value);
}
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void AddFilteredWord(Server server, string word)
public static async Task AddFilteredWord(Server server, string word)
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
if (serverPerms.Words.Contains(word))
throw new InvalidOperationException("That word is already banned.");
serverPerms.Words.Add(word);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
public static void RemoveFilteredWord(Server server, string word)
public static async Task RemoveFilteredWord(Server server, string word)
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
if (!serverPerms.Words.Contains(word))
throw new InvalidOperationException("That word is not banned.");
serverPerms.Words.Remove(word);
Task.Run(() => WriteServerToJson(serverPerms));
await WriteServerToJson(serverPerms).ConfigureAwait(false);
}
}
/// <summary>

View File

@ -68,7 +68,7 @@ namespace NadekoBot.Modules.Permissions.Commands
var chan = string.IsNullOrWhiteSpace(chanStr)
? e.Channel
: PermissionHelper.ValidateChannel(e.Server, chanStr);
PermissionsHandler.SetChannelWordPermission(chan, state);
await PermissionsHandler.SetChannelWordPermission(chan, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Word filtering has been **{(state ? "enabled" : "disabled")}** for **{chan.Name}** channel.").ConfigureAwait(false);
return;
}
@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Permissions.Commands
foreach (var curChannel in e.Server.TextChannels)
{
PermissionsHandler.SetChannelWordPermission(curChannel, state);
await PermissionsHandler.SetChannelWordPermission(curChannel, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"Word filtering has been **{(state ? "enabled" : "disabled")}** for **ALL** channels.").ConfigureAwait(false);
}
@ -98,7 +98,7 @@ namespace NadekoBot.Modules.Permissions.Commands
var word = e.GetArg("word");
if (string.IsNullOrWhiteSpace(word))
return;
PermissionsHandler.AddFilteredWord(e.Server, word.ToLowerInvariant().Trim());
await PermissionsHandler.AddFilteredWord(e.Server, word.ToLowerInvariant().Trim()).ConfigureAwait(false);
await e.Channel.SendMessage($"Successfully added new filtered word.").ConfigureAwait(false);
}
@ -120,7 +120,7 @@ namespace NadekoBot.Modules.Permissions.Commands
var word = e.GetArg("word");
if (string.IsNullOrWhiteSpace(word))
return;
PermissionsHandler.RemoveFilteredWord(e.Server, word.ToLowerInvariant().Trim());
await PermissionsHandler.RemoveFilteredWord(e.Server, word.ToLowerInvariant().Trim()).ConfigureAwait(false);
await e.Channel.SendMessage($"Successfully removed filtered word.").ConfigureAwait(false);
}
@ -159,7 +159,7 @@ namespace NadekoBot.Modules.Permissions.Commands
try
{
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
PermissionsHandler.SetServerWordPermission(e.Server, state);
await PermissionsHandler.SetServerWordPermission(e.Server, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Word filtering has been **{(state ? "enabled" : "disabled")}** on this server.")
.ConfigureAwait(false);

View File

@ -55,7 +55,7 @@ namespace NadekoBot.Modules.Permissions
await e.Channel.SendMessage($"Role `{arg}` probably doesn't exist. Create the role with that name first.").ConfigureAwait(false);
return;
}
PermissionsHandler.SetPermissionsRole(e.Server, role.Name);
await PermissionsHandler.SetPermissionsRole(e.Server, role.Name).ConfigureAwait(false);
await e.Channel.SendMessage($"Role `{role.Name}` is now required in order to change permissions.").ConfigureAwait(false);
});
@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Permissions
var args = arg.Split('~').Select(a => a.Trim()).ToArray();
if (args.Length > 2)
{
await e.Channel.SendMessage("💢Invalid number of '~'s in the argument.");
await e.Channel.SendMessage("💢Invalid number of '~'s in the argument.").ConfigureAwait(false);
return;
}
try
@ -79,12 +79,12 @@ namespace NadekoBot.Modules.Permissions
var fromRole = PermissionHelper.ValidateRole(e.Server, args[0]);
var toRole = PermissionHelper.ValidateRole(e.Server, args[1]);
PermissionsHandler.CopyRolePermissions(fromRole, toRole);
await e.Channel.SendMessage($"Copied permission settings from **{fromRole.Name}** to **{toRole.Name}**.");
await PermissionsHandler.CopyRolePermissions(fromRole, toRole).ConfigureAwait(false);
await e.Channel.SendMessage($"Copied permission settings from **{fromRole.Name}** to **{toRole.Name}**.").ConfigureAwait(false);
}
catch (Exception ex)
{
await e.Channel.SendMessage($"💢{ex.Message}");
await e.Channel.SendMessage($"💢{ex.Message}").ConfigureAwait(false);
}
});
cgb.CreateCommand(Prefix + "chnlpermscopy")
@ -107,8 +107,8 @@ namespace NadekoBot.Modules.Permissions
var fromChannel = PermissionHelper.ValidateChannel(e.Server, args[0]);
var toChannel = PermissionHelper.ValidateChannel(e.Server, args[1]);
PermissionsHandler.CopyChannelPermissions(fromChannel, toChannel);
await e.Channel.SendMessage($"Copied permission settings from **{fromChannel.Name}** to **{toChannel.Name}**.");
await PermissionsHandler.CopyChannelPermissions(fromChannel, toChannel).ConfigureAwait(false);
await e.Channel.SendMessage($"Copied permission settings from **{fromChannel.Name}** to **{toChannel.Name}**.").ConfigureAwait(false);
}
catch (Exception ex)
{
@ -127,7 +127,7 @@ namespace NadekoBot.Modules.Permissions
var args = arg.Split('~').Select(a => a.Trim()).ToArray();
if (args.Length > 2)
{
await e.Channel.SendMessage("💢Invalid number of '~'s in the argument.");
await e.Channel.SendMessage("💢Invalid number of '~'s in the argument.").ConfigureAwait(false);
return;
}
try
@ -135,8 +135,8 @@ namespace NadekoBot.Modules.Permissions
var fromUser = PermissionHelper.ValidateUser(e.Server, args[0]);
var toUser = PermissionHelper.ValidateUser(e.Server, args[1]);
PermissionsHandler.CopyUserPermissions(fromUser, toUser);
await e.Channel.SendMessage($"Copied permission settings from **{fromUser.ToString()}**to * *{toUser.ToString()}**.");
await PermissionsHandler.CopyUserPermissions(fromUser, toUser).ConfigureAwait(false);
await e.Channel.SendMessage($"Copied permission settings from **{fromUser.ToString()}**to * *{toUser.ToString()}**.").ConfigureAwait(false);
}
catch (Exception ex)
{
@ -152,7 +152,7 @@ namespace NadekoBot.Modules.Permissions
{
var arg = e.GetArg("arg");
var val = PermissionHelper.ValidateBool(arg);
PermissionsHandler.SetVerbosity(e.Server, val);
await PermissionsHandler.SetVerbosity(e.Server, val).ConfigureAwait(false);
await e.Channel.SendMessage($"Verbosity set to {val}.").ConfigureAwait(false);
});
@ -254,7 +254,7 @@ namespace NadekoBot.Modules.Permissions
var module = PermissionHelper.ValidateModule(e.GetArg("module"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
PermissionsHandler.SetServerModulePermission(e.Server, module, state);
await PermissionsHandler.SetServerModulePermission(e.Server, module, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false);
}
catch (ArgumentException exArg)
@ -278,7 +278,7 @@ namespace NadekoBot.Modules.Permissions
var command = PermissionHelper.ValidateCommand(e.GetArg("command"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
PermissionsHandler.SetServerCommandPermission(e.Server, command, state);
await PermissionsHandler.SetServerCommandPermission(e.Server, command, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false);
}
catch (ArgumentException exArg)
@ -307,7 +307,7 @@ namespace NadekoBot.Modules.Permissions
{
foreach (var role in e.Server.Roles)
{
PermissionsHandler.SetRoleModulePermission(role, module, state);
await PermissionsHandler.SetRoleModulePermission(role, module, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.").ConfigureAwait(false);
}
@ -315,7 +315,7 @@ namespace NadekoBot.Modules.Permissions
{
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
PermissionsHandler.SetRoleModulePermission(role, module, state);
await PermissionsHandler.SetRoleModulePermission(role, module, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false);
}
}
@ -345,7 +345,7 @@ namespace NadekoBot.Modules.Permissions
{
foreach (var role in e.Server.Roles)
{
PermissionsHandler.SetRoleCommandPermission(role, command, state);
await PermissionsHandler.SetRoleCommandPermission(role, command, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.").ConfigureAwait(false);
}
@ -353,7 +353,7 @@ namespace NadekoBot.Modules.Permissions
{
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
PermissionsHandler.SetRoleCommandPermission(role, command, state);
await PermissionsHandler.SetRoleCommandPermission(role, command, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false);
}
}
@ -383,20 +383,20 @@ namespace NadekoBot.Modules.Permissions
{
foreach (var channel in e.Server.TextChannels)
{
PermissionsHandler.SetChannelModulePermission(channel, module, state);
await PermissionsHandler.SetChannelModulePermission(channel, module, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.").ConfigureAwait(false);
}
else if (string.IsNullOrWhiteSpace(channelArg))
{
PermissionsHandler.SetChannelModulePermission(e.Channel, module, state);
await PermissionsHandler.SetChannelModulePermission(e.Channel, module, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{e.Channel.Name}** channel.").ConfigureAwait(false);
}
else
{
var channel = PermissionHelper.ValidateChannel(e.Server, channelArg);
PermissionsHandler.SetChannelModulePermission(channel, module, state);
await PermissionsHandler.SetChannelModulePermission(channel, module, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false);
}
}
@ -426,7 +426,7 @@ namespace NadekoBot.Modules.Permissions
{
foreach (var channel in e.Server.TextChannels)
{
PermissionsHandler.SetChannelCommandPermission(channel, command, state);
await PermissionsHandler.SetChannelCommandPermission(channel, command, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.").ConfigureAwait(false);
}
@ -434,7 +434,7 @@ namespace NadekoBot.Modules.Permissions
{
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
PermissionsHandler.SetChannelCommandPermission(channel, command, state);
await PermissionsHandler.SetChannelCommandPermission(channel, command, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false);
}
}
@ -461,7 +461,7 @@ namespace NadekoBot.Modules.Permissions
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
PermissionsHandler.SetUserModulePermission(user, module, state);
await PermissionsHandler.SetUserModulePermission(user, module, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.").ConfigureAwait(false);
}
catch (ArgumentException exArg)
@ -487,7 +487,7 @@ namespace NadekoBot.Modules.Permissions
var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
PermissionsHandler.SetUserCommandPermission(user, command, state);
await PermissionsHandler.SetUserCommandPermission(user, command, state).ConfigureAwait(false);
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.").ConfigureAwait(false);
}
catch (ArgumentException exArg)
@ -511,7 +511,7 @@ namespace NadekoBot.Modules.Permissions
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
{
PermissionsHandler.SetServerModulePermission(e.Server, module.Name, state);
await PermissionsHandler.SetServerModulePermission(e.Server, module.Name, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false);
}
@ -538,7 +538,7 @@ namespace NadekoBot.Modules.Permissions
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
{
PermissionsHandler.SetServerCommandPermission(e.Server, command.Text, state);
await PermissionsHandler.SetServerCommandPermission(e.Server, command.Text, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false);
}
@ -565,7 +565,7 @@ namespace NadekoBot.Modules.Permissions
var channel = string.IsNullOrWhiteSpace(chArg) ? e.Channel : PermissionHelper.ValidateChannel(e.Server, chArg);
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
{
PermissionsHandler.SetChannelModulePermission(channel, module.Name, state);
await PermissionsHandler.SetChannelModulePermission(channel, module.Name, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false);
@ -594,7 +594,7 @@ namespace NadekoBot.Modules.Permissions
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
{
PermissionsHandler.SetChannelCommandPermission(channel, command.Text, state);
await PermissionsHandler.SetChannelCommandPermission(channel, command.Text, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false);
}
@ -620,7 +620,7 @@ namespace NadekoBot.Modules.Permissions
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
{
PermissionsHandler.SetRoleModulePermission(role, module.Name, state);
await PermissionsHandler.SetRoleModulePermission(role, module.Name, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false);
@ -652,7 +652,7 @@ namespace NadekoBot.Modules.Permissions
{
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
{
PermissionsHandler.SetRoleCommandPermission(role, command.Text, state);
await PermissionsHandler.SetRoleCommandPermission(role, command.Text, state).ConfigureAwait(false);
}
}
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **all roles** role.").ConfigureAwait(false);
@ -663,7 +663,7 @@ namespace NadekoBot.Modules.Permissions
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
{
PermissionsHandler.SetRoleCommandPermission(role, command.Text, state);
await PermissionsHandler.SetRoleCommandPermission(role, command.Text, state).ConfigureAwait(false);
}
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false);
}
@ -795,7 +795,7 @@ namespace NadekoBot.Modules.Permissions
throw new ArgumentOutOfRangeException("secs", "Invalid second parameter. (Must be a number between 0 and 3600)");
PermissionsHandler.SetCommandCooldown(e.Server, command, secs);
await PermissionsHandler.SetCommandCooldown(e.Server, command, secs).ConfigureAwait(false);
if(secs == 0)
await e.Channel.SendMessage($"Command **{command}** has no coooldown now.").ConfigureAwait(false);
else