permissions pretty much finished, bugfixes and 1 improvement left
This commit is contained in:
@ -17,25 +17,60 @@ namespace NadekoBot.Classes.Permissions {
|
||||
|
||||
public bool CanRun(Command command, User user, Channel channel, out string error) {
|
||||
error = null;
|
||||
|
||||
if (channel.IsPrivate)
|
||||
return true;
|
||||
|
||||
try {
|
||||
//is it a permission command?
|
||||
if (command.Text == "Permissions")
|
||||
// if it is, check if the user has the correct role
|
||||
// if yes return true, if no return false
|
||||
// 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))))
|
||||
return true;
|
||||
else
|
||||
throw new Exception("You do not have necessary role 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);
|
||||
|
||||
if (permissionType == PermissionsHandler.PermissionBanType.None)
|
||||
return true;
|
||||
string msg;
|
||||
|
||||
throw new InvalidOperationException($"Cannot run this command: {permissionType}");
|
||||
switch (permissionType) {
|
||||
case PermissionsHandler.PermissionBanType.None:
|
||||
return true;
|
||||
case PermissionsHandler.PermissionBanType.ServerBanCommand:
|
||||
msg = $"**{command.Text}** command has been banned from use on this **server**.";
|
||||
break;
|
||||
case PermissionsHandler.PermissionBanType.ServerBanModule:
|
||||
msg = $"**{command.Category}** module has been banned from use on this **server**.";
|
||||
break;
|
||||
case PermissionsHandler.PermissionBanType.ChannelBanCommand:
|
||||
msg = $"**{command.Text}** command has been banned from use on this **channel**.";
|
||||
break;
|
||||
case PermissionsHandler.PermissionBanType.ChannelBanModule:
|
||||
msg = $"**{command.Category}** module has been banned from use on this **channel**.";
|
||||
break;
|
||||
case PermissionsHandler.PermissionBanType.RoleBanCommand:
|
||||
msg = $"You do not have a **role** which permits you the usage of **{command.Text}** command.";
|
||||
break;
|
||||
case PermissionsHandler.PermissionBanType.RoleBanModule:
|
||||
msg = $"You do not have a **role** which permits you the usage of **{command.Category}** module.";
|
||||
break;
|
||||
case PermissionsHandler.PermissionBanType.UserBanCommand:
|
||||
msg = $"{user.Mention}, You have been banned from using **{command.Text}** command.";
|
||||
break;
|
||||
case PermissionsHandler.PermissionBanType.UserBanModule:
|
||||
msg = $"{user.Mention}, You have been banned from using **{command.Category}** module.";
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
|
||||
Task.Run(() => channel.SendMessage(msg));
|
||||
return false;
|
||||
} catch (Exception ex) {
|
||||
if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
|
||||
channel.SendMessage(ex.Message);
|
||||
Task.Run(() => channel.SendMessage(ex.Message));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ namespace NadekoBot.Classes {
|
||||
case "t":
|
||||
case "true":
|
||||
case "enable":
|
||||
case "enabled":
|
||||
case "allow":
|
||||
case "unban":
|
||||
return true;
|
||||
@ -26,6 +27,7 @@ namespace NadekoBot.Classes {
|
||||
case "f":
|
||||
case "false":
|
||||
case "disable":
|
||||
case "disabled":
|
||||
case "disallow":
|
||||
case "ban":
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user