fixes, ;pr , donators fixed
This commit is contained in:
parent
02953e84e4
commit
ca52c29559
@ -25,11 +25,15 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
//is it a permission command?
|
//is it a permission command?
|
||||||
// if it is, check if the user has the correct role
|
// if it is, check if the user has the correct role
|
||||||
// if yes return true, if no return false
|
// if yes return true, if no return false
|
||||||
if (command.Category == "Permissions")
|
if (command.Category == "Permissions") {
|
||||||
if (user.Server.IsOwner || user.HasRole(PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server))))
|
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;
|
return true;
|
||||||
else
|
throw new Exception($"You don't have the necessary role (**{PermissionsHandler._permissionsDict[user.Server].PermissionsControllerRole}**) to change permissions.");
|
||||||
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);
|
var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel);
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
public static ConcurrentDictionary<Server, ServerPermissions> _permissionsDict =
|
public static ConcurrentDictionary<Server, ServerPermissions> _permissionsDict =
|
||||||
new ConcurrentDictionary<Server, ServerPermissions>();
|
new ConcurrentDictionary<Server, ServerPermissions>();
|
||||||
|
|
||||||
|
|
||||||
public enum PermissionBanType {
|
public enum PermissionBanType {
|
||||||
None, ServerBanCommand, ServerBanModule,
|
None, ServerBanCommand, ServerBanModule,
|
||||||
ChannelBanCommand, ChannelBanModule, RoleBanCommand,
|
ChannelBanCommand, ChannelBanModule, RoleBanCommand,
|
||||||
@ -42,13 +41,6 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Console.WriteLine("Permission initialization complete.");
|
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) {
|
internal static Permissions GetRolePermissionsById(Server server, ulong id) {
|
||||||
if (!_permissionsDict.ContainsKey(server))
|
if (!_permissionsDict.ContainsKey(server))
|
||||||
return null;
|
return null;
|
||||||
@ -172,6 +164,22 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
return _permissionsDict[server].PermissionsControllerRole;
|
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) {
|
public static void SetServerModulePermission(Server server, string moduleName, bool value) {
|
||||||
if (!_permissionsDict.ContainsKey(server)) {
|
if (!_permissionsDict.ContainsKey(server)) {
|
||||||
_permissionsDict.TryAdd(server, new ServerPermissions(server.Id, server.Name));
|
_permissionsDict.TryAdd(server, new ServerPermissions(server.Id, server.Name));
|
||||||
@ -181,7 +189,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
modules[moduleName] = value;
|
modules[moduleName] = value;
|
||||||
else
|
else
|
||||||
modules.Add(moduleName, value);
|
modules.Add(moduleName, value);
|
||||||
WriteServerToJson(server);
|
Task.Run(() => WriteServerToJson(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetServerCommandPermission(Server server, string commandName, bool value) {
|
public static void SetServerCommandPermission(Server server, string commandName, bool value) {
|
||||||
@ -193,7 +201,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
commands[commandName] = value;
|
commands[commandName] = value;
|
||||||
else
|
else
|
||||||
commands.Add(commandName, value);
|
commands.Add(commandName, value);
|
||||||
WriteServerToJson(server);
|
Task.Run(() => WriteServerToJson(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetChannelModulePermission(Channel channel, string moduleName, bool value) {
|
public static void SetChannelModulePermission(Channel channel, string moduleName, bool value) {
|
||||||
@ -210,7 +218,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
modules[moduleName] = value;
|
modules[moduleName] = value;
|
||||||
else
|
else
|
||||||
modules.Add(moduleName, value);
|
modules.Add(moduleName, value);
|
||||||
WriteServerToJson(server);
|
Task.Run(() => WriteServerToJson(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetChannelCommandPermission(Channel channel, string commandName, bool value) {
|
public static void SetChannelCommandPermission(Channel channel, string commandName, bool value) {
|
||||||
@ -227,7 +235,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
commands[commandName] = value;
|
commands[commandName] = value;
|
||||||
else
|
else
|
||||||
commands.Add(commandName, value);
|
commands.Add(commandName, value);
|
||||||
WriteServerToJson(server);
|
Task.Run(() => WriteServerToJson(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetRoleModulePermission(Role role, string moduleName, bool value) {
|
public static void SetRoleModulePermission(Role role, string moduleName, bool value) {
|
||||||
@ -244,7 +252,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
modules[moduleName] = value;
|
modules[moduleName] = value;
|
||||||
else
|
else
|
||||||
modules.Add(moduleName, value);
|
modules.Add(moduleName, value);
|
||||||
WriteServerToJson(server);
|
Task.Run(() => WriteServerToJson(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetRoleCommandPermission(Role role, string commandName, bool value) {
|
public static void SetRoleCommandPermission(Role role, string commandName, bool value) {
|
||||||
@ -261,7 +269,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
commands[commandName] = value;
|
commands[commandName] = value;
|
||||||
else
|
else
|
||||||
commands.Add(commandName, value);
|
commands.Add(commandName, value);
|
||||||
WriteServerToJson(server);
|
Task.Run(() => WriteServerToJson(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetUserModulePermission(User user, string moduleName, bool value) {
|
public static void SetUserModulePermission(User user, string moduleName, bool value) {
|
||||||
@ -278,7 +286,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
modules[moduleName] = value;
|
modules[moduleName] = value;
|
||||||
else
|
else
|
||||||
modules.Add(moduleName, value);
|
modules.Add(moduleName, value);
|
||||||
WriteServerToJson(server);
|
Task.Run(() => WriteServerToJson(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetUserCommandPermission(User user, string commandName, bool value) {
|
public static void SetUserCommandPermission(User user, string commandName, bool value) {
|
||||||
@ -295,7 +303,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
commands[commandName] = value;
|
commands[commandName] = value;
|
||||||
else
|
else
|
||||||
commands.Add(commandName, value);
|
commands.Add(commandName, value);
|
||||||
WriteServerToJson(server);
|
Task.Run(() => WriteServerToJson(server));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -580,8 +580,8 @@ namespace NadekoBot.Modules {
|
|||||||
var rows = Classes.DBHandler.Instance.GetAllRows<Donator>();
|
var rows = Classes.DBHandler.Instance.GetAllRows<Donator>();
|
||||||
var donatorsOrdered = rows.OrderBy(d => d.Amount);
|
var donatorsOrdered = rows.OrderBy(d => d.Amount);
|
||||||
string str = $"`Total number of people who donated is {donatorsOrdered.Count()}`\n";
|
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)));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ namespace NadekoBot.Modules {
|
|||||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
||||||
|
|
||||||
cgb.CreateCommand("~hentai")
|
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)
|
.Parameter("tag", ParameterType.Unparsed)
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
string tag = e.GetArg("tag");
|
string tag = e.GetArg("tag");
|
||||||
@ -30,7 +30,7 @@ namespace NadekoBot.Modules {
|
|||||||
await e.Send(":heart: Danbooru: " + await SearchHelper.GetDanbooruImageLink(tag));
|
await e.Send(":heart: Danbooru: " + await SearchHelper.GetDanbooruImageLink(tag));
|
||||||
});
|
});
|
||||||
cgb.CreateCommand("~danbooru")
|
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)
|
.Parameter("tag", ParameterType.Unparsed)
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
string tag = e.GetArg("tag");
|
string tag = e.GetArg("tag");
|
||||||
@ -39,7 +39,7 @@ namespace NadekoBot.Modules {
|
|||||||
await e.Send(await SearchHelper.GetDanbooruImageLink(tag));
|
await e.Send(await SearchHelper.GetDanbooruImageLink(tag));
|
||||||
});
|
});
|
||||||
cgb.CreateCommand("~gelbooru")
|
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)
|
.Parameter("tag", ParameterType.Unparsed)
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
string tag = e.GetArg("tag");
|
string tag = e.GetArg("tag");
|
||||||
|
@ -21,15 +21,39 @@ namespace NadekoBot.Modules {
|
|||||||
|
|
||||||
commands.ForEach(cmd => cmd.Init(cgb));
|
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")
|
cgb.CreateCommand(prefix + "verbose")
|
||||||
.Description("Sets whether to show when a command/module is blocked.\n**Usage**: ;verbose true")
|
.Alias(prefix + "v")
|
||||||
.Parameter("arg", ParameterType.Required)
|
.Description("Sets whether to show when a command/module is blocked.\n**Usage**: ;verbose true")
|
||||||
.Do(async e => {
|
.Parameter("arg", ParameterType.Required)
|
||||||
var arg = e.GetArg("arg");
|
.Do(async e => {
|
||||||
bool val = PermissionHelper.ValidateBool(arg);
|
var arg = e.GetArg("arg");
|
||||||
PermsHandler.SetVerbosity(e.Server, val);
|
bool val = PermissionHelper.ValidateBool(arg);
|
||||||
await e.Send($"Verbosity set to {val}.");
|
PermsHandler.SetVerbosity(e.Server, val);
|
||||||
});
|
await e.Send($"Verbosity set to {val}.");
|
||||||
|
});
|
||||||
|
|
||||||
cgb.CreateCommand(prefix + "serverperms")
|
cgb.CreateCommand(prefix + "serverperms")
|
||||||
.Alias(prefix + "sp")
|
.Alias(prefix + "sp")
|
||||||
|
Loading…
Reference in New Issue
Block a user