Merge branch 'dev-merge'
This commit is contained in:
commit
007f7ff056
24 changed files with 359 additions and 170 deletions
|
|
@ -11,17 +11,14 @@ 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.core.Config;
|
||||
import com.bbn.hadder.listener.*;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder;
|
||||
import net.dv8tion.jda.api.sharding.ShardManager;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
public class Hadder {
|
||||
|
|
@ -33,29 +30,21 @@ public class Hadder {
|
|||
}
|
||||
|
||||
public static void startBot() {
|
||||
File configfile = new File("./config.json");
|
||||
if (!configfile.exists()) {
|
||||
System.err.println("No Config File Found!");
|
||||
System.exit(1);
|
||||
}
|
||||
Config config = new Config("./config.json");
|
||||
if (!config.fileExists()) config.create();
|
||||
config.load();
|
||||
|
||||
JSONObject config = null;
|
||||
try {
|
||||
config = new JSONObject(new String(Files.readAllBytes(Paths.get(configfile.toURI()))));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Rethink.connect();
|
||||
Rethink rethink = new Rethink(config);
|
||||
rethink.connect();
|
||||
|
||||
DefaultShardManagerBuilder builder = new DefaultShardManagerBuilder();
|
||||
|
||||
builder.setShardsTotal(1);
|
||||
builder.setActivity(Activity.streaming("on the BigBotNetwork", "https://twitch.tv/BigBotNetwork"));
|
||||
builder.setToken(config.getString("Token"));
|
||||
builder.setToken(config.getToken());
|
||||
|
||||
|
||||
CommandHandler.cmdlist.addAll(
|
||||
CommandHandler commandHandler = new CommandHandler(
|
||||
List.of(
|
||||
new HelpCommand(),
|
||||
new TestCommand(),
|
||||
|
|
@ -69,14 +58,14 @@ public class Hadder {
|
|||
new GitHubCommand(),
|
||||
new ScreenshareCommand(),
|
||||
new RebootCommand(),
|
||||
new EqualsCommand()));
|
||||
new EqualsCommand()), config);
|
||||
|
||||
builder.addEventListeners(
|
||||
new MentionListener(),
|
||||
new PrivateMessageListener(),
|
||||
new CommandListener(),
|
||||
new GuildListener(),
|
||||
new ReadyListener());
|
||||
new CommandListener(rethink, commandHandler),
|
||||
new GuildListener(rethink),
|
||||
new ReadyListener(rethink));
|
||||
|
||||
try {
|
||||
shardManager = builder.build();
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package com.bbn.hadder;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import com.bbn.hadder.core.Config;
|
||||
import com.rethinkdb.RethinkDB;
|
||||
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
||||
import com.rethinkdb.net.Connection;
|
||||
import com.rethinkdb.net.Cursor;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
|
|
@ -13,12 +14,22 @@ import java.util.NoSuchElementException;
|
|||
*/
|
||||
|
||||
public class Rethink {
|
||||
private static RethinkDB r = RethinkDB.r;
|
||||
static Connection conn;
|
||||
private RethinkDB r = RethinkDB.r;
|
||||
private Connection conn;
|
||||
private Config config;
|
||||
|
||||
public static boolean connect() {
|
||||
public Rethink(Config config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public boolean connect() {
|
||||
try {
|
||||
conn = r.connection().hostname("127.0.0.1").db("Hadder").port(28015).connect();
|
||||
conn = r.connection()
|
||||
.hostname(config.getDatabaseIP())
|
||||
.db(config.getDatabaseName())
|
||||
.port(config.getDatabasePort())
|
||||
.user(config.getDatabaseUsername(), config.getDatabasePassword())
|
||||
.connect();
|
||||
System.out.println("DB CONNECTED");
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.toString());
|
||||
|
|
@ -27,31 +38,29 @@ public class Rethink {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static void disconnect() {
|
||||
public void disconnect() {
|
||||
conn.close();
|
||||
System.out.println("DISCONNECTED");
|
||||
}
|
||||
|
||||
public static String get(String table, String where, String value, String column) {
|
||||
private JSONArray getAsArray(String table, String where, String value) {
|
||||
try {
|
||||
Cursor cursor = r.table(table).filter(row -> row.g(where.toLowerCase()).eq(value)).run(conn);
|
||||
if (cursor.hasNext()) {
|
||||
String sad = new JsonParser().parse(cursor.next().toString()).getAsJsonObject().get(column).toString();
|
||||
if (sad.startsWith("\"") && sad.endsWith("\"")) {
|
||||
return sad.substring(1, sad.length()-1);
|
||||
} else {
|
||||
return sad;
|
||||
}
|
||||
} else return null;
|
||||
String string = r.table(table).filter(row -> row.g(where.toLowerCase()).eq(value)).coerceTo("array").toJson().run(conn);
|
||||
JSONArray jsonArray = new JSONArray(string);
|
||||
return jsonArray;
|
||||
} catch (NoSuchElementException e) {
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "<3";
|
||||
return new JSONArray();
|
||||
}
|
||||
|
||||
public static String update(String table, String whatvalue, String where, String wherevalue) {
|
||||
private String get(String table, String where, String value, String column) {
|
||||
return this.getAsArray(table, where, value).getJSONObject(0).getString(column);
|
||||
}
|
||||
|
||||
private String update(String table, String whatvalue, String where, String wherevalue) {
|
||||
String out="";
|
||||
try {
|
||||
Cursor cursor = r.table(table).get(whatvalue).update(r.hashMap(where, wherevalue)).run(conn);
|
||||
|
|
@ -60,30 +69,16 @@ public class Rethink {
|
|||
return out;
|
||||
}
|
||||
|
||||
public static String insertServer(String id) {
|
||||
private String insert(String table, Object object) {
|
||||
String out = "";
|
||||
try {
|
||||
Cursor cursor = r.table("server")
|
||||
.insert(r.hashMap("id", id)
|
||||
).run(conn);
|
||||
Cursor cursor = r.table(table).insert(object).run(conn);
|
||||
out = cursor.next().toString();
|
||||
} catch (ClassCastException ignored) {}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String insertUser(String id) {
|
||||
String out = "";
|
||||
try {
|
||||
Cursor cursor = r.table("user")
|
||||
.insert(r.hashMap("id", id)
|
||||
.with("prefix", "h.")
|
||||
).run(conn);
|
||||
out = cursor.next().toString();
|
||||
} catch (ClassCastException ignored) {}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
public void setup() {
|
||||
try {
|
||||
r.dbCreate("Hadder").run(conn);
|
||||
} catch (ReqlOpFailedError e) {
|
||||
|
|
@ -101,4 +96,29 @@ public class Rethink {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public String setUserPrefix(String prefix, String userid) {
|
||||
return this.update("user", userid, "prefix", prefix);
|
||||
}
|
||||
|
||||
public String getUserPrefix(String id) {
|
||||
return this.get("user", "id", id, "prefix");
|
||||
}
|
||||
|
||||
public String setServerPrefix(String prefix, String guildid) {
|
||||
return this.update("server", guildid, "prefix", prefix);
|
||||
}
|
||||
|
||||
public String getServerPrefix(String id) {
|
||||
return this.get("server", "id", id, "prefix");
|
||||
}
|
||||
|
||||
public String insertServer(String id) {
|
||||
return this.insert("server", r.hashMap("id", id).with("prefix", "h."));
|
||||
}
|
||||
|
||||
public String insertUser(String id) {
|
||||
return this.insert("user", r.hashMap("id", id).with("prefix", "h."));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ package com.bbn.hadder.commands;
|
|||
* @author Skidder / GregTCLTK
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public interface Command {
|
||||
void executed(String[] args, MessageReceivedEvent event);
|
||||
void executed(String[] args, CommandEvent event);
|
||||
String[] labels();
|
||||
String description();
|
||||
String usage();
|
||||
|
|
|
|||
43
src/main/java/com/bbn/hadder/commands/CommandEvent.java
Normal file
43
src/main/java/com/bbn/hadder/commands/CommandEvent.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package com.bbn.hadder.commands;
|
||||
|
||||
import com.bbn.hadder.Rethink;
|
||||
import com.bbn.hadder.core.CommandHandler;
|
||||
import com.bbn.hadder.core.Config;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class CommandEvent extends MessageReceivedEvent {
|
||||
|
||||
private Rethink rethink;
|
||||
private Config config;
|
||||
private CommandHandler commandHandler;
|
||||
|
||||
public CommandEvent(@Nonnull JDA api, long responseNumber, @Nonnull Message message, Config config, Rethink rethink, CommandHandler commandHandler) {
|
||||
super(api, responseNumber, message);
|
||||
this.config = config;
|
||||
this.rethink = rethink;
|
||||
this.commandHandler = commandHandler;
|
||||
}
|
||||
|
||||
public CommandEvent(@Nonnull MessageReceivedEvent event, Config config, Rethink rethink, CommandHandler commandHandler) {
|
||||
super(event.getJDA(), event.getResponseNumber(), event.getMessage());
|
||||
this.config = config;
|
||||
this.rethink = rethink;
|
||||
this.commandHandler = commandHandler;
|
||||
}
|
||||
|
||||
public Rethink getRethink() {
|
||||
return rethink;
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public CommandHandler getCommandHandler() {
|
||||
return commandHandler;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.commands.fun;
|
|||
*/
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
|
@ -23,7 +24,7 @@ import java.util.Random;
|
|||
public class GifCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (args.length > 0) {
|
||||
StringBuilder query = new StringBuilder();
|
||||
for (String arg : args) {
|
||||
|
|
@ -71,6 +72,6 @@ public class GifCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0]+" <Searchterm>";
|
||||
return "<Searchterm>";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
package com.bbn.hadder.commands.general;
|
||||
|
||||
import com.bbn.hadder.Rethink;
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
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) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (args.length == 0) {
|
||||
HashMap<String, ArrayList<Command>> hashMap = new HashMap<>();
|
||||
for (Command cmd : CommandHandler.cmdlist) {
|
||||
for (Command cmd : event.getCommandHandler().getCommandList()) {
|
||||
if (!hashMap.containsKey(cmd.getClass().getPackageName())) {
|
||||
ArrayList<Command> cmdlist = new ArrayList<>();
|
||||
cmdlist.add(cmd);
|
||||
|
|
@ -42,14 +41,14 @@ public class HelpCommand implements Command {
|
|||
new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, eb);
|
||||
event.getChannel().sendMessage(eb.build()).queue();
|
||||
} else {
|
||||
for (Command cmd : CommandHandler.cmdlist) {
|
||||
for (Command cmd : event.getCommandHandler().getCommandList()) {
|
||||
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);
|
||||
eb.addField("Usage", event.getRethink().getUserPrefix(event.getAuthor().getId()) + cmd.labels()[0] + " " + cmd.usage(), false);
|
||||
new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, eb);
|
||||
event.getChannel().sendMessage(eb.build()).queue();
|
||||
}
|
||||
|
|
@ -71,6 +70,6 @@ public class HelpCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return "help [Commandname]";
|
||||
return "[Commandname]";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.commands.general;
|
|||
*/
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
|
@ -12,7 +13,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|||
public class PingCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
event.getJDA().getRestPing().queue(ping -> {
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder).setTitle("Ping").setDescription(String.valueOf(ping)).build()).queue();
|
||||
|
|
@ -31,6 +32,6 @@ public class PingCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
package com.bbn.hadder.commands.misc;
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.EventWaiter;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class EqualsCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
event.getChannel().sendMessage(
|
||||
new MessageEditor()
|
||||
.setDefaultSettings(
|
||||
|
|
@ -53,6 +55,6 @@ public class EqualsCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return "equals";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.commands.misc;
|
|||
*/
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
|
@ -17,8 +18,9 @@ import org.json.JSONObject;
|
|||
import java.io.IOException;
|
||||
|
||||
public class GitHubCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (args.length > 0) {
|
||||
Request request = new Request.Builder().url("https://api.github.com/users/" + args[0]).build();
|
||||
try {
|
||||
|
|
@ -81,6 +83,6 @@ public class GitHubCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0]+" <Username>";
|
||||
return "<Username>";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.bbn.hadder.commands.misc;
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.EventWaiter;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
|
|
@ -11,7 +12,7 @@ import java.util.List;
|
|||
|
||||
public class ScreenshareCommand implements Command {
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (args.length>0) {
|
||||
if (args[0].matches("[0-9]*")&&args.length==1) {
|
||||
for (VoiceChannel vc : event.getGuild().getVoiceChannels()) {
|
||||
|
|
@ -83,6 +84,6 @@ public class ScreenshareCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return "screenshare <voicechannelid|voicechannelname>";
|
||||
return "<voicechannelid|voicechannelname>";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.commands.moderation;
|
|||
*/
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
|
|
@ -13,7 +14,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|||
|
||||
public class BanCommand implements Command {
|
||||
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
@Override
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (event.getGuild().getMemberById(event.getAuthor().getId()).hasPermission(Permission.BAN_MEMBERS) || event.getGuild().getOwner().getId().equals(event.getAuthor().getId())) {
|
||||
if (event.getMessage().getMentionedMembers().size() == 1) {
|
||||
Member victim = event.getMessage().getMentionedMembers().get(0);
|
||||
|
|
@ -60,6 +62,6 @@ public class BanCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0]+" <@User>";
|
||||
return "<@User>";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.commands.moderation;
|
|||
*/
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
|
|
@ -20,7 +21,7 @@ import static java.time.temporal.ChronoUnit.DAYS;
|
|||
public class ClearCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (args.length > 0) {
|
||||
if (event.getGuild().getMemberById(event.getAuthor().getId()).hasPermission(Permission.MESSAGE_MANAGE) || event.getGuild().getOwnerId().equals(event.getAuthor().getId())) {
|
||||
if (event.getGuild().getMemberById(event.getJDA().getSelfUser().getId()).hasPermission(Permission.MESSAGE_MANAGE)) {
|
||||
|
|
@ -67,6 +68,6 @@ public class ClearCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0]+" <Number>";
|
||||
return "<Number>";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
package com.bbn.hadder.commands.moderation;
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
|
||||
public class GuildPrefixCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (event.getGuild().getMemberById(event.getAuthor().getId()).hasPermission(Permission.MANAGE_SERVER) || event.getGuild().getOwnerId().equals(event.getAuthor().getId())) {
|
||||
if (args.length == 1) {
|
||||
if (!args[0].contains("\"")) {
|
||||
|
||||
event.getRethink().setServerPrefix(args[0], event.getGuild().getId());
|
||||
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder).setTitle("✅ Successfully set ✅").setDescription("I successfully set the new prefix for you to " + args[0]).build()).queue();
|
||||
} else {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, builder).setDescription("The prefix must not contain **\"**").build()).queue();
|
||||
}
|
||||
} else {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, builder).setDescription("You have to set a prefix.").build()).queue();
|
||||
}
|
||||
} else {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.NO_PERMISSION, builder).build()).queue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] labels() {
|
||||
return new String[]{"guildprefix"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Sets the Guild-Prefix";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String usage() {
|
||||
return "<New Guild-Prefix>";
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.commands.moderation;
|
|||
*/
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
|
|
@ -12,8 +13,9 @@ import net.dv8tion.jda.api.entities.Member;
|
|||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class KickCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (event.getGuild().getMemberById(event.getAuthor().getId()).hasPermission(Permission.KICK_MEMBERS) || event.getGuild().getOwnerId().equals(event.getAuthor().getId())) {
|
||||
if (event.getMessage().getMentionedMembers().size() == 1) {
|
||||
Member victim = event.getMessage().getMentionedMembers().get(0);
|
||||
|
|
@ -57,6 +59,6 @@ public class KickCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0]+" <@User>";
|
||||
return "<@User>";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package com.bbn.hadder.commands.owner;
|
|||
|
||||
import com.bbn.hadder.Rethink;
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
|
@ -18,7 +19,7 @@ import static com.bbn.hadder.Hadder.startBot;
|
|||
public class RebootCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (event.getAuthor().getId().equals("477141528981012511") || event.getAuthor().getId().equals("261083609148948488")) {
|
||||
|
||||
} else {
|
||||
|
|
@ -39,6 +40,6 @@ public class RebootCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.commands.owner;
|
|||
*/
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
|
||||
|
|
@ -12,7 +13,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|||
|
||||
public class ShutdownCommand implements Command {
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (event.getAuthor().getId().equals("477141528981012511") || event.getAuthor().getId().equals("261083609148948488")) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder).setTitle("Shutdown").build()).queue();
|
||||
|
|
@ -37,6 +38,6 @@ public class ShutdownCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.commands.owner;
|
|||
*/
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
/*
|
||||
|
|
@ -13,7 +14,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|||
|
||||
public class TestCommand implements Command {
|
||||
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
@Override
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
event.getTextChannel().sendMessage("TEST my friends").queue();
|
||||
}
|
||||
|
||||
|
|
@ -29,6 +31,6 @@ public class TestCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,25 +6,19 @@ package com.bbn.hadder.commands.settings;
|
|||
|
||||
import com.bbn.hadder.Rethink;
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
|
||||
public class PrefixCommand implements Command {
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
|
||||
public void executed(String[] args, CommandEvent event) {
|
||||
if (args.length == 1) {
|
||||
if (!args[0].contains("\"")) {
|
||||
|
||||
Rethink.update("user", event.getAuthor().getId(), "prefix", args[0]);
|
||||
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder).setTitle("✅ Successfully set ✅").setDescription("I successfully set the new prefix for you to " + args[0]).build()).queue();
|
||||
} else {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, builder).setDescription("The prefix must not contain **\"**").build()).queue();
|
||||
}
|
||||
event.getRethink().setUserPrefix(args[0], event.getAuthor().getId());
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder).setTitle("✅ Successfully set ✅").setDescription("I successfully set the new prefix for you to " + args[0]).build()).queue();
|
||||
} else {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, builder).setDescription("You have to set a prefix.").build()).queue();
|
||||
|
|
@ -43,6 +37,6 @@ public class PrefixCommand implements Command {
|
|||
|
||||
@Override
|
||||
public String usage() {
|
||||
return labels()[0]+" <New Prefix>";
|
||||
return "<New Prefix>";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,41 @@
|
|||
package com.bbn.hadder.core;
|
||||
|
||||
/*
|
||||
* @author Skidder / GregTCLTK
|
||||
*/
|
||||
|
||||
import com.bbn.hadder.Rethink;
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.commands.CommandEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandHandler {
|
||||
|
||||
public static ArrayList<Command> cmdlist = new ArrayList<>();
|
||||
List<Command> commandList;
|
||||
Config config;
|
||||
|
||||
public static void handleCommand(CommandParser.commandContainer cmd) {
|
||||
for (Command command : cmdlist) {
|
||||
for (String label : command.labels()) {
|
||||
if (label.toLowerCase().equals(cmd.invoke.toLowerCase())) command.executed(cmd.args, cmd.event);
|
||||
public CommandHandler(List<Command> commandList, Config config) {
|
||||
this.commandList = commandList;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void handle(MessageReceivedEvent event, Rethink rethink, String prefix) {
|
||||
StringBuilder regexBuilder = new StringBuilder().append("\\").append(prefix);
|
||||
String invoke = event.getMessage().getContentRaw().replaceFirst(regexBuilder.toString(), "").split(" ")[0];
|
||||
for (Command cmd : commandList) {
|
||||
for (String label : cmd.labels()) {
|
||||
if (label.equals(invoke)) {
|
||||
String argString = event.getMessage().getContentRaw()
|
||||
.replaceFirst(regexBuilder.toString(), "").replaceFirst(invoke, "");
|
||||
if (argString.startsWith(" ")) argString = argString.replaceFirst(" ", "");
|
||||
String[] args = argString.split(" ");
|
||||
if (args.length>0&&args[0].equals("")) args = new String[0];
|
||||
cmd.executed(args, new CommandEvent(event, config, rethink, this));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public List<Command> getCommandList() {
|
||||
return commandList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
package com.bbn.hadder.core;
|
||||
|
||||
/*
|
||||
* @author Skidder / GregTCLTK
|
||||
*/
|
||||
|
||||
import com.bbn.hadder.Rethink;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class CommandParser {
|
||||
public static commandContainer parser(String raw, MessageReceivedEvent event) {
|
||||
|
||||
String cmd = raw.replaceFirst(Rethink.get("user", "id", event.getAuthor().getId(), "prefix"), "");
|
||||
String[] cmdsplit = cmd.split(" ");
|
||||
String invoke = cmdsplit[0];
|
||||
ArrayList<String> split = new ArrayList<>();
|
||||
Collections.addAll(split, cmdsplit);
|
||||
String[] args = new String[split.size() - 1];
|
||||
split.subList(1, split.size()).toArray(args);
|
||||
|
||||
return new commandContainer(raw, cmd, cmdsplit, invoke, args, event);
|
||||
}
|
||||
|
||||
static class commandContainer {
|
||||
|
||||
final String raw;
|
||||
final String cmd;
|
||||
final String[] cmdsplit;
|
||||
final String invoke;
|
||||
final String[] args;
|
||||
final MessageReceivedEvent event;
|
||||
|
||||
commandContainer(String rw, String cmd, String[] cmdsplit, String invoke, String[] args, MessageReceivedEvent event) {
|
||||
this.raw = rw;
|
||||
this.cmd = cmd;
|
||||
this.cmdsplit = cmdsplit;
|
||||
this.invoke = invoke;
|
||||
this.args = args;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
85
src/main/java/com/bbn/hadder/core/Config.java
Normal file
85
src/main/java/com/bbn/hadder/core/Config.java
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package com.bbn.hadder.core;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONStringer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
public class Config {
|
||||
|
||||
private Path file;
|
||||
private JSONObject config;
|
||||
|
||||
public Config(String path) {
|
||||
this.file = Paths.get(path);
|
||||
}
|
||||
|
||||
public boolean fileExists() {
|
||||
return Files.exists(file);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
config = new JSONObject(new String(Files.readAllBytes(file)));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void create() {
|
||||
try {
|
||||
if (Files.notExists(file)) {
|
||||
file = Files.createFile(file);
|
||||
}
|
||||
Files.write(file, defaultConfigContent().getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String defaultConfigContent() {
|
||||
return new JSONStringer().object()
|
||||
.key("Token").value(null)
|
||||
.key("Owners").value(new Long[]{477141528981012511L, 261083609148948488L})
|
||||
.key("Database").object()
|
||||
.key("IP").value("127.0.0.1")
|
||||
.key("Port").value(28015)
|
||||
.key("DBName").value("Hadder")
|
||||
.key("Username").value(null)
|
||||
.key("Password").value(null)
|
||||
.endObject().endObject().toString();
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return config.getString("Token");
|
||||
}
|
||||
|
||||
public List<Object> getOwners() {
|
||||
return config.getJSONArray("Owners").toList();
|
||||
}
|
||||
|
||||
public String getDatabaseIP() {
|
||||
return config.getJSONObject("Database").getString("IP");
|
||||
}
|
||||
|
||||
public Integer getDatabasePort() {
|
||||
return config.getJSONObject("Database").getInt("Port");
|
||||
}
|
||||
|
||||
public String getDatabaseName() {
|
||||
return config.getJSONObject("Database").getString("DBName");
|
||||
}
|
||||
|
||||
public String getDatabaseUsername() {
|
||||
return config.getJSONObject("Database").getString("Username");
|
||||
}
|
||||
|
||||
public String getDatabasePassword() {
|
||||
return config.getJSONObject("Database").getString("Password");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ package com.bbn.hadder.listener;
|
|||
|
||||
import com.bbn.hadder.Rethink;
|
||||
import com.bbn.hadder.core.CommandHandler;
|
||||
import com.bbn.hadder.core.CommandParser;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
|
@ -13,12 +12,24 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|||
|
||||
public class CommandListener extends ListenerAdapter {
|
||||
|
||||
private Rethink rethink;
|
||||
private CommandHandler handler;
|
||||
|
||||
public CommandListener(Rethink rethink, CommandHandler handler) {
|
||||
this.rethink = rethink;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
if (event.isFromType(ChannelType.TEXT)) {
|
||||
if (!event.getAuthor().isBot()) {
|
||||
if (event.getMessage().getContentRaw().startsWith(Rethink.get("user", "id", event.getAuthor().getId(), "prefix"))) {
|
||||
CommandHandler.handleCommand(CommandParser.parser(event.getMessage().getContentRaw(), event));
|
||||
String[] prefixes = {rethink.getUserPrefix(event.getAuthor().getId()), rethink.getServerPrefix(event.getGuild().getId()), event.getGuild().getSelfMember().getAsMention()+" ", event.getGuild().getSelfMember().getAsMention()};
|
||||
for (String prefix : prefixes) {
|
||||
if (event.getMessage().getContentRaw().startsWith(prefix)) {
|
||||
handler.handle(event, rethink, prefix);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,14 +18,20 @@ import java.time.Instant;
|
|||
|
||||
public class GuildListener extends ListenerAdapter {
|
||||
|
||||
private Rethink rethink;
|
||||
|
||||
public GuildListener(Rethink rethink) {
|
||||
this.rethink = rethink;
|
||||
}
|
||||
|
||||
public void onGuildJoin(GuildJoinEvent event) {
|
||||
for (User user : event.getJDA().getUsers()) {
|
||||
if (!user.getId().equals(event.getJDA().getSelfUser().getId())) {
|
||||
Rethink.insertUser(user.getId());
|
||||
rethink.insertUser(user.getId());
|
||||
}
|
||||
}
|
||||
|
||||
Rethink.insertServer(event.getGuild().getId());
|
||||
rethink.insertServer(event.getGuild().getId());
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
event.getJDA().getTextChannelById("475722540140986369").sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder)
|
||||
.setTitle("Joined Server").setThumbnail(event.getGuild().getIconUrl())
|
||||
|
|
@ -55,7 +61,7 @@ public class GuildListener extends ListenerAdapter {
|
|||
|
||||
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
|
||||
if (!event.getUser().getId().equals(event.getJDA().getSelfUser().getId())) {
|
||||
Rethink.insertUser(event.getUser().getId());
|
||||
rethink.insertUser(event.getUser().getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,16 +11,22 @@ import javax.annotation.Nonnull;
|
|||
|
||||
public class ReadyListener extends ListenerAdapter {
|
||||
|
||||
private Rethink rethink;
|
||||
|
||||
public ReadyListener(Rethink rethink) {
|
||||
this.rethink = rethink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(@Nonnull ReadyEvent event) {
|
||||
Rethink.setup();
|
||||
rethink.setup();
|
||||
for (User user : event.getJDA().getUsers()) {
|
||||
if (!user.getId().equals(event.getJDA().getSelfUser().getId())) {
|
||||
Rethink.insertUser(user.getId());
|
||||
rethink.insertUser(user.getId());
|
||||
}
|
||||
}
|
||||
for (Guild g : event.getJDA().getGuilds()) {
|
||||
Rethink.insertServer(g.getId());
|
||||
rethink.insertServer(g.getId());
|
||||
}
|
||||
|
||||
BotList.post();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue