Merge branch 'greg-dev' of https://github.com/BigBotNetwork/Hadder into greg-dev

This commit is contained in:
GregTCLTK 2019-10-31 19:52:24 +01:00
commit 1741885006
13 changed files with 173 additions and 5 deletions

View file

@ -6,6 +6,7 @@ import com.bbn.hadder.commands.misc.GitHubCommand;
import com.bbn.hadder.commands.moderation.*;
import com.bbn.hadder.commands.owner.RebootCommand;
import com.bbn.hadder.commands.owner.ShutdownCommand;
import com.bbn.hadder.commands.owner.TestCommand;
import com.bbn.hadder.commands.settings.PrefixCommand;
import com.bbn.hadder.core.CommandHandler;
import com.bbn.hadder.listener.*;
@ -50,8 +51,8 @@ public class Hadder {
builder.setToken(config.getString("Token"));
CommandHandler.cmdlist.addAll(List.of(new TestCommand(), new BanCommand(), new PrefixCommand(), new ShutdownCommand(), new KickCommand(), new PingCommand(), new GifCommand(), new ClearCommand(), new GitHubCommand(), new RebootCommand()));
CommandHandler.cmdlist.addAll(List.of(new HelpCommand(), new TestCommand(), new BanCommand(), new PrefixCommand(), new ShutdownCommand(), new KickCommand(), new PingCommand(), new GifCommand(), new ClearCommand(), new GitHubCommand(), new RebootCommand()));
builder.addEventListeners(
new MentionListener(),
new PrivateMessageListener(),

View file

@ -1,10 +1,10 @@
package com.bbn.hadder;
import com.google.gson.JsonParser;
import com.rethinkdb.RethinkDB;
import com.rethinkdb.gen.exc.ReqlOpFailedError;
import com.rethinkdb.net.Connection;
import com.rethinkdb.net.Cursor;
import com.google.gson.JsonParser;
import java.util.NoSuchElementException;

View file

@ -9,4 +9,6 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public interface Command {
void executed(String[] args, MessageReceivedEvent event);
String[] labels();
String description();
String usage();
}

View file

@ -63,4 +63,14 @@ public class GifCommand implements Command {
public String[] labels() {
return new String[]{"gif"};
}
@Override
public String description() {
return "Displays a gif";
}
@Override
public String usage() {
return labels()[0]+" <Searchterm>";
}
}

View file

@ -0,0 +1,76 @@
package com.bbn.hadder.commands.general;
import com.bbn.hadder.Rethink;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.core.CommandHandler;
import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class HelpCommand implements Command {
@Override
public void executed(String[] args, MessageReceivedEvent event) {
if (args.length == 0) {
HashMap<String, ArrayList<Command>> hashMap = new HashMap<>();
for (Command cmd : CommandHandler.cmdlist) {
if (!hashMap.containsKey(cmd.getClass().getPackageName())) {
ArrayList<Command> cmdlist = new ArrayList<>();
cmdlist.add(cmd);
hashMap.put(cmd.getClass().getPackageName(), cmdlist);
} else {
hashMap.get(cmd.getClass().getPackageName()).add(cmd);
}
}
EmbedBuilder eb = new EmbedBuilder();
for (Map.Entry<String, ArrayList<Command>> entry : hashMap.entrySet()) {
if (!entry.getKey().endsWith("owner") || (entry.getKey().endsWith("owner") && (event.getAuthor().getId().equals("477141528981012511") || event.getAuthor().getId().equals("261083609148948488")))) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < entry.getValue().size(); i++) {
Command cmd = entry.getValue().get(i);
sb.append("`" + cmd.labels()[0] + "`");
if (i < entry.getValue().size() - 1) sb.append(", ");
}
String[] packagesplit = entry.getKey().split("\\.");
eb.addField(packagesplit[packagesplit.length - 1], sb.toString(), false);
}
}
new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, eb);
event.getChannel().sendMessage(eb.build()).queue();
} else {
for (Command cmd : CommandHandler.cmdlist) {
for (String label : cmd.labels()) {
if (label.toLowerCase().equals(args[0])) {
if (!cmd.getClass().getPackageName().endsWith("owner") || (cmd.getClass().getPackageName().endsWith("owner") && (event.getAuthor().getId().equals("477141528981012511") || event.getAuthor().getId().equals("261083609148948488")))) {
EmbedBuilder eb = new EmbedBuilder();
String name = cmd.labels()[0];
eb.setDescription(cmd.description()).setTitle(name.replaceFirst(String.valueOf(name.charAt(0)), String.valueOf(name.charAt(0)).toUpperCase()));
eb.addField("Usage", Rethink.get("user", "id", event.getAuthor().getId(), "prefix") + cmd.usage(), false);
new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, eb);
event.getChannel().sendMessage(eb.build()).queue();
}
}
}
}
}
}
@Override
public String[] labels() {
return new String[]{"help"};
}
@Override
public String description() {
return "Shows every Command or explains a Command";
}
@Override
public String usage() {
return "help [Commandname]";
}
}

View file

@ -23,4 +23,14 @@ public class PingCommand implements Command {
public String[] labels() {
return new String[]{"ping"};
}
@Override
public String description() {
return "Shows the ping to the discord api";
}
@Override
public String usage() {
return labels()[0];
}
}

View file

@ -73,4 +73,14 @@ public class GitHubCommand implements Command {
public String[] labels() {
return new String[]{"GitHub"};
}
@Override
public String description() {
return "Shows info of an user";
}
@Override
public String usage() {
return labels()[0]+" <Username>";
}
}

View file

@ -52,4 +52,14 @@ public class BanCommand implements Command {
public String[] labels() {
return new String[]{"ban"};
}
@Override
public String description() {
return "Bans an user";
}
@Override
public String usage() {
return labels()[0]+" <@User>";
}
}

View file

@ -59,4 +59,14 @@ public class ClearCommand implements Command {
public String[] labels() {
return new String[]{"clear"};
}
@Override
public String description() {
return "Clears messages";
}
@Override
public String usage() {
return labels()[0]+" <Number>";
}
}

View file

@ -49,4 +49,14 @@ public class KickCommand implements Command {
public String[] labels() {
return new String[]{"kick"};
}
@Override
public String description() {
return "Kicks an user";
}
@Override
public String usage() {
return labels()[0]+" <@User>";
}
}

View file

@ -29,4 +29,14 @@ public class ShutdownCommand implements Command {
public String[] labels() {
return new String[]{"shutdown"};
}
@Override
public String description() {
return "Shuts the Bot down";
}
@Override
public String usage() {
return labels()[0];
}
}

View file

@ -1,4 +1,4 @@
package com.bbn.hadder.commands.general;
package com.bbn.hadder.commands.owner;
/*
* @author Skidder / GregTCLTK
@ -21,4 +21,14 @@ public class TestCommand implements Command {
public String[] labels() {
return new String[]{"test"};
}
@Override
public String description() {
return "Sub to bbn";
}
@Override
public String usage() {
return labels()[0];
}
}

View file

@ -8,7 +8,6 @@ import com.bbn.hadder.Rethink;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -36,4 +35,14 @@ public class PrefixCommand implements Command {
public String[] labels() {
return new String[]{"prefix"};
}
@Override
public String description() {
return "Changes the prefix";
}
@Override
public String usage() {
return labels()[0]+" <New Prefix>";
}
}