Merge pull request #223 from BigBotNetwork/hax-dev
Introducing the Permission System
This commit is contained in:
commit
4a190b73d7
4 changed files with 69 additions and 17 deletions
|
|
@ -4,20 +4,64 @@
|
||||||
|
|
||||||
package com.bbn.hadder.commands;
|
package com.bbn.hadder.commands;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
|
||||||
public enum Perm {
|
public enum Perm {
|
||||||
|
|
||||||
BOT_OWNER() {
|
BOT_OWNER() {
|
||||||
public boolean check() {
|
@Override
|
||||||
return true;
|
public boolean check(CommandEvent commandEvent) {
|
||||||
|
return commandEvent.getConfig().getOwners().contains(commandEvent.getAuthor().getId());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
MANAGE_MESSAGES,
|
MANAGE_MESSAGES {
|
||||||
EMBED_MESSAGES,
|
@Override
|
||||||
BAN_MEMBERS,
|
public boolean check(CommandEvent commandEvent) {
|
||||||
KICK_MEMBERS,
|
return commandEvent.getMember().hasPermission(Permission.MESSAGE_MANAGE);
|
||||||
MANAGE_SERVER,
|
}
|
||||||
MANAGE_ROLES,
|
},
|
||||||
CHANGE_NICKNAME,
|
EMBED_MESSAGES {
|
||||||
ADMIN_PERMISSIONS
|
@Override
|
||||||
|
public boolean check(CommandEvent commandEvent) {
|
||||||
|
return commandEvent.getMember().hasPermission(Permission.MESSAGE_EMBED_LINKS);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
BAN_MEMBERS {
|
||||||
|
@Override
|
||||||
|
public boolean check(CommandEvent commandEvent) {
|
||||||
|
return commandEvent.getMember().hasPermission(Permission.BAN_MEMBERS);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KICK_MEMBERS {
|
||||||
|
@Override
|
||||||
|
public boolean check(CommandEvent commandEvent) {
|
||||||
|
return commandEvent.getMember().hasPermission(Permission.KICK_MEMBERS);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MANAGE_SERVER {
|
||||||
|
@Override
|
||||||
|
public boolean check(CommandEvent commandEvent) {
|
||||||
|
return commandEvent.getMember().hasPermission(Permission.MANAGE_SERVER);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MANAGE_ROLES {
|
||||||
|
@Override
|
||||||
|
public boolean check(CommandEvent commandEvent) {
|
||||||
|
return commandEvent.getMember().hasPermission(Permission.MANAGE_ROLES);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CHANGE_NICKNAME {
|
||||||
|
@Override
|
||||||
|
public boolean check(CommandEvent commandEvent) {
|
||||||
|
return commandEvent.getMember().hasPermission(Permission.NICKNAME_CHANGE);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ADMIN_PERMISSIONS {
|
||||||
|
@Override
|
||||||
|
public boolean check(CommandEvent commandEvent) {
|
||||||
|
return commandEvent.getMember().hasPermission(Permission.ADMINISTRATOR);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public abstract boolean check(CommandEvent commandEvent);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@
|
||||||
package com.bbn.hadder.commands;
|
package com.bbn.hadder.commands;
|
||||||
|
|
||||||
public @interface Perms {
|
public @interface Perms {
|
||||||
Perm[] perms() default {};
|
Perm[] value() default {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.bbn.hadder.commands.owner;
|
||||||
|
|
||||||
import com.bbn.hadder.commands.Command;
|
import com.bbn.hadder.commands.Command;
|
||||||
import com.bbn.hadder.commands.CommandEvent;
|
import com.bbn.hadder.commands.CommandEvent;
|
||||||
|
import com.bbn.hadder.commands.Perm;
|
||||||
import com.bbn.hadder.commands.Perms;
|
import com.bbn.hadder.commands.Perms;
|
||||||
import com.bbn.hadder.utils.MessageEditor;
|
import com.bbn.hadder.utils.MessageEditor;
|
||||||
import com.bbn.hadder.utils.MessageEditor.MessageType;
|
import com.bbn.hadder.utils.MessageEditor.MessageType;
|
||||||
|
|
@ -12,7 +13,7 @@ import static com.bbn.hadder.commands.Perm.BOT_OWNER;
|
||||||
* @author Skidder / GregTCLTK
|
* @author Skidder / GregTCLTK
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Perms(perms = BOT_OWNER)
|
@Perms(Perm.BOT_OWNER)
|
||||||
public class TestCommand implements Command {
|
public class TestCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package com.bbn.hadder.core;
|
||||||
import com.bbn.hadder.Rethink;
|
import com.bbn.hadder.Rethink;
|
||||||
import com.bbn.hadder.commands.Command;
|
import com.bbn.hadder.commands.Command;
|
||||||
import com.bbn.hadder.commands.CommandEvent;
|
import com.bbn.hadder.commands.CommandEvent;
|
||||||
|
import com.bbn.hadder.commands.Perm;
|
||||||
|
import com.bbn.hadder.commands.Perms;
|
||||||
import com.bbn.hadder.commands.general.HelpCommand;
|
import com.bbn.hadder.commands.general.HelpCommand;
|
||||||
import com.bbn.hadder.utils.MessageEditor;
|
import com.bbn.hadder.utils.MessageEditor;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
@ -30,11 +32,16 @@ public class CommandHandler {
|
||||||
.replaceFirst(prefix, "").replaceFirst(invoke, "");
|
.replaceFirst(prefix, "").replaceFirst(invoke, "");
|
||||||
if (argString.startsWith(" ")) argString = argString.replaceFirst(" ", "");
|
if (argString.startsWith(" ")) argString = argString.replaceFirst(" ", "");
|
||||||
String[] args = argString.split(" ");
|
String[] args = argString.split(" ");
|
||||||
if (args.length>0&&args[0].equals("")) args = new String[0];
|
if (args.length > 0 && args[0].equals("")) args = new String[0];
|
||||||
cmd.executed(args,
|
|
||||||
new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink,
|
CommandEvent commandEvent = new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink,
|
||||||
config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()))
|
config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()));
|
||||||
);
|
|
||||||
|
for (Perm perm : ((Perms) cmd).value()) {
|
||||||
|
if (!perm.check(commandEvent)) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.executed(args, commandEvent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue