Prepare for role-basaed command permission

This commit is contained in:
anthorob committed 2021-09-15 14:35:39 -04:00
1 parent fd4c54e568
commit 3ecda23983
42 files changed
+407 -146

No files matched your search

+19 -5
View File
@@ -1,6 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xtremcommunity.discord</groupId> <groupId>com.xtremcommunity.discord</groupId>
<artifactId>netneutrality</artifactId> <artifactId>netneutrality</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
@@ -9,8 +16,7 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
<maven.compiler.source>1.11</maven.compiler.source> <java.version>11</java.version>
<maven.compiler.target>1.11</maven.compiler.target>
</properties> </properties>
@@ -56,9 +62,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>org.mariadb.jdbc</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mariadb-java-client</artifactId>
<version>8.0.26</version> <version>2.7.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
@@ -75,6 +81,12 @@
<artifactId>log4j-slf4j-impl</artifactId> <artifactId>log4j-slf4j-impl</artifactId>
<version>2.14.1</version> <version>2.14.1</version>
</dependency> </dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.fusesource.jansi</groupId> <groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId> <artifactId>jansi</artifactId>
@@ -91,6 +103,8 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.13.2</version> <version>4.13.2</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
+19 -2
View File
@@ -6,6 +6,8 @@ package netneutrality;
* This file is closed-source. It should not be distributed or copied in any way or form * This file is closed-source. It should not be distributed or copied in any way or form
*/ */
import netneutrality.thread.BaseThread;
import netneutrality.utils.Settings;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -16,9 +18,24 @@ import java.util.concurrent.TimeUnit;
public class ThreadManager { public class ThreadManager {
private static ThreadManager INSTANCE;
private final static Logger logger = LoggerFactory.getLogger(ThreadManager.class); private final static Logger logger = LoggerFactory.getLogger(ThreadManager.class);
public static final ExecutorService executor = Executors.newSingleThreadExecutor(); public static final ExecutorService executor = Executors.newSingleThreadExecutor(new BaseThread("executor"));
public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2); public static final ExecutorService dBExecutor = Executors.newSingleThreadExecutor(new BaseThread("db-action"));
public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(5, new BaseThread("scheduled-action"));
public ThreadManager() {
}
public static ThreadManager getInstance() {
if(INSTANCE == null) {
INSTANCE = new ThreadManager();
}
return INSTANCE;
}
public static void shutdownExecutor() { public static void shutdownExecutor() {
logger.info("[Executor] Shutting down..."); logger.info("[Executor] Shutting down...");
@@ -39,13 +39,15 @@ public abstract class AbstractCommand {
public abstract Visibility getVisibility(); public abstract Visibility getVisibility();
public abstract CommandType getType();
/** /**
* @param event
* @param args the arguments to the command * @param args the arguments to the command
* @return
*/ */
public abstract String execute(MessageReceivedEvent event, String args); public abstract String execute(MessageReceivedEvent event, String args);
public int countArgs(String command) { public int countArgs(String command) {
if (command.isEmpty()) if (command.isEmpty())
return 0; return 0;
@@ -0,0 +1,14 @@
package netneutrality.command;/*
* Copyright (c) anthorob
*
* https://xtremcommunity.com/
* https://discord.gg/CdFcyQ
*/
public enum CommandType {
MUSIC(1), ADMINISTRATION(0), UTILITY(5);
CommandType(int i) {
}
}
@@ -0,0 +1,28 @@
package netneutrality.command;/*
* Copyright (c) anthorob
*
* https://xtremcommunity.com/
* https://discord.gg/CdFcyQ
*/
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import netneutrality.db.DBController;
import netneutrality.db.entities.Permission;
import netneutrality.db.models.MTableModel;
import java.util.List;
public class PermissionManager {
public static boolean CheckPermissionForUser(Guild guild, Member member, AbstractCommand command) {
//Permission permissions = DBController.get().prepareAndExecuteAsync("SELECT * FROM permissions WHERE guild_id = ?").blocking();
List<Role> roles = member.getRoles();
return false;
}
}
@@ -15,7 +15,7 @@ public enum Visibility {
PRIVATE, CHANNEL, BOTH; PRIVATE, CHANNEL, BOTH;
public static boolean check(MessageChannel channel, Visibility v) { public static boolean check(MessageChannel channel, Visibility v) {
if (v == BOTH && channel instanceof TextChannel || channel instanceof PrivateChannel) if (v == BOTH && (channel instanceof TextChannel || channel instanceof PrivateChannel))
return true; return true;
if (v == PRIVATE && channel instanceof PrivateChannel) if (v == PRIVATE && channel instanceof PrivateChannel)
@@ -1,6 +1,5 @@
package netneutrality.command.basic; package netneutrality.command.basic;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.TextChannel;
@@ -8,13 +7,11 @@ import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandManager; import netneutrality.command.CommandManager;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.utils.Settings; import netneutrality.utils.MessageFunction;
import java.awt.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.SortedSet;
import java.util.TreeSet;
public class HelpCommand extends AbstractCommand { public class HelpCommand extends AbstractCommand {
@@ -64,35 +61,16 @@ public class HelpCommand extends AbstractCommand {
return Visibility.BOTH; return Visibility.BOTH;
} }
@Override
public CommandType getType() {
return CommandType.UTILITY;
}
public void sendHelp(HashMap<String, AbstractCommand> commands, HashMap<String, AbstractCommand> alias, User user, MessageChannel channel) { public void sendHelp(HashMap<String, AbstractCommand> commands, HashMap<String, AbstractCommand> alias, User user, MessageChannel channel) {
StringBuilder help = new StringBuilder();
SortedSet<String> keys = new TreeSet<>(commands.keySet());
for (String key : keys) {
AbstractCommand command = commands.get(key);
if (command.isEnabled()) {
help.append(Settings.getInstance().getPrefix()).append(command.getCommand());
if (command.getUsage() != null)
help.append(" ").append(command.getUsage());
if (command.getDescription() != null)
help.append(": ").append(command.getDescription());
help.append("\n");
}
}
EmbedBuilder embed = new EmbedBuilder();
embed.setColor(Color.green);
embed.addField("Commands for Net Neutrality", help.toString(), false);
if (channel instanceof TextChannel) if (channel instanceof TextChannel)
channel.sendMessage(new MessageBuilder().append(user).append(" help has been sent your way!").build()).queue(); channel.sendMessage(new MessageBuilder().append(user).append(" help has been sent your way!").build()).queue();
user.openPrivateChannel().queue(t -> t.sendMessage(embed.build()).queue()); user.openPrivateChannel().queue(t -> t.sendMessage(MessageFunction.buildHelpMessage(commands, alias)).queue());
} }
} }
@@ -3,13 +3,11 @@ package netneutrality.command.basic;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.MusicBot; import netneutrality.MusicBot;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
public class PingCommand extends AbstractCommand { public class PingCommand extends AbstractCommand {
public PingCommand() {
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
if (countArgs(args) == 0) if (countArgs(args) == 0)
@@ -54,4 +52,9 @@ public class PingCommand extends AbstractCommand {
return Visibility.BOTH; return Visibility.BOTH;
} }
@Override
public CommandType getType() {
return null;
}
} }
@@ -3,6 +3,7 @@ package netneutrality.command.crypto;
import java.io.IOException; import java.io.IOException;
import java.util.function.Consumer; import java.util.function.Consumer;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@@ -101,4 +102,9 @@ public class BitcoinPriceCommand extends AbstractCommand {
return Visibility.BOTH; return Visibility.BOTH;
} }
@Override
public CommandType getType() {
return null;
}
} }
@@ -18,7 +18,7 @@ public enum Currency {
WST("WST"), XAF("XAF"), XAG("XAG"), XAU("XAU"), XBA("XBA"), XBB("XBB"), XBC("XBC"), XBD("XBD"), XCD("XCD"), XDR("XDR"), XFU("XFU"), XOF("XOF"), WST("WST"), XAF("XAF"), XAG("XAG"), XAU("XAU"), XBA("XBA"), XBB("XBB"), XBC("XBC"), XBD("XBD"), XCD("XCD"), XDR("XDR"), XFU("XFU"), XOF("XOF"),
XPD("XPD"), XPF("XPF"), XPT("XPT"), XSU("XSU"), XTS("XTS"), XUA("XUA"), XXX("XXX"), YER("YER"), ZAR("ZAR"), ZMW("ZMW"); XPD("XPD"), XPF("XPF"), XPT("XPT"), XSU("XSU"), XTS("XTS"), XUA("XUA"), XXX("XXX"), YER("YER"), ZAR("ZAR"), ZMW("ZMW");
private String iso4217Code; private final String iso4217Code;
Currency(String code) { Currency(String code) {
this.iso4217Code = code; this.iso4217Code = code;
@@ -3,6 +3,7 @@ package netneutrality.command.crypto;
import java.io.IOException; import java.io.IOException;
import java.util.function.Consumer; import java.util.function.Consumer;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import org.json.JSONException; import org.json.JSONException;
@@ -38,10 +39,7 @@ public class EthereumPriceCommand extends AbstractCommand {
} }
event.getTextChannel().sendMessage("Retreiving price, please wait...").queue(new Consumer<Message>() { event.getTextChannel().sendMessage("Retreiving price, please wait...").queue(t -> {
@Override
public void accept(Message t) {
try { try {
WebModule ethereumHttp = new WebModule(currencyUrl + currency.toUpperCase()).request(); WebModule ethereumHttp = new WebModule(currencyUrl + currency.toUpperCase()).request();
@@ -52,7 +50,6 @@ public class EthereumPriceCommand extends AbstractCommand {
t.editMessage("Error getting ethereum price!").queue(); t.editMessage("Error getting ethereum price!").queue();
} }
t.editMessage(messageBuilder(price)).queue(); t.editMessage(messageBuilder(price)).queue();
}
}); });
return null; return null;
@@ -93,4 +90,9 @@ public class EthereumPriceCommand extends AbstractCommand {
return Visibility.BOTH; return Visibility.BOTH;
} }
@Override
public CommandType getType() {
return null;
}
} }
@@ -3,6 +3,7 @@ package netneutrality.command.crypto;
import java.io.IOException; import java.io.IOException;
import java.util.function.Consumer; import java.util.function.Consumer;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import org.json.JSONException; import org.json.JSONException;
@@ -38,10 +39,7 @@ public class LitecoinPriceCommand extends AbstractCommand {
} }
event.getTextChannel().sendMessage("Retreiving price, please wait...").queue(new Consumer<Message>() { event.getTextChannel().sendMessage("Retreiving price, please wait...").queue(t -> {
@Override
public void accept(Message t) {
try { try {
WebModule litecoinHttp = new WebModule(currencyUrl + currency).request(); WebModule litecoinHttp = new WebModule(currencyUrl + currency).request();
@@ -52,7 +50,6 @@ public class LitecoinPriceCommand extends AbstractCommand {
} }
t.editMessage(messageBuilder(price)).queue(); t.editMessage(messageBuilder(price)).queue();
}
}); });
return null; return null;
@@ -92,4 +89,9 @@ public class LitecoinPriceCommand extends AbstractCommand {
public Visibility getVisibility() { public Visibility getVisibility() {
return Visibility.BOTH; return Visibility.BOTH;
} }
@Override
public CommandType getType() {
return null;
}
} }
@@ -1,15 +1,13 @@
package netneutrality.command.message; package netneutrality.command.message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.MusicBot;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.db.DBController; import netneutrality.db.DBController;
import netneutrality.db.controllers.DBBlacklist; import netneutrality.db.controllers.DBBlacklist;
import netneutrality.db.models.MBlacklist; import netneutrality.db.models.MBlacklist;
import java.util.ArrayList;
public class BlacklistCommand extends AbstractCommand { public class BlacklistCommand extends AbstractCommand {
@Override @Override
@@ -34,12 +32,12 @@ public class BlacklistCommand extends AbstractCommand {
@Override @Override
public String getUsage() { public String getUsage() {
return "Manages the blacklist of your server."; return null;
} }
@Override @Override
public String getDescription() { public String getDescription() {
return null; return "Manages the blacklist of your server.";
} }
@Override @Override
@@ -47,6 +45,11 @@ public class BlacklistCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
@@ -67,13 +70,6 @@ public class BlacklistCommand extends AbstractCommand {
t.editMessage("List of blacklisted words for this server [" + event.getGuild().getName() + "] :\n" + (mBlacklists.isEmpty() ? "No word found" : sb.toString())).queue(); t.editMessage("List of blacklisted words for this server [" + event.getGuild().getName() + "] :\n" + (mBlacklists.isEmpty() ? "No word found" : sb.toString())).queue();
}); });
// ArrayList<MBlacklist> mBlacklists = ((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(event.getGuild().getId());
// for (MBlacklist bl : mBlacklists) {
// sb.append(bl.getWord()).append(" -> ").append(bl.isEnabled() ? "enabled" : "disabled").append("\n");
// }
//
// t.editMessage("List of blacklisted words for this server [" + event.getGuild().getName() + "] :\n" + (mBlacklists.isEmpty() ? "No word found" : sb.toString())).queue();
}); });
break; break;
@@ -2,6 +2,7 @@ package netneutrality.command.message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.utils.ChannelFunction; import netneutrality.utils.ChannelFunction;
@@ -42,6 +43,11 @@ public class PruneCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
if (countArgs(args) == 1) if (countArgs(args) == 1)
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
@@ -49,6 +50,11 @@ public class BitconnectCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
Member member = event.getMember(); Member member = event.getMember();
@@ -59,16 +65,14 @@ public class BitconnectCommand extends AbstractCommand {
if (player.isConnected()) { if (player.isConnected()) {
if (player.isConnectedTo(vChannel)) { if (player.isConnectedTo(vChannel)) {
player.play("https://www.youtube.com/watch?v=A8M70M7tzTI", event.getTextChannel(), event.getMember(), true); player.play("https://www.youtube.com/watch?v=e5nyQmaq4k4", event.getTextChannel(), member, true);
} else } else
event.getTextChannel().sendMessage("Not in your voice channel").queue(); event.getTextChannel().sendMessage("Not in your voice channel").queue();
} else { } else {
player.connect(vChannel); player.connect(vChannel);
player.play("https://www.youtube.com/watch?v=A8M70M7tzTI", event.getTextChannel(), event.getMember(), true); player.play("https://www.youtube.com/watch?v=e5nyQmaq4k4", event.getTextChannel(), member, true);
} }
} else } else
event.getTextChannel().sendMessage("You are not in a voice channel").queue(); event.getTextChannel().sendMessage("You are not in a voice channel").queue();
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
@@ -49,6 +50,11 @@ public class DeleteQueueCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
Member member = event.getMember(); Member member = event.getMember();
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
@@ -49,6 +50,11 @@ public class JoinCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
Member member = event.getMember(); Member member = event.getMember();
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
@@ -49,6 +50,11 @@ public class LeaveCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
Member member = event.getMember(); Member member = event.getMember();
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
@@ -49,6 +50,11 @@ public class PlayCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
Member member = event.getMember(); Member member = event.getMember();
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
@@ -49,6 +50,11 @@ public class SkipCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
Member member = event.getMember(); Member member = event.getMember();
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
@@ -49,6 +50,11 @@ public class StopCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
Member member = event.getMember(); Member member = event.getMember();
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
@@ -49,6 +50,11 @@ public class VolumeCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
Member member = event.getMember(); Member member = event.getMember();
@@ -11,6 +11,7 @@ import net.dv8tion.jda.api.entities.PrivateChannel;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.db.DBController; import netneutrality.db.DBController;
import netneutrality.db.controllers.DBMessage; import netneutrality.db.controllers.DBMessage;
@@ -54,6 +55,11 @@ public class DatabaseCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
//TODO: Clean up the mess //TODO: Clean up the mess
@@ -8,6 +8,7 @@ package netneutrality.command.specific;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.music.MusicManager; import netneutrality.music.MusicManager;
import netneutrality.utils.Settings; import netneutrality.utils.Settings;
@@ -25,7 +26,7 @@ public class EvalMethod extends AbstractCommand {
@Override @Override
public boolean isEnabled() { public boolean isEnabled() {
return true; return false;
} }
@Override @Override
@@ -53,6 +54,11 @@ public class EvalMethod extends AbstractCommand {
return Visibility.BOTH; return Visibility.BOTH;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
@@ -2,6 +2,7 @@ package netneutrality.command.specific;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
public class LoggingCommand extends AbstractCommand { public class LoggingCommand extends AbstractCommand {
@@ -45,6 +46,11 @@ public class LoggingCommand extends AbstractCommand {
return Visibility.CHANNEL; return Visibility.CHANNEL;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
@@ -8,6 +8,7 @@ package netneutrality.command.specific;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.db.DBController; import netneutrality.db.DBController;
import netneutrality.db.controllers.DBSettings; import netneutrality.db.controllers.DBSettings;
@@ -53,6 +54,11 @@ public class SellyCommand extends AbstractCommand {
return Visibility.PRIVATE; return Visibility.PRIVATE;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
@@ -2,6 +2,7 @@ package netneutrality.command.specific;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
public class ShutdownCommand extends AbstractCommand { public class ShutdownCommand extends AbstractCommand {
@@ -41,6 +42,11 @@ public class ShutdownCommand extends AbstractCommand {
return Visibility.BOTH; return Visibility.BOTH;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
event.getJDA().shutdown(); event.getJDA().shutdown();
@@ -8,6 +8,7 @@ package netneutrality.command.specific;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import netneutrality.command.AbstractCommand; import netneutrality.command.AbstractCommand;
import netneutrality.command.CommandType;
import netneutrality.command.Visibility; import netneutrality.command.Visibility;
import netneutrality.utils.MessageFunction; import netneutrality.utils.MessageFunction;
import netneutrality.utils.Settings; import netneutrality.utils.Settings;
@@ -53,6 +54,11 @@ public class TestCommand extends AbstractCommand {
return Visibility.BOTH; return Visibility.BOTH;
} }
@Override
public CommandType getType() {
return null;
}
@Override @Override
public String execute(MessageReceivedEvent event, String args) { public String execute(MessageReceivedEvent event, String args) {
if (event.getAuthor().getDiscriminator().equals(Settings.getInstance().getCreator().getDiscriminator())) { if (event.getAuthor().getDiscriminator().equals(Settings.getInstance().getCreator().getDiscriminator())) {
@@ -1,15 +1,13 @@
package netneutrality.db.controllers; package netneutrality.db.controllers;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer; import java.util.function.Consumer;
import netneutrality.MusicBot;
import netneutrality.ThreadManager; import netneutrality.ThreadManager;
import netneutrality.db.AbstractController; import netneutrality.db.AbstractController;
import netneutrality.db.DBController;
import netneutrality.db.MysqlDatabase; import netneutrality.db.MysqlDatabase;
import netneutrality.db.models.MBlacklist; import netneutrality.db.models.MBlacklist;
import netneutrality.db.models.MTableModel; import netneutrality.db.models.MTableModel;
@@ -18,21 +16,12 @@ import org.slf4j.LoggerFactory;
public class DBBlacklist extends AbstractController { public class DBBlacklist extends AbstractController {
private final static Logger logger = LoggerFactory.getLogger(DBBlacklist.class); private final Logger logger = LoggerFactory.getLogger(DBBlacklist.class);
public DBBlacklist() { public DBBlacklist() {
} }
/**
* Returns an instance of {@link MysqlDatabase} with the database name as set in the {@link DBController} class
*
* @return {@link MysqlDatabase}
*/
public MysqlDatabase getDatabase() {
return database;
}
public void add(MBlacklist obj, Consumer<Boolean> success) { public void add(MBlacklist obj, Consumer<Boolean> success) {
isAlreadyBlacklisted(obj.getWord(), obj.getServerId(), blacklisted -> { isAlreadyBlacklisted(obj.getWord(), obj.getServerId(), blacklisted -> {
if (blacklisted == 0) { if (blacklisted == 0) {
@@ -49,7 +38,7 @@ public class DBBlacklist extends AbstractController {
isAlreadyBlacklisted(word, serverId, blacklisted -> { isAlreadyBlacklisted(word, serverId, blacklisted -> {
if (blacklisted >= 1) { if (blacklisted >= 1) {
database.prepareAndExecuteAsync("DELETE FROM blacklist WHERE word = ? AND serverId = ?", word, serverId).async(); database.prepareAndExecuteAsync("DELETE FROM blacklist WHERE word = ? AND serverId = ?", word, serverId).async();
logger.info("blacklisted"); logger.debug("removed word from blacklist");
success.accept(true); success.accept(true);
} else { } else {
logger.info("not blacklisted"); logger.info("not blacklisted");
@@ -82,7 +71,7 @@ public class DBBlacklist extends AbstractController {
logger.info("disabled"); logger.info("disabled");
success.accept(true); success.accept(true);
} else { } else {
logger.info("error disabled"); logger.info("error disabling");
success.accept(false); success.accept(false);
} }
}); });
@@ -109,16 +98,12 @@ public class DBBlacklist extends AbstractController {
} }
public void getBlacklistFromServer(String serverId, Consumer<ArrayList<MBlacklist>> success) { public void getBlacklistFromServer(String serverId, Consumer<ArrayList<MBlacklist>> success) {
database.prepareAndExecuteAsync("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId).async(model -> { database.prepareAndExecuteAsync("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId).async(model -> {
ArrayList<MBlacklist> output = new ArrayList<>(); ArrayList<MBlacklist> output = new ArrayList<>();
if (model.getNbRows() > 0) { if (model.getNbRows() > 0) {
for (int row = 0; row < model.getNbRows(); row++) { for (int row = 0; row < model.getNbRows(); row++) {
logger.debug("enter loop");
MBlacklist bl = new MBlacklist(model.getRow(row)); MBlacklist bl = new MBlacklist(model.getRow(row));
output.add(bl); output.add(bl);
} }
@@ -130,7 +115,7 @@ public class DBBlacklist extends AbstractController {
} }
@Deprecated @Deprecated
public ArrayList<MBlacklist> getBlacklistFromServer(String serverId) { public ArrayList<MBlacklist> getBlacklistFromServer(String serverId) throws ExecutionException, InterruptedException {
MTableModel model = database.prepareAndExecuteAsync("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId).blocking(); MTableModel model = database.prepareAndExecuteAsync("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId).blocking();
ArrayList<MBlacklist> output = new ArrayList<>(); ArrayList<MBlacklist> output = new ArrayList<>();
@@ -0,0 +1,18 @@
package netneutrality.db.controllers;/*
* Copyright (c) anthorob
*
* https://xtremcommunity.com/
* https://discord.gg/CdFcyQ
*/
import netneutrality.db.AbstractController;
public class DBGuild extends AbstractController {
@Override
public String getControllerName() {
return "guild";
}
}
@@ -4,6 +4,7 @@ import java.sql.SQLException;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.function.Consumer;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
@@ -35,7 +36,7 @@ public class DBMessage extends AbstractController {
} }
public void log(Guild guild, TextChannel channel, User author, Message message) { public void log(Guild guild, TextChannel channel, User author, Message message) {
String servername = guild.getName(); String servername = guild.getId();
String channelname = channel.getName(); String channelname = channel.getName();
String username = author.getName(); String username = author.getName();
String datesent = message.getTimeCreated().format(DateTimeFormatter.ofPattern(Settings.getInstance().DATETIMEFORMAT)); String datesent = message.getTimeCreated().format(DateTimeFormatter.ofPattern(Settings.getInstance().DATETIMEFORMAT));
@@ -62,6 +63,22 @@ public class DBMessage extends AbstractController {
return null; return null;
} }
public void getMessagesFromUser(String username, String serverName, int max, Consumer<ArrayList<MMessage>> success) {
database.prepareAndExecuteAsync("SELECT * FROM log_message WHERE userName = ? AND serverName = ? ORDER BY dateSent DESC LIMIT ?", username, serverName, max).async(table -> {
ArrayList<MMessage> messages = new ArrayList<>();
if (table.getNbRows() > 0) {
for (int row = 0; row < max; row++) {
messages.add(new MMessage(table.getRowModel(row)));
}
}
success.accept(messages);
});
}
@Deprecated
public ArrayList<MMessage> getMessagesFromUser(String username, String serverName, int max) { public ArrayList<MMessage> getMessagesFromUser(String username, String serverName, int max) {
ArrayList<MMessage> messages = new ArrayList<>(); ArrayList<MMessage> messages = new ArrayList<>();
@@ -1,10 +1,9 @@
package netneutrality.db.controllers; package netneutrality.db.controllers;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.ExecutionException;
import java.util.function.Consumer; import java.util.function.Consumer;
import netneutrality.db.AbstractController; import netneutrality.db.AbstractController;
import netneutrality.db.MysqlDatabase;
import netneutrality.db.models.MTableModel; import netneutrality.db.models.MTableModel;
public class DBSettings extends AbstractController { public class DBSettings extends AbstractController {
@@ -0,0 +1,14 @@
package netneutrality.db.entities;/*
* Copyright (c) anthorob
*
* https://xtremcommunity.com/
* https://discord.gg/CdFcyQ
*/
import netneutrality.db.models.MTableModel;
public interface EntityInterface<E> {
public E ConvertFromTableModel(MTableModel table);
}
@@ -0,0 +1,16 @@
package netneutrality.db.entities;/*
* Copyright (c) anthorob
*
* https://xtremcommunity.com/
* https://discord.gg/CdFcyQ
*/
public class Guild {
private int guildID;
public Guild() {
}
}
@@ -0,0 +1,53 @@
package netneutrality.db.entities;/*
* Copyright (c) anthorob
*
* https://xtremcommunity.com/
* https://discord.gg/CdFcyQ
*/
import netneutrality.command.CommandType;
import netneutrality.db.models.MTableModel;
import java.util.List;
public class Permission implements EntityInterface<Permission> {
private final String guild_id;
private final String role_id;
private final CommandType type;
private final String command;
public Permission(String guild_id, String role_id, CommandType type, String command) {
this.guild_id = guild_id;
this.role_id = role_id;
this.type = type;
this.command = command;
}
public Permission(List<Object> row) {
this.guild_id = (String) row.get(0);
this.role_id = (String) row.get(1);
this.type = (CommandType) row.get(2);
this.command = (String) row.get(3);
}
public String getGuild_id() {
return guild_id;
}
public String getRole_id() {
return role_id;
}
public CommandType getType() {
return type;
}
public String getCommand() {
return command;
}
@Override
public Permission ConvertFromTableModel(MTableModel table) {
return null;
}
}
@@ -12,9 +12,8 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
public class MTableModel { public class MTableModel {
private List<String> column; private final List<String> column;
private MRowsModel rows; private final MRowsModel rows;
private String tableName;
public MTableModel() { public MTableModel() {
@@ -25,7 +24,6 @@ public class MTableModel {
public MTableModel(String tableName) { public MTableModel(String tableName) {
this.column = new LinkedList<>(); this.column = new LinkedList<>();
this.rows = new MRowsModel(); this.rows = new MRowsModel();
this.tableName = tableName;
} }
public MTableModel(String... columns) { public MTableModel(String... columns) {
@@ -58,7 +58,7 @@ public class WebModule {
} }
public WebModule post(TreeMap<String, String> params, Map<String, String> headers) throws IOException { public WebModule post(TreeMap<String, String> params, Map<String, String> headers) throws IOException {
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), createJson(params)); RequestBody body = RequestBody.create(createJson(params), MediaType.parse("application/json; charset=utf-8"));
Request.Builder builder = new Request.Builder().url(this.url) Request.Builder builder = new Request.Builder().url(this.url)
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"); .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
@@ -71,9 +71,9 @@ public class MusicManager {
guild.getAudioManager().openAudioConnection(vChannel); guild.getAudioManager().openAudioConnection(vChannel);
ThreadManager.scheduler.scheduleWithFixedDelay(() -> { ThreadManager.scheduler.scheduleWithFixedDelay(() -> {
if (getCurrentlyPlaying() == null && scheduler.queue.isEmpty()) if ((getCurrentlyPlaying() == null && scheduler.queue.isEmpty()) || vChannel.getMembers().size() == 0)
leave(); leave();
}, 10, 10, TimeUnit.SECONDS); }, 120, 120, TimeUnit.SECONDS);
} else } else
logger.error("Error connecting!"); logger.error("Error connecting!");
} }
@@ -6,9 +6,13 @@ import java.util.List;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.TextChannel;
import netneutrality.ThreadManager; import netneutrality.ThreadManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChannelFunction { public class ChannelFunction {
private static final Logger logger = LoggerFactory.getLogger(ChannelFunction.class);
public static void bulkDeleteMessage(TextChannel channel, int toDelete) { public static void bulkDeleteMessage(TextChannel channel, int toDelete) {
if (toDelete >= 2500) return; if (toDelete >= 2500) return;
@@ -34,10 +38,10 @@ public class ChannelFunction {
} }
private static void deleteFromList(List<Message> messages, TextChannel channel) { private synchronized static void deleteFromList(List<Message> messages, TextChannel channel) {
try { try {
channel.deleteMessages(messages).complete(); channel.deleteMessages(messages).complete();
System.out.println("Deleted " + messages.size() + " messages"); logger.debug("Deleted " + messages.size() + " messages");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
messages.forEach(m -> { messages.forEach(m -> {
@@ -8,11 +8,15 @@ package netneutrality.utils;
import java.awt.*; import java.awt.*;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.*;
import netneutrality.command.AbstractCommand;
import netneutrality.db.DBController; import netneutrality.db.DBController;
import netneutrality.db.controllers.DBBlacklist; import netneutrality.db.controllers.DBBlacklist;
import netneutrality.db.models.MBlacklist; import netneutrality.db.models.MBlacklist;
@@ -23,6 +27,12 @@ public class MessageFunction {
private final static Logger logger = LoggerFactory.getLogger(MessageFunction.class); private final static Logger logger = LoggerFactory.getLogger(MessageFunction.class);
public static void logMessageIfNeeded(Guild guild, TextChannel channel, User author, Message message) {
}
public static Member getStartingMention(Message message) { public static Member getStartingMention(Message message) {
if (isStartingWithMention(message)) { if (isStartingWithMention(message)) {
return message.getMentionedMembers().get(0); return message.getMentionedMembers().get(0);
@@ -59,18 +69,42 @@ public class MessageFunction {
return message.build(); return message.build();
} }
public static MessageEmbed buildHelpMessage(HashMap<String, AbstractCommand> commands, HashMap<String, AbstractCommand> alias) {
EmbedBuilder message = new EmbedBuilder();
message.setTitle("Commands for Net Neutrality");
message.setColor(Color.green);
SortedSet<String> keys = new TreeSet<>(commands.keySet());
for (String key : keys) {
AbstractCommand command = commands.get(key);
String usage = "None";
String description = "No description yet";
if (command.isEnabled()) {
if (command.getUsage() != null)
usage = command.getUsage();
if (command.getDescription() != null)
description = command.getDescription();
}
message.addField(Settings.getInstance().get("bot.prefix") + command.getCommand() + " - Arguments: " + usage, description, false);
}
return message.build();
}
public static void checkBlacklist(String guildId, Message message, TextChannel channel, String msg) { public static void checkBlacklist(String guildId, Message message, TextChannel channel, String msg) {
try {
((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(guildId, mBlacklists -> { ((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(guildId, mBlacklists -> {
if (!mBlacklists.isEmpty()) { if (!mBlacklists.isEmpty()) {
logger.debug("Not Empty");
boolean found = false; boolean found = false;
for (MBlacklist aBlacklist : mBlacklists) { for (MBlacklist aBlacklist : mBlacklists) {
logger.debug("TESTING WORD:" + aBlacklist.getWord());
if (msg.toLowerCase().contains(aBlacklist.getWord())) { if (msg.toLowerCase().contains(aBlacklist.getWord())) {
found = true; found = true;
break;
} }
} }
@@ -80,8 +114,7 @@ public class MessageFunction {
} }
} }
}); });
} catch (RuntimeException ignored) {
}
} }
} }
@@ -12,15 +12,16 @@ import java.util.Properties;
public class Settings { public class Settings {
public static Settings INSTANCE; private static Settings INSTANCE;
private Properties prop = new Properties(); private final Properties prop = new Properties();
public Settings() { public Settings() {
String configFile = "bot.config"; String configFile = "bot.config";
InputStream is = Settings.class.getClassLoader().getResourceAsStream(configFile);
try { try {
InputStream is = Settings.class.getClassLoader().getResourceAsStream(configFile);
prop.load(is); prop.load(is);
is.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -35,20 +36,23 @@ public class Settings {
return INSTANCE; return INSTANCE;
} }
public String get(String key) {
return prop.getProperty(key);
}
public final String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss"; public final String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss";
public String getPrefix() { return prop.getProperty("bot.prefix"); }
public String getToken() { return prop.getProperty("bot.token"); }
public User getCreator() { public User getCreator() {
return MusicBot.getJDA().getUserById(prop.getProperty("bot.owner")); return MusicBot.getJDA().getUserById(get("bot.owner"));
} }
public Guild getOwnerGuild() { public Guild getOwnerGuild() {
return MusicBot.getJDA().getGuildById(prop.getProperty("bot.ownerguild")); return MusicBot.getJDA().getGuildById(get("bot.ownerguild"));
} }
public TextChannel getLogChannel() { public TextChannel getLogChannel() {
return MusicBot.getJDA().getTextChannelById(prop.getProperty("bot.errorchannel")); return MusicBot.getJDA().getTextChannelById(get("bot.errorchannel"));
} }
@@ -1,30 +0,0 @@
package netneutrality.db;
/*
* Copyright (c) anthorob
*
* https://xtremcommunity.com/
* https://discord.gg/CdFcyQ
*/
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class MysqlDatabaseTest {
MysqlDatabase db;
@Before
public void setUp() throws Exception {
db = new MysqlDatabase("discord");
}
@Test
public void exists() {
Assert.assertTrue(db.exists("settings", "skey", "prefix"));
}
}