Just some stuff
This commit is contained in:
parent
dde3848d37
commit
f32fc9b4bd
4 changed files with 74 additions and 65 deletions
|
|
@ -11,7 +11,7 @@ public enum Perm {
|
||||||
BOT_OWNER() {
|
BOT_OWNER() {
|
||||||
@Override
|
@Override
|
||||||
public boolean check(CommandEvent commandEvent) {
|
public boolean check(CommandEvent commandEvent) {
|
||||||
return commandEvent.getConfig().getOwners().contains(commandEvent.getAuthor().getId());
|
return commandEvent.getConfig().getOwners().contains(commandEvent.getAuthor().getIdLong());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
MANAGE_MESSAGES {
|
MANAGE_MESSAGES {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,10 @@
|
||||||
|
|
||||||
package com.bbn.hadder.commands;
|
package com.bbn.hadder.commands;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Perms {
|
public @interface Perms {
|
||||||
Perm[] value() default {};
|
Perm[] value() default {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ package com.bbn.hadder.commands.owner;
|
||||||
import com.bbn.hadder.Hadder;
|
import com.bbn.hadder.Hadder;
|
||||||
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.utils.MessageEditor;
|
import com.bbn.hadder.utils.MessageEditor;
|
||||||
|
|
||||||
import javax.script.ScriptEngine;
|
import javax.script.ScriptEngine;
|
||||||
|
|
@ -16,11 +18,11 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Perms(Perm.BOT_OWNER)
|
||||||
public class EvalCommand implements Command {
|
public class EvalCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executed(String[] args, CommandEvent event) {
|
public void executed(String[] args, CommandEvent event) {
|
||||||
if (event.getConfig().getOwners().toString().contains(event.getAuthor().getId())) {
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
|
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
|
||||||
|
|
||||||
|
|
@ -84,11 +86,6 @@ public class EvalCommand implements Command {
|
||||||
} else {
|
} else {
|
||||||
event.getHelpCommand().sendHelp(this, event);
|
event.getHelpCommand().sendHelp(this, event);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
event.getTextChannel()
|
|
||||||
.sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.NO_PERMISSION).build())
|
|
||||||
.queue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ 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;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandHandler {
|
public class CommandHandler {
|
||||||
|
|
@ -37,8 +38,15 @@ public class CommandHandler {
|
||||||
CommandEvent commandEvent = 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 (Arrays.asList(cmd.getClass().getAnnotations()).contains(Perms.class)) {
|
||||||
if (!perm.check(commandEvent)) return;
|
for (Perm perm : cmd.getClass().getAnnotation(Perms.class).value()) {
|
||||||
|
if (!perm.check(commandEvent)) {
|
||||||
|
commandEvent.getTextChannel()
|
||||||
|
.sendMessage(commandEvent.getMessageEditor().getMessage(MessageEditor.MessageType.NO_PERMISSION).build())
|
||||||
|
.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.executed(args, commandEvent);
|
cmd.executed(args, commandEvent);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue