Permissions now friendly to custom reactions (soon™️)

This commit is contained in:
Kwoth 2016-09-30 17:16:30 +02:00
parent 0d918d39c9
commit 3f168a21f1
3 changed files with 27 additions and 9 deletions

View File

@ -19,8 +19,19 @@ namespace NadekoBot.Modules.Help
{
public string HelpString {
get {
var str = "To add me to your server, use this link -> <https://discordapp.com/oauth2/authorize?client_id={0}&scope=bot&permissions=66186303>\n";
return str + String.Format(str, NadekoBot.Credentials.ClientId);
var str = @"To add me to your server, use this link -> <https://discordapp.com/oauth2/authorize?client_id={0}&scope=bot&permissions=66186303>
You can use `{1}modules` command to see a list of all modules.
You can use `{1}commands ModuleName`
(for example `{1}commands Administration`) to see a list of all of the commands in that module.
For a specific command help, use {1}h ""Command name"" (for example {1}h !!q)
**LIST OF COMMANDS CAN BE FOUND ON THIS LINK**
<https://github.com/Kwoth/NadekoBot/blob/master/commandlist.md>
Nadeko Support Server: https://discord.gg/0ehQwTK2RBjAxzEY";
return String.Format(str, NadekoBot.Credentials.ClientId, NadekoBot.ModulePrefixes[typeof(Help).Name]);
}
}
public Help(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)

View File

@ -17,10 +17,17 @@ namespace NadekoBot.Modules.Permissions
{
var perms = permsEnumerable as List<Permission> ?? permsEnumerable.ToList();
int throwaway;
return perms.CheckPermissions(message, command, out throwaway);
return perms.CheckPermissions(message, command.Name, command.Module.Name, out throwaway);
}
public static bool CheckPermissions(this IEnumerable<Permission> permsEnumerable, IUserMessage message, Command command, out int permIndex)
public static bool CheckPermissions(this IEnumerable<Permission> permsEnumerable, IUserMessage message, string commandName, string moduleName)
{
var perms = permsEnumerable as List<Permission> ?? permsEnumerable.ToList();
int throwaway;
return perms.CheckPermissions(message, commandName, moduleName, out throwaway);
}
public static bool CheckPermissions(this IEnumerable<Permission> permsEnumerable, IUserMessage message, string commandName, string moduleName, out int permIndex)
{
var perms = permsEnumerable as List<Permission> ?? permsEnumerable.ToList();
@ -28,7 +35,7 @@ namespace NadekoBot.Modules.Permissions
{
var perm = perms[i];
var result = perm.CheckPermission(message, command);
var result = perm.CheckPermission(message, commandName, moduleName);
if (result == null)
{
@ -47,12 +54,12 @@ namespace NadekoBot.Modules.Permissions
//null = not applicable
//true = applicable, allowed
//false = applicable, not allowed
public static bool? CheckPermission(this Permission perm, IUserMessage message, Command command)
public static bool? CheckPermission(this Permission perm, IUserMessage message, string commandName, string moduleName)
{
if (!((perm.SecondaryTarget == SecondaryPermissionType.Command &&
perm.SecondaryTargetName.ToLowerInvariant() == command.Text.ToLowerInvariant()) ||
perm.SecondaryTargetName.ToLowerInvariant() == commandName.ToLowerInvariant()) ||
(perm.SecondaryTarget == SecondaryPermissionType.Module &&
perm.SecondaryTargetName.ToLowerInvariant() == command.Module.Name.ToLowerInvariant()) ||
perm.SecondaryTargetName.ToLowerInvariant() == moduleName.ToLowerInvariant()) ||
perm.SecondaryTarget == SecondaryPermissionType.AllModules))
return null;

View File

@ -164,7 +164,7 @@ namespace NadekoBot.Services
if (guild != null)
{
int index;
if (!rootPerm.AsEnumerable().CheckPermissions(message, cmd, out index))
if (!rootPerm.AsEnumerable().CheckPermissions(message, cmd.Name, cmd.Module.Name, out index))
{
var returnMsg = $"Permission number #{index} **{rootPerm.GetAt(index).GetCommand()}** is preventing this action.";
return new Tuple<Command, IResult>(cmd, SearchResult.FromError(CommandError.Exception, returnMsg));