Prepare for role-basaed command permission
This commit is contained in:
1 parent
fd4c54e568
commit
3ecda23983
42 files changed
+528
-267
No files matched your search
@@ -6,6 +6,8 @@ package netneutrality;
|
||||
* 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.LoggerFactory;
|
||||
|
||||
@@ -16,9 +18,24 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ThreadManager {
|
||||
|
||||
private static ThreadManager INSTANCE;
|
||||
private final static Logger logger = LoggerFactory.getLogger(ThreadManager.class);
|
||||
public static final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
|
||||
public static final ExecutorService executor = Executors.newSingleThreadExecutor(new BaseThread("executor"));
|
||||
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() {
|
||||
logger.info("[Executor] Shutting down...");
|
||||
|
||||
@@ -39,13 +39,15 @@ public abstract class AbstractCommand {
|
||||
|
||||
public abstract Visibility getVisibility();
|
||||
|
||||
public abstract CommandType getType();
|
||||
|
||||
/**
|
||||
* @param event
|
||||
* @param args the arguments to the command
|
||||
* @return
|
||||
*/
|
||||
public abstract String execute(MessageReceivedEvent event, String args);
|
||||
|
||||
|
||||
|
||||
|
||||
public int countArgs(String command) {
|
||||
if (command.isEmpty())
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
if (v == PRIVATE && channel instanceof PrivateChannel)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package netneutrality.command.basic;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
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 netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandManager;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.utils.Settings;
|
||||
import netneutrality.utils.MessageFunction;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class HelpCommand extends AbstractCommand {
|
||||
|
||||
@@ -64,35 +61,16 @@ public class HelpCommand extends AbstractCommand {
|
||||
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) {
|
||||
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)
|
||||
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 netneutrality.MusicBot;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
|
||||
public class PingCommand extends AbstractCommand {
|
||||
|
||||
public PingCommand() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
if (countArgs(args) == 0)
|
||||
@@ -54,4 +52,9 @@ public class PingCommand extends AbstractCommand {
|
||||
return Visibility.BOTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package netneutrality.command.crypto;
|
||||
import java.io.IOException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -101,4 +102,9 @@ public class BitcoinPriceCommand extends AbstractCommand {
|
||||
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"),
|
||||
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) {
|
||||
this.iso4217Code = code;
|
||||
|
||||
@@ -3,6 +3,7 @@ package netneutrality.command.crypto;
|
||||
import java.io.IOException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import org.json.JSONException;
|
||||
|
||||
@@ -38,21 +39,17 @@ 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 {
|
||||
WebModule ethereumHttp = new WebModule(currencyUrl + currency.toUpperCase()).request();
|
||||
price = Double.toString(ethereumHttp.getAsObject().getDouble(currency));
|
||||
|
||||
} catch (IOException | RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
t.editMessage("Error getting ethereum price!").queue();
|
||||
}
|
||||
t.editMessage(messageBuilder(price)).queue();
|
||||
try {
|
||||
WebModule ethereumHttp = new WebModule(currencyUrl + currency.toUpperCase()).request();
|
||||
price = Double.toString(ethereumHttp.getAsObject().getDouble(currency));
|
||||
|
||||
} catch (IOException | RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
t.editMessage("Error getting ethereum price!").queue();
|
||||
}
|
||||
t.editMessage(messageBuilder(price)).queue();
|
||||
});
|
||||
|
||||
return null;
|
||||
@@ -93,4 +90,9 @@ public class EthereumPriceCommand extends AbstractCommand {
|
||||
return Visibility.BOTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package netneutrality.command.crypto;
|
||||
import java.io.IOException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import org.json.JSONException;
|
||||
|
||||
@@ -38,21 +39,17 @@ 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 {
|
||||
WebModule litecoinHttp = new WebModule(currencyUrl + currency).request();
|
||||
price = litecoinHttp.getAsArray().getJSONObject(0).getString("price_" + currency.toLowerCase());
|
||||
} catch (IOException | RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
t.editMessage("Error getting litecoin price!").queue();
|
||||
}
|
||||
t.editMessage(messageBuilder(price)).queue();
|
||||
|
||||
try {
|
||||
WebModule litecoinHttp = new WebModule(currencyUrl + currency).request();
|
||||
price = litecoinHttp.getAsArray().getJSONObject(0).getString("price_" + currency.toLowerCase());
|
||||
} catch (IOException | RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
t.editMessage("Error getting litecoin price!").queue();
|
||||
}
|
||||
t.editMessage(messageBuilder(price)).queue();
|
||||
|
||||
});
|
||||
|
||||
return null;
|
||||
@@ -92,4 +89,9 @@ public class LitecoinPriceCommand extends AbstractCommand {
|
||||
public Visibility getVisibility() {
|
||||
return Visibility.BOTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,134 +1,130 @@
|
||||
package netneutrality.command.message;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import netneutrality.MusicBot;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.controllers.DBBlacklist;
|
||||
import netneutrality.db.models.MBlacklist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BlacklistCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public boolean needAdmin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean needAdmin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand() {
|
||||
return "blacklist";
|
||||
}
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAlias() {
|
||||
return new String[] {"bl"};
|
||||
}
|
||||
@Override
|
||||
public String getCommand() {
|
||||
return "blacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "Manages the blacklist of your server.";
|
||||
}
|
||||
@Override
|
||||
public String[] getAlias() {
|
||||
return new String[] {"bl"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Manages the blacklist of your server.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
if (countArgs(args) > 0 && countArgs(args) < 3) {
|
||||
String word = (countArgs(args) == 2 ? parseArgs(args, 1) : "");
|
||||
|
||||
switch (parseArgs(args, 0)) {
|
||||
|
||||
case "get":
|
||||
event.getTextChannel().sendMessage("Retrieving list, please wait...").queue(t -> {
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
|
||||
if (countArgs(args) > 0 && countArgs(args) < 3) {
|
||||
String word = (countArgs(args) == 2 ? parseArgs(args, 1) : "");
|
||||
|
||||
switch (parseArgs(args, 0)) {
|
||||
|
||||
case "get":
|
||||
event.getTextChannel().sendMessage("Retrieving list, please wait...").queue(t -> {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(event.getGuild().getId(), mBlacklists -> {
|
||||
for (MBlacklist bl : mBlacklists) {
|
||||
sb.append(bl.getWord()).append(" -> ").append(bl.isEnabled() ? "enabled" : "disabled").append("\n");
|
||||
}
|
||||
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();
|
||||
});
|
||||
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;
|
||||
|
||||
case "add":
|
||||
break;
|
||||
|
||||
((DBBlacklist) DBController.get("blacklist")).add(new MBlacklist(word, true, event.getAuthor().getId(), event.getGuild().getId()), response -> {
|
||||
if (response) {
|
||||
event.getTextChannel().sendMessage("Added the word \"" + word + "\" to the blacklist.").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage("Error adding \"" + word + "\" to the blacklist. It's already blacklisted!").queue();
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case "remove":
|
||||
case "add":
|
||||
|
||||
((DBBlacklist) DBController.get("blacklist")).delete(word, event.getGuild().getId(), success -> {
|
||||
if (success) {
|
||||
event.getTextChannel().sendMessage("Removed the word \"" + word + "\" from the blacklist.").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage("Error removing \"" + word + "\" from the blacklist").queue();
|
||||
}
|
||||
});
|
||||
((DBBlacklist) DBController.get("blacklist")).add(new MBlacklist(word, true, event.getAuthor().getId(), event.getGuild().getId()), response -> {
|
||||
if (response) {
|
||||
event.getTextChannel().sendMessage("Added the word \"" + word + "\" to the blacklist.").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage("Error adding \"" + word + "\" to the blacklist. It's already blacklisted!").queue();
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
case "disable":
|
||||
case "remove":
|
||||
|
||||
((DBBlacklist) DBController.get("blacklist")).disable(word, event.getGuild().getId(), success -> {
|
||||
if (success) {
|
||||
event.getTextChannel().sendMessage("Removed the word \"" + word + "\" from the blacklist.").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage("Error removing \"" + word + "\" from the blacklist").queue();
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case "enable":
|
||||
((DBBlacklist) DBController.get("blacklist")).delete(word, event.getGuild().getId(), success -> {
|
||||
if (success) {
|
||||
event.getTextChannel().sendMessage("Removed the word \"" + word + "\" from the blacklist.").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage("Error removing \"" + word + "\" from the blacklist").queue();
|
||||
}
|
||||
});
|
||||
|
||||
((DBBlacklist) DBController.get("blacklist")).enable(word, event.getGuild().getId(), success -> {
|
||||
if (success) {
|
||||
event.getTextChannel().sendMessage("Removed the word \"" + word + "\" from the blacklist.").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage("Error removing \"" + word + "\" from the blacklist").queue();
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
|
||||
case "disable":
|
||||
|
||||
((DBBlacklist) DBController.get("blacklist")).disable(word, event.getGuild().getId(), success -> {
|
||||
if (success) {
|
||||
event.getTextChannel().sendMessage("Removed the word \"" + word + "\" from the blacklist.").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage("Error removing \"" + word + "\" from the blacklist").queue();
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case "enable":
|
||||
|
||||
((DBBlacklist) DBController.get("blacklist")).enable(word, event.getGuild().getId(), success -> {
|
||||
if (success) {
|
||||
event.getTextChannel().sendMessage("Removed the word \"" + word + "\" from the blacklist.").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage("Error removing \"" + word + "\" from the blacklist").queue();
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package netneutrality.command.message;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.utils.ChannelFunction;
|
||||
|
||||
@@ -42,6 +43,11 @@ public class PruneCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
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.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.music.MusicManager;
|
||||
|
||||
@@ -49,6 +50,11 @@ public class BitconnectCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
Member member = event.getMember();
|
||||
@@ -59,16 +65,14 @@ public class BitconnectCommand extends AbstractCommand {
|
||||
|
||||
if (player.isConnected()) {
|
||||
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
|
||||
event.getTextChannel().sendMessage("Not in your voice channel").queue();
|
||||
} else {
|
||||
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
|
||||
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.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.music.MusicManager;
|
||||
|
||||
@@ -49,6 +50,11 @@ public class DeleteQueueCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
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.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.music.MusicManager;
|
||||
|
||||
@@ -49,6 +50,11 @@ public class JoinCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
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.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.music.MusicManager;
|
||||
|
||||
@@ -49,6 +50,11 @@ public class LeaveCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
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.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.music.MusicManager;
|
||||
|
||||
@@ -49,6 +50,11 @@ public class PlayCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
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.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.music.MusicManager;
|
||||
|
||||
@@ -49,6 +50,11 @@ public class SkipCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
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.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.music.MusicManager;
|
||||
|
||||
@@ -49,6 +50,11 @@ public class StopCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
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.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.music.MusicManager;
|
||||
|
||||
@@ -49,6 +50,11 @@ public class VolumeCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
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.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.controllers.DBMessage;
|
||||
@@ -54,6 +55,11 @@ public class DatabaseCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
//TODO: Clean up the mess
|
||||
|
||||
@@ -8,6 +8,7 @@ package netneutrality.command.specific;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.music.MusicManager;
|
||||
import netneutrality.utils.Settings;
|
||||
@@ -25,7 +26,7 @@ public class EvalMethod extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,6 +54,11 @@ public class EvalMethod extends AbstractCommand {
|
||||
return Visibility.BOTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package netneutrality.command.specific;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
|
||||
public class LoggingCommand extends AbstractCommand {
|
||||
@@ -45,6 +46,11 @@ public class LoggingCommand extends AbstractCommand {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package netneutrality.command.specific;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.controllers.DBSettings;
|
||||
@@ -53,6 +54,11 @@ public class SellyCommand extends AbstractCommand {
|
||||
return Visibility.PRIVATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package netneutrality.command.specific;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
|
||||
public class ShutdownCommand extends AbstractCommand {
|
||||
@@ -41,6 +42,11 @@ public class ShutdownCommand extends AbstractCommand {
|
||||
return Visibility.BOTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
event.getJDA().shutdown();
|
||||
|
||||
@@ -8,6 +8,7 @@ package netneutrality.command.specific;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.utils.MessageFunction;
|
||||
import netneutrality.utils.Settings;
|
||||
@@ -53,6 +54,11 @@ public class TestCommand extends AbstractCommand {
|
||||
return Visibility.BOTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
if (event.getAuthor().getDiscriminator().equals(Settings.getInstance().getCreator().getDiscriminator())) {
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package netneutrality.db.controllers;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import netneutrality.MusicBot;
|
||||
import netneutrality.ThreadManager;
|
||||
import netneutrality.db.AbstractController;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.MysqlDatabase;
|
||||
import netneutrality.db.models.MBlacklist;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
@@ -18,21 +16,12 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DBBlacklist extends AbstractController {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(DBBlacklist.class);
|
||||
private final Logger logger = LoggerFactory.getLogger(DBBlacklist.class);
|
||||
|
||||
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) {
|
||||
isAlreadyBlacklisted(obj.getWord(), obj.getServerId(), blacklisted -> {
|
||||
if (blacklisted == 0) {
|
||||
@@ -49,7 +38,7 @@ public class DBBlacklist extends AbstractController {
|
||||
isAlreadyBlacklisted(word, serverId, blacklisted -> {
|
||||
if (blacklisted >= 1) {
|
||||
database.prepareAndExecuteAsync("DELETE FROM blacklist WHERE word = ? AND serverId = ?", word, serverId).async();
|
||||
logger.info("blacklisted");
|
||||
logger.debug("removed word from blacklist");
|
||||
success.accept(true);
|
||||
} else {
|
||||
logger.info("not blacklisted");
|
||||
@@ -82,7 +71,7 @@ public class DBBlacklist extends AbstractController {
|
||||
logger.info("disabled");
|
||||
success.accept(true);
|
||||
} else {
|
||||
logger.info("error disabled");
|
||||
logger.info("error disabling");
|
||||
success.accept(false);
|
||||
}
|
||||
});
|
||||
@@ -109,16 +98,12 @@ public class DBBlacklist extends AbstractController {
|
||||
}
|
||||
|
||||
public void getBlacklistFromServer(String serverId, Consumer<ArrayList<MBlacklist>> success) {
|
||||
|
||||
database.prepareAndExecuteAsync("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId).async(model -> {
|
||||
ArrayList<MBlacklist> output = new ArrayList<>();
|
||||
|
||||
|
||||
if (model.getNbRows() > 0) {
|
||||
|
||||
|
||||
for (int row = 0; row < model.getNbRows(); row++) {
|
||||
logger.debug("enter loop");
|
||||
MBlacklist bl = new MBlacklist(model.getRow(row));
|
||||
output.add(bl);
|
||||
}
|
||||
@@ -130,7 +115,7 @@ public class DBBlacklist extends AbstractController {
|
||||
}
|
||||
|
||||
@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();
|
||||
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.util.ArrayList;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
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) {
|
||||
String servername = guild.getName();
|
||||
String servername = guild.getId();
|
||||
String channelname = channel.getName();
|
||||
String username = author.getName();
|
||||
String datesent = message.getTimeCreated().format(DateTimeFormatter.ofPattern(Settings.getInstance().DATETIMEFORMAT));
|
||||
@@ -62,6 +63,22 @@ public class DBMessage extends AbstractController {
|
||||
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) {
|
||||
ArrayList<MMessage> messages = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package netneutrality.db.controllers;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import netneutrality.db.AbstractController;
|
||||
import netneutrality.db.MysqlDatabase;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
|
||||
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;
|
||||
|
||||
public class MTableModel {
|
||||
private List<String> column;
|
||||
private MRowsModel rows;
|
||||
private String tableName;
|
||||
private final List<String> column;
|
||||
private final MRowsModel rows;
|
||||
|
||||
|
||||
public MTableModel() {
|
||||
@@ -25,7 +24,6 @@ public class MTableModel {
|
||||
public MTableModel(String tableName) {
|
||||
this.column = new LinkedList<>();
|
||||
this.rows = new MRowsModel();
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public MTableModel(String... columns) {
|
||||
|
||||
@@ -58,7 +58,7 @@ public class WebModule {
|
||||
}
|
||||
|
||||
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)
|
||||
.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);
|
||||
|
||||
ThreadManager.scheduler.scheduleWithFixedDelay(() -> {
|
||||
if (getCurrentlyPlaying() == null && scheduler.queue.isEmpty())
|
||||
if ((getCurrentlyPlaying() == null && scheduler.queue.isEmpty()) || vChannel.getMembers().size() == 0)
|
||||
leave();
|
||||
}, 10, 10, TimeUnit.SECONDS);
|
||||
}, 120, 120, TimeUnit.SECONDS);
|
||||
} else
|
||||
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.TextChannel;
|
||||
import netneutrality.ThreadManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ChannelFunction {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ChannelFunction.class);
|
||||
|
||||
public static void bulkDeleteMessage(TextChannel channel, int toDelete) {
|
||||
|
||||
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 {
|
||||
channel.deleteMessages(messages).complete();
|
||||
System.out.println("Deleted " + messages.size() + " messages");
|
||||
logger.debug("Deleted " + messages.size() + " messages");
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
messages.forEach(m -> {
|
||||
|
||||
@@ -8,11 +8,15 @@ package netneutrality.utils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.controllers.DBBlacklist;
|
||||
import netneutrality.db.models.MBlacklist;
|
||||
@@ -23,6 +27,12 @@ public class MessageFunction {
|
||||
|
||||
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) {
|
||||
if (isStartingWithMention(message)) {
|
||||
return message.getMentionedMembers().get(0);
|
||||
@@ -59,29 +69,52 @@ public class MessageFunction {
|
||||
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) {
|
||||
try {
|
||||
((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(guildId, mBlacklists -> {
|
||||
if (!mBlacklists.isEmpty()) {
|
||||
|
||||
logger.debug("Not Empty");
|
||||
boolean found = false;
|
||||
for (MBlacklist aBlacklist : mBlacklists) {
|
||||
logger.debug("TESTING WORD:" + aBlacklist.getWord());
|
||||
if (msg.toLowerCase().contains(aBlacklist.getWord())) {
|
||||
((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(guildId, mBlacklists -> {
|
||||
if (!mBlacklists.isEmpty()) {
|
||||
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
message.delete().queue();
|
||||
channel.sendMessage("Not in my christian server").queue();
|
||||
boolean found = false;
|
||||
for (MBlacklist aBlacklist : mBlacklists) {
|
||||
if (msg.toLowerCase().contains(aBlacklist.getWord())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (RuntimeException ignored) {
|
||||
}
|
||||
|
||||
if (found) {
|
||||
message.delete().queue();
|
||||
channel.sendMessage("Not in my christian server").queue();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,15 +12,16 @@ import java.util.Properties;
|
||||
|
||||
public class Settings {
|
||||
|
||||
public static Settings INSTANCE;
|
||||
private Properties prop = new Properties();
|
||||
private static Settings INSTANCE;
|
||||
private final Properties prop = new Properties();
|
||||
|
||||
public Settings() {
|
||||
String configFile = "bot.config";
|
||||
InputStream is = Settings.class.getClassLoader().getResourceAsStream(configFile);
|
||||
|
||||
try {
|
||||
InputStream is = Settings.class.getClassLoader().getResourceAsStream(configFile);
|
||||
prop.load(is);
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -35,20 +36,23 @@ public class Settings {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
return prop.getProperty(key);
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
return MusicBot.getJDA().getUserById(prop.getProperty("bot.owner"));
|
||||
return MusicBot.getJDA().getUserById(get("bot.owner"));
|
||||
}
|
||||
|
||||
public Guild getOwnerGuild() {
|
||||
return MusicBot.getJDA().getGuildById(prop.getProperty("bot.ownerguild"));
|
||||
return MusicBot.getJDA().getGuildById(get("bot.ownerguild"));
|
||||
}
|
||||
|
||||
public TextChannel getLogChannel() {
|
||||
return MusicBot.getJDA().getTextChannelById(prop.getProperty("bot.errorchannel"));
|
||||
return MusicBot.getJDA().getTextChannelById(get("bot.errorchannel"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user