commit
cd013aceba
13 changed files with 172 additions and 4 deletions
|
|
@ -5,6 +5,7 @@ import com.bbn.hadder.commands.fun.GifCommand;
|
||||||
import com.bbn.hadder.commands.misc.GitHubCommand;
|
import com.bbn.hadder.commands.misc.GitHubCommand;
|
||||||
import com.bbn.hadder.commands.moderation.*;
|
import com.bbn.hadder.commands.moderation.*;
|
||||||
import com.bbn.hadder.commands.owner.ShutdownCommand;
|
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.commands.settings.PrefixCommand;
|
||||||
import com.bbn.hadder.core.CommandHandler;
|
import com.bbn.hadder.core.CommandHandler;
|
||||||
import com.bbn.hadder.listener.*;
|
import com.bbn.hadder.listener.*;
|
||||||
|
|
@ -46,7 +47,7 @@ public class Hadder {
|
||||||
builder.setToken(config.getString("Token"));
|
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()));
|
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()));
|
||||||
|
|
||||||
builder.addEventListeners(
|
builder.addEventListeners(
|
||||||
new MentionListener(),
|
new MentionListener(),
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package com.bbn.hadder;
|
package com.bbn.hadder;
|
||||||
|
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
import com.rethinkdb.RethinkDB;
|
import com.rethinkdb.RethinkDB;
|
||||||
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
||||||
import com.rethinkdb.net.Connection;
|
import com.rethinkdb.net.Connection;
|
||||||
import com.rethinkdb.net.Cursor;
|
import com.rethinkdb.net.Cursor;
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,6 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
public interface Command {
|
public interface Command {
|
||||||
void executed(String[] args, MessageReceivedEvent event);
|
void executed(String[] args, MessageReceivedEvent event);
|
||||||
String[] labels();
|
String[] labels();
|
||||||
|
String description();
|
||||||
|
String usage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,4 +63,14 @@ public class GifCommand implements Command {
|
||||||
public String[] labels() {
|
public String[] labels() {
|
||||||
return new String[]{"gif"};
|
return new String[]{"gif"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Displays a gif";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return labels()[0]+" <Searchterm>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,4 +23,14 @@ public class PingCommand implements Command {
|
||||||
public String[] labels() {
|
public String[] labels() {
|
||||||
return new String[]{"ping"};
|
return new String[]{"ping"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Shows the ping to the discord api";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return labels()[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,4 +73,14 @@ public class GitHubCommand implements Command {
|
||||||
public String[] labels() {
|
public String[] labels() {
|
||||||
return new String[]{"GitHub"};
|
return new String[]{"GitHub"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Shows info of an user";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return labels()[0]+" <Username>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,4 +52,14 @@ public class BanCommand implements Command {
|
||||||
public String[] labels() {
|
public String[] labels() {
|
||||||
return new String[]{"ban"};
|
return new String[]{"ban"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Bans an user";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return labels()[0]+" <@User>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,4 +59,14 @@ public class ClearCommand implements Command {
|
||||||
public String[] labels() {
|
public String[] labels() {
|
||||||
return new String[]{"clear"};
|
return new String[]{"clear"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Clears messages";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return labels()[0]+" <Number>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,4 +49,14 @@ public class KickCommand implements Command {
|
||||||
public String[] labels() {
|
public String[] labels() {
|
||||||
return new String[]{"kick"};
|
return new String[]{"kick"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Kicks an user";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return labels()[0]+" <@User>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,14 @@ public class ShutdownCommand implements Command {
|
||||||
public String[] labels() {
|
public String[] labels() {
|
||||||
return new String[]{"shutdown"};
|
return new String[]{"shutdown"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Shuts the Bot down";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return labels()[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bbn.hadder.commands.general;
|
package com.bbn.hadder.commands.owner;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @author Skidder / GregTCLTK
|
* @author Skidder / GregTCLTK
|
||||||
|
|
@ -21,4 +21,14 @@ public class TestCommand implements Command {
|
||||||
public String[] labels() {
|
public String[] labels() {
|
||||||
return new String[]{"test"};
|
return new String[]{"test"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Sub to bbn";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return labels()[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,6 @@ import com.bbn.hadder.Rethink;
|
||||||
import com.bbn.hadder.commands.Command;
|
import com.bbn.hadder.commands.Command;
|
||||||
import com.bbn.hadder.utils.MessageEditor;
|
import com.bbn.hadder.utils.MessageEditor;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -36,4 +35,14 @@ public class PrefixCommand implements Command {
|
||||||
public String[] labels() {
|
public String[] labels() {
|
||||||
return new String[]{"prefix"};
|
return new String[]{"prefix"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
return "Changes the prefix";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String usage() {
|
||||||
|
return labels()[0]+" <New Prefix>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue