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?
|
||||
// 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.");
|
||||
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);
|
||||
|
||||
|
@ -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>
|
||||
|
@ -580,8 +580,8 @@ namespace NadekoBot.Modules {
|
||||
var rows = Classes.DBHandler.Instance.GetAllRows<Donator>();
|
||||
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)));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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");
|
||||
|
@ -21,15 +21,39 @@ 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")
|
||||
.Description("Sets whether to show when a command/module is blocked.\n**Usage**: ;verbose true")
|
||||
.Parameter("arg", ParameterType.Required)
|
||||
.Do(async e => {
|
||||
var arg = e.GetArg("arg");
|
||||
bool val = PermissionHelper.ValidateBool(arg);
|
||||
PermsHandler.SetVerbosity(e.Server, val);
|
||||
await e.Send($"Verbosity set to {val}.");
|
||||
});
|
||||
.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 => {
|
||||
var arg = e.GetArg("arg");
|
||||
bool val = PermissionHelper.ValidateBool(arg);
|
||||
PermsHandler.SetVerbosity(e.Server, val);
|
||||
await e.Send($"Verbosity set to {val}.");
|
||||
});
|
||||
|
||||
cgb.CreateCommand(prefix + "serverperms")
|
||||
.Alias(prefix + "sp")
|
||||
|
Loading…
Reference in New Issue
Block a user