fixes, ;pr , donators fixed

This commit is contained in:
Master Kwoth 2016-02-13 17:01:24 +01:00
parent 02953e84e4
commit ca52c29559
5 changed files with 69 additions and 33 deletions

View File

@ -25,11 +25,15 @@ namespace NadekoBot.Classes.Permissions {
//is it a permission command?
// if it is, check if the user has the correct role
// if yes return true, if no return false
if (command.Category == "Permissions")
if (user.Server.IsOwner || user.HasRole(PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server))))
if (command.Category == "Permissions") {
Discord.Role role = null;
try {
role = PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server));
} catch { }
if (user.Server.Owner.Id == user.Id || (role != null && user.HasRole(role)))
return true;
else
throw new Exception($"You don't have the necessary role (**{PermissionsHandler._permissionsDict[user.Server].PermissionsControllerRole}**) to change permissions.");
}
var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel);

View File

@ -14,7 +14,6 @@ namespace NadekoBot.Classes.Permissions {
public static ConcurrentDictionary<Server, ServerPermissions> _permissionsDict =
new ConcurrentDictionary<Server, ServerPermissions>();
public enum PermissionBanType {
None, ServerBanCommand, ServerBanModule,
ChannelBanCommand, ChannelBanModule, RoleBanCommand,
@ -42,13 +41,6 @@ namespace NadekoBot.Classes.Permissions {
Console.WriteLine("Permission initialization complete.");
}
internal static void SetVerbosity(Server server, bool val) {
if (!_permissionsDict.ContainsKey(server)) {
_permissionsDict.TryAdd(server, new ServerPermissions(server.Id, server.Name));
}
_permissionsDict[server].Verbose = val;
}
internal static Permissions GetRolePermissionsById(Server server, ulong id) {
if (!_permissionsDict.ContainsKey(server))
return null;
@ -172,6 +164,22 @@ namespace NadekoBot.Classes.Permissions {
return _permissionsDict[server].PermissionsControllerRole;
}
internal static void SetPermissionsRole(Server server, string roleName) {
if (!_permissionsDict.ContainsKey(server)) {
_permissionsDict.TryAdd(server, new ServerPermissions(server.Id, server.Name));
}
_permissionsDict[server].PermissionsControllerRole = roleName;
Task.Run(() => WriteServerToJson(server));
}
internal static void SetVerbosity(Server server, bool val) {
if (!_permissionsDict.ContainsKey(server)) {
_permissionsDict.TryAdd(server, new ServerPermissions(server.Id, server.Name));
}
_permissionsDict[server].Verbose = val;
Task.Run(() => WriteServerToJson(server));
}
public static void SetServerModulePermission(Server server, string moduleName, bool value) {
if (!_permissionsDict.ContainsKey(server)) {
_permissionsDict.TryAdd(server, new ServerPermissions(server.Id, server.Name));
@ -181,7 +189,7 @@ namespace NadekoBot.Classes.Permissions {
modules[moduleName] = value;
else
modules.Add(moduleName, value);
WriteServerToJson(server);
Task.Run(() => WriteServerToJson(server));
}
public static void SetServerCommandPermission(Server server, string commandName, bool value) {
@ -193,7 +201,7 @@ namespace NadekoBot.Classes.Permissions {
commands[commandName] = value;
else
commands.Add(commandName, value);
WriteServerToJson(server);
Task.Run(() => WriteServerToJson(server));
}
public static void SetChannelModulePermission(Channel channel, string moduleName, bool value) {
@ -210,7 +218,7 @@ namespace NadekoBot.Classes.Permissions {
modules[moduleName] = value;
else
modules.Add(moduleName, value);
WriteServerToJson(server);
Task.Run(() => WriteServerToJson(server));
}
public static void SetChannelCommandPermission(Channel channel, string commandName, bool value) {
@ -227,7 +235,7 @@ namespace NadekoBot.Classes.Permissions {
commands[commandName] = value;
else
commands.Add(commandName, value);
WriteServerToJson(server);
Task.Run(() => WriteServerToJson(server));
}
public static void SetRoleModulePermission(Role role, string moduleName, bool value) {
@ -244,7 +252,7 @@ namespace NadekoBot.Classes.Permissions {
modules[moduleName] = value;
else
modules.Add(moduleName, value);
WriteServerToJson(server);
Task.Run(() => WriteServerToJson(server));
}
public static void SetRoleCommandPermission(Role role, string commandName, bool value) {
@ -261,7 +269,7 @@ namespace NadekoBot.Classes.Permissions {
commands[commandName] = value;
else
commands.Add(commandName, value);
WriteServerToJson(server);
Task.Run(() => WriteServerToJson(server));
}
public static void SetUserModulePermission(User user, string moduleName, bool value) {
@ -278,7 +286,7 @@ namespace NadekoBot.Classes.Permissions {
modules[moduleName] = value;
else
modules.Add(moduleName, value);
WriteServerToJson(server);
Task.Run(() => WriteServerToJson(server));
}
public static void SetUserCommandPermission(User user, string commandName, bool value) {
@ -295,7 +303,7 @@ namespace NadekoBot.Classes.Permissions {
commands[commandName] = value;
else
commands.Add(commandName, value);
WriteServerToJson(server);
Task.Run(() => WriteServerToJson(server));
}
}
/// <summary>

View File

@ -581,7 +581,7 @@ namespace NadekoBot.Modules {
var donatorsOrdered = rows.OrderBy(d => d.Amount);
string str = $"`Total number of people who donated is {donatorsOrdered.Count()}`\n";
await e.Channel.SendMessage(string.Join(", ", donatorsOrdered));
await e.Channel.SendMessage(string.Join(", ", donatorsOrdered.Select(d => d.UserName)));
});
});

View File

@ -20,7 +20,7 @@ namespace NadekoBot.Modules {
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
cgb.CreateCommand("~hentai")
.Description("Shows a random NSFW hentai image from gelbooru and danbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~hentai yuri")
.Description("Shows a random NSFW hentai image from gelbooru and danbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)\n**Usage**: ~hentai yuri")
.Parameter("tag", ParameterType.Unparsed)
.Do(async e => {
string tag = e.GetArg("tag");
@ -30,7 +30,7 @@ namespace NadekoBot.Modules {
await e.Send(":heart: Danbooru: " + await SearchHelper.GetDanbooruImageLink(tag));
});
cgb.CreateCommand("~danbooru")
.Description("Shows a random hentai image from danbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~danbooru yuri")
.Description("Shows a random hentai image from danbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)\n**Usage**: ~danbooru yuri+kissing")
.Parameter("tag", ParameterType.Unparsed)
.Do(async e => {
string tag = e.GetArg("tag");
@ -39,7 +39,7 @@ namespace NadekoBot.Modules {
await e.Send(await SearchHelper.GetDanbooruImageLink(tag));
});
cgb.CreateCommand("~gelbooru")
.Description("Shows a random hentai image from gelbooru with a given tag. Tag is optional but preffered.\n**Usage**: ~gelbooru yuri")
.Description("Shows a random hentai image from gelbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +)\n**Usage**: ~gelbooru yuri+kissing")
.Parameter("tag", ParameterType.Unparsed)
.Do(async e => {
string tag = e.GetArg("tag");

View File

@ -21,7 +21,31 @@ namespace NadekoBot.Modules {
commands.ForEach(cmd => cmd.Init(cgb));
cgb.CreateCommand(prefix + "permrole")
.Alias(prefix + "pr")
.Description("Sets a role which can change permissions. Or supply no parameters to find out the current one. Default one is 'Nadeko'.")
.Parameter("role", ParameterType.Unparsed)
.Do(async e => {
if (string.IsNullOrWhiteSpace(e.GetArg("role"))) {
await e.Send($"Current permissions role is `{PermsHandler.GetServerPermissionsRoleName(e.Server)}`");
return;
}
var arg = e.GetArg("role");
Discord.Role role = null;
try {
role = PermissionHelper.ValidateRole(e.Server, arg);
} catch (Exception ex) {
Console.WriteLine(ex.Message);
await e.Send($"Role `{arg}` probably doesn't exist. Create the role with that name first.");
return;
}
PermsHandler.SetPermissionsRole(e.Server, role.Name);
await e.Send($"Role `{role.Name}` is now required in order to change permissions.");
});
cgb.CreateCommand(prefix + "verbose")
.Alias(prefix + "v")
.Description("Sets whether to show when a command/module is blocked.\n**Usage**: ;verbose true")
.Parameter("arg", ParameterType.Required)
.Do(async e => {