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() { 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 {

View file

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

View file

@ -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,16 +86,11 @@ 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
public String[] labels() { public String[] labels() {
return new String[] { "eval" }; return new String[]{"eval"};
} }
@Override @Override

View file

@ -6,9 +6,12 @@ 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.utils.MessageEditor; import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
@Perms(Perm.BOT_OWNER)
public class GuildLeaveCommand implements Command { public class GuildLeaveCommand implements Command {
@Override @Override
@ -32,14 +35,20 @@ public class GuildLeaveCommand implements Command {
} }
} else { } else {
event.getTextChannel() 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(); .queue();
} else {
event.getHelpCommand().sendHelp(this, event);
} }
} }
@Override @Override
public String[] labels() { public String[] labels() {
return new String[] { "guildleave" }; return new String[]{"guildleave"};
} }
@Override @Override

View file

@ -6,18 +6,16 @@ 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.utils.MessageEditor; import com.bbn.hadder.utils.MessageEditor;
@Perms(Perm.BOT_OWNER)
public class RebootCommand implements Command { public class RebootCommand 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())) {
Runtime.getRuntime().exit(69); Runtime.getRuntime().exit(69);
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.NO_PERMISSION).build()).queue();
}
} }
@Override @Override

View file

@ -6,20 +6,19 @@ 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.utils.MessageEditor; import com.bbn.hadder.utils.MessageEditor;
@Perms(Perm.BOT_OWNER)
public class ShutdownCommand implements Command { public class ShutdownCommand 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())) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO).setTitle("Shutdown").build()).queue(); event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO).setTitle("Shutdown").build()).queue();
event.getJDA().getShardManager().shutdown(); event.getJDA().getShardManager().shutdown();
System.out.println("Bot shut down via Command..."); System.out.println("Bot shut down via Command...");
Runtime.getRuntime().exit(69); Runtime.getRuntime().exit(69);
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.NO_PERMISSION).build()).queue();
}
} }
@Override @Override

View file

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