patches to command manager(and elsewhere) and added info command

Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
lever1209 2021-12-08 00:46:46 -04:00
commit 0fddf1e458
No known key found for this signature in database
GPG key ID: EEBCBB60C9DFC782
15 changed files with 475 additions and 132 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
/bin/
/src/pkg/deepCurse/nopalmo/core/TokenVault.java
/nopalmo.lock

View file

@ -23,9 +23,10 @@ public interface CommandInterface { // TODO rewrite to implement type args?
return false;
}
public default boolean isPremium() { // im probably never gonna use this, but ill leave it in for those who want to
public default int getPremiumLevel() { // im probably never gonna use this, but ill leave it in for those who want
// to
// see how i would implement it
return false;
return 0;
}
public abstract HelpPage getHelpPage();
@ -36,8 +37,20 @@ public interface CommandInterface { // TODO rewrite to implement type args?
public String getHelp();
public default String getUsage() {
return Global.prefix + getCommandName();
public default String getUsage(boolean hasPermissionInfo) {
StringBuilder sB = new StringBuilder();
for (Argument i : getArguments().values()) {
if (!i.isDeveloper() || (hasPermissionInfo && i.isDeveloper())) {
sB.append(i.isRequired() ? "<" : "[");
if (i.getPrefixRequirement()) {
sB.append(Argument.argumentPrefix);
}
sB.append(i.getArgName() + (i.isRequired() ? "> " : "] "));
}
}
return (Global.prefix + getCommandName() + " " + sB.toString()).strip();
}
public default int getTimeout() {
@ -45,9 +58,7 @@ public interface CommandInterface { // TODO rewrite to implement type args?
}
@Nullable
public default HashMap<String, Argument> getArguments() {
return null;
}
public HashMap<String, Argument> getArguments();
public interface DualCommandInterface extends DirectCommandInterface, GuildCommandInterface {
@Override
@ -82,8 +93,4 @@ public interface CommandInterface { // TODO rewrite to implement type args?
}
}
public default String getCompleteUsage() {
return Global.prefix + getCommandName();
}
}

View file

@ -5,6 +5,7 @@ import java.util.HashMap;
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Guild;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
@ -27,7 +28,7 @@ public class Prefix implements GuildCommandInterface {
Guild.Prefix.setPrefix(
blob.getEvent().getGuild().getIdLong(), argumentList.get("prefix").getWildCardString());
blob.getEvent().getChannel().sendMessage("Set prefix to " + argumentList.get("prefix").getWildCardString()).queue();
blob.getChannel().sendMessage("Remember: you can always ping me to use any command in case you forget the prefix").queue();
if (!Users.isAdvancedUser(blob.getUserID())) blob.getChannel().sendMessage("Remember: you can always ping me to use any command in case you forget the prefix").queue();
} else {
Guild.Prefix.setPrefix(
blob.getEvent().getGuild().getIdLong(), Global.prefix);
@ -45,11 +46,6 @@ public class Prefix implements GuildCommandInterface {
return args;
}
@Override
public String getUsage() {
return Global.prefix + getCommandName() + " <prefix>";
}
@Override
public String getHelp() {
return "Sets a prefix for your guild";

View file

@ -2,6 +2,8 @@ package pkg.deepCurse.nopalmo.command.commands.general;
import java.util.HashMap;
import org.jetbrains.annotations.Nullable;
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
@ -23,9 +25,24 @@ public class Test implements GuildCommandInterface {
return "A command used to test various things";
}
@Override
public boolean isNSFW() {
return true;
}
@Override
public int getPremiumLevel() {
return 1;
}
@Override
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
blob.getEvent().getChannel().sendMessage("Tested").queue();
}
@Override
public @Nullable HashMap<String, Argument> getArguments() {
return null;
}
}

View file

@ -3,7 +3,6 @@ package pkg.deepCurse.nopalmo.command.commands.info;
import java.util.HashMap;
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob;
@ -32,7 +31,7 @@ public class Git implements DualCommandInterface {
blob.getChannel().sendMessage("This is the automatically running argument inside of " + this.getCommandName()).queue();
}).setPrefixRequirement(true).setAutoStartRunnable(true));
}).setPrefixRequirement(true).setAutoStartRunnable(true).setDeveloper(true));
return args;
}
@ -42,9 +41,4 @@ public class Git implements DualCommandInterface {
return "Posts my github link";
}
@Override
public String getCompleteUsage() {
return Global.prefix + getCommandName() + " [-test]";
}
}

View file

@ -8,9 +8,7 @@ import java.util.List;
import net.dv8tion.jda.api.EmbedBuilder;
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
import pkg.deepCurse.nopalmo.global.Tools;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob;
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
import pkg.deepCurse.nopalmo.manager.GuildCommandManager;
@ -32,8 +30,6 @@ public class Help implements GuildCommandInterface {
deniedPages.add(HelpPage.EGG);
deniedPages.add(HelpPage.TESTING);
// System.out.println(argumentMap.size()+":"+devEnabled+"\n"+argumentMap.toString());
if (argumentMap.isEmpty() || (isDevEnabled && argumentMap.size() == 1)) {
EmbedBuilder embed = new EmbedBuilder().setTitle(isDevEnabled ? "^Commands:" : "Commands:");
@ -75,32 +71,25 @@ public class Help implements GuildCommandInterface {
GuildCommandInterface ping = blob.getCommandManager().getCommand("ping");
if (ping != null) {
sB.append("`" + ping.getUsage() + "`\n");
sB.append("`" + ping.getUsage(isDevEnabled) + "`\n");
}
GuildCommandInterface help = blob.getCommandManager().getCommand("help");
if (help != null) {
sB.append("`" + help.getUsage() + "`\n");
GuildCommandInterface info = blob.getCommandManager().getCommand("info");
if (info != null) {
sB.append("`" + info.getUsage(isDevEnabled) + "`\n");
}
GuildCommandInterface prefix = blob.getCommandManager().getCommand("prefix");
if (prefix != null) {
sB.append("`" + prefix.getUsage() + "`\n");
sB.append("`" + prefix.getUsage(isDevEnabled) + "`\n");
}
embed.addField("Information:", "Commands to take note of:\n" + sB, false);
// embed.addField("Commands : ", "`"+sB.toString()+"`\n", true);
// desc.append("`").append(sB).append("`\n");
// embed.addBlankField(true);
// embed.setFooter("Command list requested by: "+event.getAuthor().getAsTag(),
// event.getAuthor().getEffectiveAvatarUrl());
embed.setFooter(blob.getEvent().getMember().getEffectiveName(),
blob.getEvent().getMember().getUser().getEffectiveAvatarUrl());
embed.setTimestamp(Instant.now());
embed.setColor(0);
embed.setColor(Global.getEmbedColor());
blob.getChannel().sendMessageEmbeds(embed.build()).queue();
@ -111,47 +100,57 @@ public class Help implements GuildCommandInterface {
if (command != null && ((deniedPages.contains(command.getHelpPage()) && isDevEnabled)
|| !deniedPages.contains(command.getHelpPage()))) {
if (!command.isNSFW()) {
EmbedBuilder eB = new EmbedBuilder();
if (!(command.isNSFW() && !blob.getChannel().isNSFW())) {
EmbedBuilder eB = new EmbedBuilder();
eB.setColor(0);
StringBuilder sB = new StringBuilder();
eB.setColor(Global.getEmbedColor());
StringBuilder sB = new StringBuilder();
eB.setTitle("Help results for: " + command.getCommandName());
if (command.getHelp() != null) {
eB.addField("Help info:", command.getHelp(), false);
} else {
eB.addField("Help info:", "This command does not contain help information", false);
}
eB.addField("Usage:", command.getUsage(), false);
eB.setFooter("Page: " + command.getHelpPage().toString());
if (command.getCommandCalls().length > 1) {
for (int i = 1; i < command.getCommandCalls().length; i++) {
sB.append("`"+command.getCommandCalls()[i]+"` ");
eB.setTitle("Help results for: " + command.getCommandName());
if (command.getHelp() != null) {
eB.addField("Help info:", command.getHelp(), false);
} else {
eB.addField("Help info:", "This command does not contain help information", false);
}
sB.append("\n");
}
if (command.isNSFW()) {
sB.append("Is nsfw: "+command.isNSFW());
}
if (command.getRequiredPermission() != null) {
sB.append("Required Permission: " + command.getRequiredPermission().getName() + "\n");
}
eB.addField("Usage:", "`" + command.getUsage(isDevEnabled) + "`", false);
if (command.getTimeout() > 0) {
sB.append("Usage Timeout: " + command.getTimeout() + "\n");
}
eB.addField("Page:", command.getHelpPage().toString(), true); // ("Page: " +
// command.getHelpPage().toString());
eB.setFooter(blob.getEvent().getMember().getEffectiveName(),
blob.getEvent().getMember().getUser().getEffectiveAvatarUrl());
eB.setTimestamp(Instant.now());
if (command.getCommandCalls().length > 1) {
sB.append("Aliases: ");
for (int i = 1; i < command.getCommandCalls().length; i++) {
sB.append("`" + command.getCommandCalls()[i] + "` ");
}
sB.append("\n");
}
sB.append("Premium: " + command.isPremium() + "\n");
eB.addField("Misc", sB.toString(), false);
blob.getChannel().sendMessageEmbeds(eB.build()).queue();
if (command.isNSFW()) {
sB.append("Is nsfw: " + command.isNSFW() + "\n");
}
if (command.getRequiredPermission() != null) {
sB.append("Required Permission: " + command.getRequiredPermission().getName() + "\n");
}
if (command.getTimeout() > 0) {
sB.append("Usage Timeout: " + command.getTimeout() + "\n");
}
sB.append(
"Premium: " + ((command.getPremiumLevel() < 1) ? "no" : command.getPremiumLevel()) + "\n");
if (!sB.isEmpty()) {
eB.addField("Misc", sB.toString(), false);
}
blob.getChannel().sendMessageEmbeds(eB.build()).queue();
} else {
blob.getChannel().sendMessage("Sorry, but you are not allowed to view information about that command here, try somewhere more private").queue();
blob.getChannel().sendMessage(
"Sorry, but you are not allowed to view information about that command here, try somewhere more private")
.queue();
}
} else {
// Tools.wrongUsage(blob.getChannel(), command);
@ -180,16 +179,6 @@ public class Help implements GuildCommandInterface {
return "The help command, it seems like you already know how to use it. . .";
}
@Override
public String getUsage() {
return Global.prefix + getCommandCalls()[0] + " [Command name]";
}
@Override
public String getCompleteUsage() {
return Global.prefix + getCommandCalls()[0] + " [Command name | -dev]";
}
@Override
public HashMap<String, Argument> getArguments() {
HashMap<String, Argument> args = new HashMap<String, Argument>();

View file

@ -0,0 +1,52 @@
package pkg.deepCurse.nopalmo.command.commands.info;
import java.util.HashMap;
import org.jetbrains.annotations.Nullable;
import pkg.deepCurse.nopalmo.command.CommandInterface.DirectCommandInterface;
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob;
import pkg.deepCurse.nopalmo.manager.DirectCommandBlob;
import pkg.deepCurse.nopalmo.manager.GuildCommandBlob;
public class Info implements GuildCommandInterface, DirectCommandInterface {
@Override
public String[] getCommandCalls() {
return new String[] { "info", "i" };
}
@Override
public HelpPage getHelpPage() {
return HelpPage.Info;
}
@Override
public String getHelp() {
return "A command for getting information in and out of the bot";
}
@Override
public @Nullable HashMap<String, Argument> getArguments() {
HashMap<String, Argument> args = new HashMap<String, Argument>();
args.put("userdump", new Argument("userdump", (CommandBlob blob) -> {
blob.getChannel().sendMessage(Users.dump(blob.getUserID())).queue();
}).setPrefixRequirement(true).setAutoStartRunnable(true)
.setSkipOriginalTaskOnRunnable(true));
return args;
}
@Override
public void runDirectCommand(DirectCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
}
@Override
public void runGuildCommand(GuildCommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
blob.getChannel().sendMessage("EEE").queue();
}
}

View file

@ -4,7 +4,6 @@ import java.util.HashMap;
import net.dv8tion.jda.api.entities.MessageChannel;
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob;
import pkg.deepCurse.nopalmo.utils.UptimePing;
@ -57,11 +56,6 @@ public class Ping implements DualCommandInterface {
return new String[] { "ping" };
}
@Override
public String getUsage() {
return Global.prefix + getCommandName()+" [" + Argument.argumentPrefix + "all]";
}
@Override
public HelpPage getHelpPage() {
return HelpPage.Info;

View file

@ -18,6 +18,7 @@ import pkg.deepCurse.nopalmo.listener.DirectMessageReceivedListener;
import pkg.deepCurse.nopalmo.listener.GuildMessageReceivedListener;
import pkg.deepCurse.nopalmo.manager.DirectCommandManager;
import pkg.deepCurse.nopalmo.manager.GuildCommandManager;
import pkg.deepCurse.nopalmo.manager.StatusManager;
import pkg.deepCurse.nopalmo.utils.Locks;
import pkg.deepCurse.nopalmo.utils.LogHelper;
@ -37,6 +38,16 @@ public class Boot {
public static void main(String[] args) {
LogHelper.boot("Booting: <" + pid + ">");
new Thread(() -> {
long count = 0;
while (true) {
if (count++ > 1000000000) {
count = 0;
System.out.println("owo");
}
}
}, "owo");
LogHelper.boot("Testing Lock. . .");
try {
@ -108,7 +119,7 @@ public class Boot {
.setEnableShutdownHook(true)
.build();
.build().awaitReady();
} catch (Exception e) {
LogHelper.crash(e);
@ -117,12 +128,16 @@ public class Boot {
bot.getPresence().setStatus(OnlineStatus.ONLINE);
bot.getPresence().setActivity(Activity.listening("Infected Mushroom"));
LogHelper.boot("Init status list");
StatusManager.init();
LogHelper.boot("Initialized status list. . .");
long bootTime = System.currentTimeMillis() - preBootTime;
LogHelper.boot("Taken " + bootTime + "ms to boot");
// LogHelper.boot("Starting loop");
// loop();
LogHelper.boot("Starting loop");
loop();
}
private static void loop() {
@ -132,38 +147,42 @@ public class Boot {
long fiveMins = lastTime;
long threeMins = lastTime;
long lastTimeUpdateStatus = lastTime;
long lastTimeCheckUpdate= lastTime;
long dynamicWait = 0;
long lastTimeCheckUpdate = lastTime;
long dynamicWait = Global.getDynamicWait();
while (running) {
long now = System.currentTimeMillis();
if (now > lastTime + dynamicWait) { // dynamic wait loop
lastTime = now;
}
if (now > lastTimeCheckUpdate + 900000) {
lastTimeCheckUpdate = now;
}
if (now > lastTimeUpdateStatus + dynamicWait && Global.isShuffleStatusEnabled()) {
lastTimeUpdateStatus = now;
StatusManager.shuffle(bot);
}
if (now > fifteenMins + 900000) {
fifteenMins = now;
}
if (now > fiveMins + 300000) {
fiveMins = now;
}
if (now > threeMins + 180000) {
threeMins = now;
}
}
}

View file

@ -4,6 +4,7 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
@ -57,6 +58,89 @@ public class DatabaseTools {
// these sub classes will represent tables and the methods therein will be for
// actions within said table
public class Users {
public static int getPremiumLevel(long userID) {
Statement st = null;
ResultSet rs = null;
String query = "select * from users where userid = " + userID;
try {
st = connection.createStatement();
rs = st.executeQuery(query);
if (rs.next()) {
return rs.getInt("premiumlevel");
} else {
// throw new SQLException(null, null, 33); // we need a real catcher here
System.err
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
return 0;
}
} catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode());
return 0;
} finally { // @formatter:off
try {if (rs != null)rs.close();} catch (Exception e) {}
try {if (st != null)st.close();} catch (Exception e) {}
// @formatter:on
}
}
public static boolean isAdvancedUser(long userID) {
Statement st = null;
ResultSet rs = null;
String query = "select * from users where userid = " + userID;
try {
st = connection.createStatement();
rs = st.executeQuery(query);
if (rs.next()) {
return rs.getBoolean("advanceduser");
} else {
// throw new SQLException(null, null, 33); // we need a real catcher here
System.err
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
return false;
}
} catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode());
return false;
} finally { // @formatter:off
try {if (rs != null)rs.close();} catch (Exception e) {}
try {if (st != null)st.close();} catch (Exception e) {}
// @formatter:on
}
}
public static String dump(long userID) {
Statement st = null;
ResultSet rs = null;
String query = "select * from users where userid = " + userID;
try {
st = connection.createStatement();
rs = st.executeQuery(query);
ResultSetMetaData rsMeta = rs.getMetaData();
int columnCount = rsMeta.getColumnCount();
StringBuilder sB = new StringBuilder();
while (rs.next()) {
// Object[] values = new Object[columnCount];
for (int i = 1; i <= columnCount; i++) {
// values[i - 1] = resultSet.getObject(i);
sB.append(rsMeta.getColumnLabel(i) + ": " + rs.getString(i) + "\n");
}
}
return sB.toString();
} catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode());
return null;
} finally { // @formatter:off
try {if (rs != null)rs.close();} catch (Exception e) {}
try {if (st != null)st.close();} catch (Exception e) {}
// @formatter:on
}
}
}
public class Guild {
public class Prefix {
@ -199,7 +283,7 @@ public class DatabaseTools {
}
// return null;
}
public static String getDeveloperString(long userID, String key) {
Statement st = null;
ResultSet rs = null;
@ -237,7 +321,7 @@ public class DatabaseTools {
}
// return null;
}
public static boolean canPowerOffBot(long userID) {
return getDeveloperBoolean(userID, "canPowerOffBot");
}
@ -296,8 +380,114 @@ public class DatabaseTools {
}
public static boolean isShuffleStatusEnabled() {
return false;
Statement st = null;
ResultSet rs = null;
String query = "select * from global where id = 'isshufflestatusenabled'";
try {
st = connection.createStatement();
rs = st.executeQuery(query);
if (rs.next()) {
return rs.getString("value").contentEquals("true");
} else {
System.err
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
return false;
}
} catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode());
// System.out.println("eeeeee");
return false;
} finally {
try {
if (rs != null)
rs.close();
} catch (Exception e) {
}
try {
if (st != null)
st.close();
} catch (Exception e) {
}
// try { if (conn != null) conn.close(); } catch (Exception e) {};
}
// return null;
}
public static int getDynamicWait() {
Statement st = null;
ResultSet rs = null;
String query = "select * from global where id = 'dynamicwait'";
try {
st = connection.createStatement();
rs = st.executeQuery(query);
if (rs.next()) {
return rs.getInt("value");
} else {
System.err
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
return 45000;
}
} catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode());
// System.out.println("eeeeee");
return 45000;
} finally {
try {
if (rs != null)
rs.close();
} catch (Exception e) {
}
try {
if (st != null)
st.close();
} catch (Exception e) {
}
// try { if (conn != null) conn.close(); } catch (Exception e) {};
}
// return null;
}
public static int getEmbedColor() {
Statement st = null;
ResultSet rs = null;
String query = "select * from global where id = 'embedcolor'";
try {
st = connection.createStatement();
rs = st.executeQuery(query);
if (rs.next()) {
return rs.getInt("value");
} else {
System.err
.println("Failed to execute; errorCode=NO_ROW_FOUND; No row found; On action " + query);
return 0;
}
} catch (SQLException e) {
SQLCode.getMessage(query, e.getErrorCode());
// System.out.println("eeeeee");
return 0;
} finally {
try {
if (rs != null)
rs.close();
} catch (Exception e) {
}
try {
if (st != null)
st.close();
} catch (Exception e) {
}
// try { if (conn != null) conn.close(); } catch (Exception e) {};
}
// return null;
}
}

View file

@ -6,11 +6,11 @@ import pkg.deepCurse.nopalmo.command.CommandInterface;
public class Tools {
public static void wrongUsage(MessageChannel messageChannel, CommandInterface command) {
messageChannel.sendMessage("Wrong Command Usage!\n" + command.getUsage()).queue();
messageChannel.sendMessage("Wrong Command Usage!\n" + command.getUsage(false)).queue();
}
public static void invalidPermissions(MessageChannel messageChannel, CommandInterface command) {
messageChannel.sendMessage("Sorry, but you are not allowed to use that! Try this:\n" + command.getUsage()).queue();
messageChannel.sendMessage("Sorry, but you are not allowed to use that! Try this:\n" + command.getUsage(false)).queue();
}
// public static void wrongUsage(MessageChannel tc, DirectCommandInterface c) {

View file

@ -21,13 +21,15 @@ public class Argument {
private String argName = null;
private Argument[] subArgs = null;
private boolean requiresPrefix = false;
private Boolean isWildcard;
private Boolean isWildcard = false;
private int position = -1;
private String wildCardString = null;
private boolean autoStartRunnable = false;
private boolean skipOriginalTaskOnRunnable = false;
private RunnableArg runnableArg = null;
private String permissionLevel;
private String permissionLevel = null;
private boolean isRequired = false;
private boolean isDeveloper = false;
public static final String argumentPrefix = "-"; // This exists for the sole reason of customization and will
// generally not change, ever, its recommended you keep it to
@ -148,7 +150,7 @@ public class Argument {
}
public interface RunnableArg {
public void run(CommandBlob blob);
}
@ -186,6 +188,7 @@ public class Argument {
public Argument setPermissionLevel(String string) {
this.permissionLevel = string;
this.isDeveloper = true;
return this;
}
@ -193,4 +196,22 @@ public class Argument {
return this.permissionLevel;
}
public boolean isRequired() {
return this.isRequired;
}
public Argument setIsRequired(boolean bool) {
this.isRequired = bool;
return this;
}
public boolean isDeveloper() {
return isDeveloper;
}
public Argument setDeveloper(boolean isDeveloper) {
this.isDeveloper = isDeveloper;
return this;
}
}

View file

@ -26,7 +26,7 @@ public class DirectCommandManager extends CommandManager {
public DirectCommandManager() {
init();
executor = Executors.newSingleThreadExecutor();
executor = Executors.newCachedThreadPool();
}
public void init() {

View file

@ -14,14 +14,15 @@ import java.util.regex.Pattern;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import pkg.deepCurse.nopalmo.command.CommandInterface.GuildCommandInterface;
import pkg.deepCurse.nopalmo.command.commands.general.Example;
import pkg.deepCurse.nopalmo.command.commands.general.Prefix;
import pkg.deepCurse.nopalmo.command.commands.general.Test;
import pkg.deepCurse.nopalmo.command.commands.info.Git;
import pkg.deepCurse.nopalmo.command.commands.info.Help;
import pkg.deepCurse.nopalmo.command.commands.info.Info;
import pkg.deepCurse.nopalmo.command.commands.info.Ping;
import pkg.deepCurse.nopalmo.core.Boot;
import pkg.deepCurse.nopalmo.database.DatabaseTools;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Users;
import pkg.deepCurse.nopalmo.global.Tools;
public class GuildCommandManager extends CommandManager {
@ -31,7 +32,7 @@ public class GuildCommandManager extends CommandManager {
public GuildCommandManager() {
init();
executor = Executors.newSingleThreadExecutor();
executor = Executors.newWorkStealingPool();// newCachedThreadPool();
}
public void init() {
@ -40,7 +41,7 @@ public class GuildCommandManager extends CommandManager {
addCommand(new Git());
addCommand(new Prefix());
addCommand(new Test());
addCommand(new Example());
addCommand(new Info());
}
private void addCommand(GuildCommandInterface c) {
@ -100,7 +101,6 @@ public class GuildCommandManager extends CommandManager {
boolean printTime = false;
byte argSkipCount = 0;
boolean remainsValid = true;
// int id = 0;
HashMap<Integer, Argument> positionalArgs = new HashMap<Integer, Argument>();
@ -109,11 +109,6 @@ public class GuildCommandManager extends CommandManager {
if (i.getPosition() >= 0) {
positionalArgs.put(i.getPosition(), i);
}
if (i.isSkipOriginalTaskOnRunnable()) {
remainsValid = false;
}
}
}
@ -154,6 +149,9 @@ public class GuildCommandManager extends CommandManager {
if (guildCommand.getArguments().get(pre).getPermission() == null
|| DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
guildCommand.getArguments().get(pre).getPermission())) {
if (guildCommand.getArguments().get(pre).isSkipOriginalTaskOnRunnable()) {
remainsValid = false;
}
argumentList.put(pre, guildCommand.getArguments().get(pre));
if (guildCommand.getArguments().get(pre).isAutoStartRunnable()
&& guildCommand.getArguments().get(pre).getRunnableArg() != null) {
@ -174,6 +172,9 @@ public class GuildCommandManager extends CommandManager {
if (guildCommand.getArguments().get(x).getPermission() == null
|| DatabaseTools.Tools.Developers.hasPermission(commandBlob.getUserID(),
guildCommand.getArguments().get(x).getPermission())) {
if (guildCommand.getArguments().get(x).isSkipOriginalTaskOnRunnable()) {
remainsValid = false;
}
argumentList.put(x, guildCommand.getArguments().get(x));
offset++;
if (guildCommand.getArguments().get(x).isAutoStartRunnable()
@ -191,6 +192,9 @@ public class GuildCommandManager extends CommandManager {
|| DatabaseTools.Tools.Developers.hasPermission(
commandBlob.getUserID(),
positionalArgs.get(i - offset).getPermission())) {
if (positionalArgs.get(i - offset).isSkipOriginalTaskOnRunnable()) {
remainsValid = false;
}
if (positionalArgs.get(i - offset).getIsWildcard()) {
argumentList.put(positionalArgs.get(i - offset).getArgName(),
positionalArgs.get(i - offset).setWildCardString(x));
@ -220,6 +224,21 @@ public class GuildCommandManager extends CommandManager {
}
if (guildCommand.isNSFW() && !commandBlob.getChannel().isNSFW()) {
commandBlob.getChannel().sendMessage(
"Sorry, but you cannot run this command here, maybe try somewhere more private?")
.queue();
remainsValid = false;
}
if (guildCommand.getPremiumLevel() > Users.getPremiumLevel(commandBlob.getUserID())) {
commandBlob.getChannel().sendMessage(
"Sorry, but you cannot run this command, it is premium subs only, of at least tier "
+ guildCommand.getPremiumLevel())
.queue();
remainsValid = false;
}
commandBlob.setCommandManager(this);
if (remainsValid) {

View file

@ -0,0 +1,45 @@
package pkg.deepCurse.nopalmo.manager;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Activity;
import pkg.deepCurse.nopalmo.core.Boot;
import pkg.deepCurse.nopalmo.database.DatabaseTools.Tools.Global;
public class StatusManager {
private static List<Activity> activityList = new ArrayList<Activity>();
private static int selection = 0;
public static void init() {
activityList.add(Activity.watching("my lead developer eat a watermelon whole"));
activityList.add(Activity.watching(
Boot.bot.getUserCache().asList().size() + " users in " + Boot.bot.getGuilds().size() + " servers"));
activityList.add(Activity.watching("for " + Global.prefix+ "help"));
activityList.add(Activity.competing("your mothers love"));
}
public static void shuffle(JDA bot) {
int rand = new Random().nextInt(activityList.size());
bot.getPresence().setActivity(activityList.get(rand));
selection = rand;
}
public static void set(JDA bot, int interger) {
bot.getPresence().setActivity(activityList.get(interger));
selection = interger;
}
public static void increment(JDA bot) {
bot.getPresence().setActivity(activityList.get(selection > activityList.size() ? selection = 0 : ++selection));
}
}