commit
d434594afe
7 changed files with 96 additions and 81 deletions
|
|
@ -11,7 +11,7 @@ public enum Perm {
|
|||
BOT_OWNER() {
|
||||
@Override
|
||||
public boolean check(CommandEvent commandEvent) {
|
||||
return commandEvent.getConfig().getOwners().contains(commandEvent.getAuthor().getId());
|
||||
return commandEvent.getConfig().getOwners().contains(commandEvent.getAuthor().getIdLong());
|
||||
}
|
||||
},
|
||||
MANAGE_MESSAGES {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@
|
|||
|
||||
package com.bbn.hadder.commands;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Perms {
|
||||
Perm[] value() default {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ package com.bbn.hadder.commands.owner;
|
|||
import com.bbn.hadder.Hadder;
|
||||
import com.bbn.hadder.commands.Command;
|
||||
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 javax.script.ScriptEngine;
|
||||
|
|
@ -16,11 +18,11 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Perms(Perm.BOT_OWNER)
|
||||
public class EvalCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (event.getConfig().getOwners().toString().contains(event.getAuthor().getId())) {
|
||||
if (args.length > 0) {
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
|
||||
|
||||
|
|
@ -84,16 +86,11 @@ public class EvalCommand implements Command {
|
|||
} else {
|
||||
event.getHelpCommand().sendHelp(this, event);
|
||||
}
|
||||
} else {
|
||||
event.getTextChannel()
|
||||
.sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.NO_PERMISSION).build())
|
||||
.queue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] labels() {
|
||||
return new String[] { "eval" };
|
||||
return new String[]{"eval"};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,9 +6,12 @@ package com.bbn.hadder.commands.owner;
|
|||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
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 net.dv8tion.jda.api.entities.Guild;
|
||||
|
||||
@Perms(Perm.BOT_OWNER)
|
||||
public class GuildLeaveCommand implements Command {
|
||||
|
||||
@Override
|
||||
|
|
@ -32,14 +35,20 @@ public class GuildLeaveCommand implements Command {
|
|||
}
|
||||
} else {
|
||||
event.getTextChannel()
|
||||
.sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.NO_PERMISSION).build())
|
||||
.sendMessage(event.getMessageEditor()
|
||||
.getMessage(MessageEditor.MessageType.INFO, "commands.owner.guildleave.success.title",
|
||||
"", "commands.owner.guildleave.success.description", guild.getName())
|
||||
.build())
|
||||
.queue();
|
||||
} else {
|
||||
event.getHelpCommand().sendHelp(this, event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] labels() {
|
||||
return new String[] { "guildleave" };
|
||||
return new String[]{"guildleave"};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,18 +6,16 @@ package com.bbn.hadder.commands.owner;
|
|||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.commands.Perm;
|
||||
import com.bbn.hadder.commands.Perms;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
|
||||
|
||||
@Perms(Perm.BOT_OWNER)
|
||||
public class RebootCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (event.getConfig().getOwners().toString().contains(event.getAuthor().getId())) {
|
||||
Runtime.getRuntime().exit(69);
|
||||
} else {
|
||||
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.NO_PERMISSION).build()).queue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,20 +6,19 @@ package com.bbn.hadder.commands.owner;
|
|||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.commands.Perm;
|
||||
import com.bbn.hadder.commands.Perms;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
|
||||
@Perms(Perm.BOT_OWNER)
|
||||
public class ShutdownCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (event.getConfig().getOwners().toString().contains(event.getAuthor().getId())) {
|
||||
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO).setTitle("Shutdown").build()).queue();
|
||||
event.getJDA().getShardManager().shutdown();
|
||||
System.out.println("Bot shut down via Command...");
|
||||
Runtime.getRuntime().exit(69);
|
||||
} else {
|
||||
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.NO_PERMISSION).build()).queue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.bbn.hadder.commands.general.HelpCommand;
|
|||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandHandler {
|
||||
|
|
@ -37,8 +38,15 @@ public class CommandHandler {
|
|||
CommandEvent commandEvent = new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink,
|
||||
config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()));
|
||||
|
||||
for (Perm perm : ((Perms) cmd).value()) {
|
||||
if (!perm.check(commandEvent)) return;
|
||||
if (!Arrays.asList(cmd.getClass().getAnnotations()).contains(Perms.class)) {
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue