Merge pull request #224 from BigBotNetwork/hax-dev

Hax dev
This commit is contained in:
Skidder 2019-12-18 19:02:58 +01:00 committed by GitHub
commit d434594afe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 96 additions and 81 deletions

View file

@ -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 {

View file

@ -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 {};
}

View file

@ -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,11 +86,6 @@ 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

View file

@ -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,9 +35,15 @@ 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

View file

@ -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

View file

@ -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

View file

@ -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);