some shit

Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
lever1209 2021-12-13 17:06:27 -04:00
commit bf1d67fb48
No known key found for this signature in database
GPG key ID: EEBCBB60C9DFC782
15 changed files with 434 additions and 198 deletions

View file

@ -1,15 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="/libs-java/db/mysql-connector-java-8.0.27.jar" sourcepath="/libs-java/db/mysql-connector-java-8.0.27-sources.jar"/>
<classpathentry kind="lib" path="/libs-java/discord/JDA-4.4.0_350-withDependencies.jar" sourcepath="/libs-java/discord/JDA-4.4.0_350-sources.jar"/>
<classpathentry kind="lib" path="/libs-java/logging/slf4j-api-1.7.9.jar" sourcepath="/libs-java/logging/slf4j-api-1.7.9-sources.jar"/>
<classpathentry kind="lib" path="/libs-java/logging/slf4j-simple-1.7.9.jar" sourcepath="/libs-java/logging/slf4j-simple-1.7.9-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes> <attributes>
<attribute name="module" value="true"/> <attribute name="module" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="/libs-java/db/mysql-connector-java-8.0.27.jar" sourcepath="/libs-java/db/mysql-connector-java-8.0.27-sources.jar"/> <classpathentry combineaccessrules="false" kind="src" path="/bontebok"/>
<classpathentry kind="lib" path="/libs-java/discord/JDA-4.4.0_350-withDependencies.jar" sourcepath="/libs-java/discord/JDA-4.4.0_350-sources.jar"/>
<classpathentry kind="lib" path="/libs-java/logging/slf4j-api-1.7.9.jar" sourcepath="/libs-java/logging/slf4j-api-1.7.9-sources.jar"/>
<classpathentry kind="lib" path="/libs-java/logging/slf4j-simple-1.7.9.jar" sourcepath="/libs-java/logging/slf4j-simple-1.7.9-sources.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/phoenix-runtime"/> <classpathentry combineaccessrules="false" kind="src" path="/phoenix-runtime"/>
<classpathentry combineaccessrules="false" kind="src" path="/libs-java"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
/bin/ /bin/
/nopalmo.lock /nopalmo.lock
/.classpath
/.project

View file

@ -1,4 +1,5 @@
mix command managers // DONE mix command managers
finish loop finish loop
add socket server for better management / integration // DONE add socket server for better management / integration
implement pheonix in a smarter way than last time // DONE implement pheonix in a smarter way than last time
add better security to the socket server

View file

@ -36,21 +36,32 @@ public interface CommandInterface { // TODO rewrite to implement type args?
public String getHelp(); public String getHelp();
public default String getUsage(boolean hasPermissionInfo) { public default String getUsage(boolean hasPermissionInfo) {
StringBuilder sB = new StringBuilder(); StringBuilder sB = new StringBuilder();
if (getArguments() != null) { for (Argument i : getArguments().values()) {
for (Argument i : getArguments().values()) { if ((i.isDeveloper() && hasPermissionInfo) || !i.isDeveloper()) {
if (!i.isDeveloper() || (hasPermissionInfo && i.isDeveloper())) { if (i.isRequired()) {
sB.append(i.isRequired() ? "<" : "["); sB.append("<");
if (i.getPrefixRequirement()) { } else {
sB.append(Argument.argumentPrefix); sB.append("[");
}
sB.append((i.isPrefixRequired() ? Argument.argumentPrefix : "")+i.getArgName());
if (i.getAliases() != null) {
for (String j : i.getAliases()) {
sB.append(" | " + (i.isPrefixRequired() ? Argument.argumentPrefix : "") + j);
} }
sB.append(i.getArgName() + (i.isRequired() ? "> " : "] ")); }
if (i.isRequired()) {
sB.append("> ");
} else {
sB.append("] ");
} }
} }
} }
return (Global.prefix + getCommandName() + " " + sB.toString()).strip(); return Global.prefix + getCommandName() + " " + sB.toString().trim();
} }
public default int getTimeout() { public default int getTimeout() {
@ -93,3 +104,41 @@ public interface CommandInterface { // TODO rewrite to implement type args?
} }
} }
/*
*
*
* StringBuilder sB = new StringBuilder(); if (getArguments() != null) { for
* (String i : getArguments().keySet()) { // sB.delete(0, sB.length()); if
* (!getArguments().get(i).isDeveloper() || (hasPermissionInfo &&
* getArguments().get(i).isDeveloper())) {
* sB.append(getArguments().get(i).isRequired() ? "<" : "[");
*
* sB.append((getArguments().get(i).isPrefixRequired() ?
* sB.append(Argument.argumentPrefix) : ""));
*
* sB.append(i); // System.out.println("01"+sB.toString()); // for (int j = 0; j
* < getArguments().get(i).getAliases().size(); j++) { // sB.append((j <
* getArguments().get(i).getAliases().size() ? " | " : "") // +
* (getArguments().get(i).isPrefixRequired() ?
* sB.append(Argument.argumentPrefix) : "") // +
* getArguments().get(i).getAliases().get(j)); //
* System.out.println("02"+sB.toString()); // }
* sB.append(getArguments().get(i).isRequired() ? "> " : "] ");
* System.out.println("[000] :\t"+sB.toString()); } } }
*
* System.out.println("[001] :\t"+sB.toString()); return (Global.prefix +
* getCommandName() + " " + sB.toString()).strip();
*
* //StringBuilder sB = new StringBuilder(); //if (getArguments() != null) { //
* for (String i : getArguments().keySet()) { // if
* (!getArguments().get(i).isDeveloper() // || (hasPermissionInfo &&
* getArguments().get(i).isDeveloper())) { //
* sB.append(getArguments().get(i).isRequired() ? "<" : "["); // if
* (getArguments().get(i).isPrefixRequired()) { //
* sB.append(Argument.argumentPrefix); // } // sB.append(i); // for (int j = 0;
* j < getArguments().get(i).getAliases().size(); j++) { // sB.append((j <
* getArguments().get(i).getAliases().size() ? " | " : "") // +
* getArguments().get(i).getAliases().get(j)); // } //
* sB.append(getArguments().get(i).isRequired() ? "> " : "] "); // } // } //} //
* //return (Global.prefix + getCommandName() + " " + sB.toString()).strip();
*/

View file

@ -32,6 +32,7 @@ public class Git implements DualCommandInterface {
blob.getChannel() blob.getChannel()
.sendMessage("This is the automatically running argument inside of " + this.getCommandName()) .sendMessage("This is the automatically running argument inside of " + this.getCommandName())
.queue(); .queue();
// blob.getCommandManager().init();
}).setPrefixRequirement(true).setAutoStartRunnable(true).setDeveloper(true)); }).setPrefixRequirement(true).setAutoStartRunnable(true).setDeveloper(true));

View file

@ -32,43 +32,80 @@ public class Help implements GuildCommandInterface {
deniedPages.add(HelpPage.EGG); deniedPages.add(HelpPage.EGG);
deniedPages.add(HelpPage.TESTING); deniedPages.add(HelpPage.TESTING);
if (argumentMap.isEmpty() || (isDevEnabled && argumentMap.size() == 1)) { if (argumentMap.get("commandName") == null) {
EmbedBuilder embed = new EmbedBuilder().setTitle(isDevEnabled ? "^Commands:" : "Commands:"); EmbedBuilder embed = new EmbedBuilder().setTitle(isDevEnabled ? "^Commands:" : "Commands:");
HashMap<HelpPage, List<String>> commandHash = new HashMap<HelpPage, List<String>>(); HashMap<HelpPage, ArrayList<String>> commandHash = new HashMap<HelpPage, ArrayList<String>>();
for (CommandInterface command : manager.getCommands()) { // TODO yet another rewrite
List<String> commandNameList = commandHash.get(command.getHelpPage()); // TODO add command to log a string
if (commandNameList == null) {
commandNameList = new ArrayList<String>();
}
commandNameList.add(command.getCommandName());
commandHash.put(command.getHelpPage(), commandNameList);
}
for (HelpPage i : HelpPage.values()) { for (HelpPage i : HelpPage.values()) {
if (deniedPages.contains(i) && argumentMap.get("dev") == null) { ArrayList<String> commandNameList = commandHash.get(i);
for (CommandInterface command : manager.getCommands()) {
if (!(deniedPages.contains(i) && argumentMap.get("dev") == null)) {
if (command.getHelpPage() == i) {
if (commandNameList == null) {
commandNameList = new ArrayList<String>();
}
} else if (commandHash.get(i) != null) { if (!commandNameList.contains(command.getCommandName())) {
commandNameList.add(command.getCommandName());
commandHash.put(command.getHelpPage(), commandNameList);
}
}
}
}
commandNameList = null;
}
// blob.getChannel().sendMessage(commandHash.toString()).queue();
for (HelpPage i : HelpPage.values()) {
if (commandHash.get(i) != null) {
StringBuilder sB = new StringBuilder(); StringBuilder sB = new StringBuilder();
int count = 0; int count = 0;
for (String j : commandHash.get(i)) { for (String j : commandHash.get(i)) {
if (++count > 3) { if (count >= 3) {
sB.append("\n");
count = 0; count = 0;
sB.append("\n");
} }
count++;
sB.append("`" + j + "` "); sB.append("`" + j + "` ");
} }
embed.addField(i.toString(), sB.toString(), true); embed.addField(i.toString(), sB.toString(), true);
} }
} }
// for () {
//
// }
// for (HelpPage i : HelpPage.values()) {
// if (deniedPages.contains(i) && argumentMap.get("dev") == null) {
//
// } else if (commandHash.get(i) != null) {
//
// StringBuilder sB = new StringBuilder();
//
// int count = 0;
// for (String j : commandHash.get(i)) {
// if (++count > 3) {
// count = 0;
// sB.append("\n");
// }
// sB.append("`" + j + "` ");
// }
//
// embed.addField(i.toString(), sB.toString(), true);
//
// }
//
// }
StringBuilder sB = new StringBuilder(); StringBuilder sB = new StringBuilder();
CommandInterface ping = blob.getCommandManager().getCommand("ping"); CommandInterface ping = blob.getCommandManager().getCommand("ping");
@ -184,7 +221,8 @@ public class Help implements GuildCommandInterface {
HashMap<String, Argument> args = new HashMap<String, Argument>(); HashMap<String, Argument> args = new HashMap<String, Argument>();
args.put("commandName", new Argument("commandName").setPosition(0).setIsWildcard(true)); args.put("commandName", new Argument("commandName").setPosition(0).setIsWildcard(true));
args.put("dev", new Argument("dev").setPrefixRequirement(true).setPermissionLevel("infopermission")); args.put("dev", new Argument("dev").setPrefixRequirement(true).setPermissionLevel("infopermission")
.addAliases("d", "developer", "extra", "shit", "to", "test"));
return args; return args;
} }

View file

@ -30,11 +30,12 @@ public class Info implements GuildCommandInterface, PrivateCommandInterface {
@Override @Override
public @Nullable HashMap<String, Argument> getArguments() { public @Nullable HashMap<String, Argument> getArguments() {
HashMap<String, Argument> args = new HashMap<String, Argument>(); HashMap<String, Argument> args = new HashMap<String, Argument>();
args.put("userdump", new Argument("userdump", (CommandBlob blob) -> { args.put("userdump", new Argument("userdump", (CommandBlob blob) -> {
blob.getChannel().sendMessage(Users.dump(blob.getAuthorID())).queue(); blob.getChannel().sendMessage(!Users.dump(blob.getAuthorID()).isEmpty() ? Users.dump(blob.getAuthorID())
}).setPrefixRequirement(true).setAutoStartRunnable(true).setSkipOriginalTaskOnRunnable(true)); : "Sorry, but this user does not exist in the database").queue();
}).setPrefixRequirement(true).setAutoStartRunnable(true).setSkipOriginalTaskOnRunnable(true).addAliases("u"));
return args; return args;
} }
@ -44,6 +45,6 @@ public class Info implements GuildCommandInterface, PrivateCommandInterface {
@Override @Override
public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception { public void runGuildCommand(CommandBlob blob, HashMap<String, Argument> argumentList) throws Exception {
blob.getChannel().sendMessage("EEE").queue(); blob.getChannel().sendMessage("This command is used to send data stored in the database to whoever is authorized to view it, to view your own data, use `"+getCommandName()+" -userdump`").queue();
} }
} }

View file

@ -0,0 +1,38 @@
package pkg.deepCurse.nopalmo.command.commands.info;
import java.util.HashMap;
import org.jetbrains.annotations.Nullable;
import pkg.deepCurse.nopalmo.command.CommandInterface.DualCommandInterface;
import pkg.deepCurse.nopalmo.manager.Argument;
import pkg.deepCurse.nopalmo.manager.CommandBlob;
public class Reload implements DualCommandInterface {
@Override
public String[] getCommandCalls() {
return new String[] {"reload"};
}
@Override
public HelpPage getHelpPage() {
return HelpPage.DEV;
}
@Override
public String getHelp() {
return "you should not need help using this command";
}
@Override
public @Nullable HashMap<String, Argument> getArguments() {
return null;
}
@Override
public void runDualCommand(CommandBlob blob, HashMap<String, Argument> argumentMap) throws Exception {
blob.getCommandManager().init();
}
}

View file

@ -1,6 +1,10 @@
package pkg.deepCurse.nopalmo.core; package pkg.deepCurse.nopalmo.core;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
@ -17,16 +21,17 @@ import pkg.deepCurse.nopalmo.global.Reactions;
import pkg.deepCurse.nopalmo.listener.MessageReceivedListener; import pkg.deepCurse.nopalmo.listener.MessageReceivedListener;
import pkg.deepCurse.nopalmo.manager.CommandManager; import pkg.deepCurse.nopalmo.manager.CommandManager;
import pkg.deepCurse.nopalmo.manager.StatusManager; import pkg.deepCurse.nopalmo.manager.StatusManager;
import pkg.deepCurse.nopalmo.utils.Locks; import pkg.deepCurse.nopalmo.server.socket.Socks;
import pkg.deepCurse.nopalmo.utils.LogHelper; import pkg.deepCurse.nopalmo.utils.LogHelper;
import pkg.deepCurse.phoenixRuntime.core.PhoenixCommandManager;
import pkg.deepCurse.phoenixRuntime.core.PhoenixInterface;
import pkg.deepCurse.phoenixRuntime.core.PhoenixRuntime;
import pkg.deepCurse.phoenixRuntime.core.PhoenixSettings;
public class Boot { public class Boot {
public static JDA bot; // TODO create sharding handler public static JDA bot; // TODO create sharding handler
public static DatabaseTools databaseTools = null; public static DatabaseTools databaseTools = null;
// public static final GuildCommandManager guildCommandManager = new GuildCommandManager(); // move to master manager
// public static final DirectCommandManager directCommandManager = new DirectCommandManager(); // move to master
// // manager
public static boolean isProd = false; public static boolean isProd = false;
@ -35,155 +40,194 @@ public class Boot {
public static final CommandManager commandManager = new CommandManager(); public static final CommandManager commandManager = new CommandManager();
public static void main(String[] args) { public static void main(String[] args) {
LogHelper.boot("Booting: <" + pid + ">");
new Thread(() -> { PhoenixSettings settings = new PhoenixSettings().setAuthentication(args[3]).setCommandSplitRegex(", ").setCommandManager(new PhoenixCommandManager());
long count = 0;
while (true) { // TODO using join and a while last time + 15000 < current time, then kill and proceed as a failure
if (count++ > 1000000000) {
count = 0; settings.commandManager.addCommand("phoenix-update", (PhoenixRuntime runtime, List<String> commandArgs) -> {
System.out.println("owo"); System.out.println("Received <phoenix-update>");
Socks.sendStringSock(settings.address, settings.commonPort, "phoenix-update-confirm");
System.out.println("Sent <phoenix-update-confirm>");
if (bot != null) {
bot.shutdown();
}
runtime.shutdown(9);
});
// settings.actions.put("phoenix-update-confirm", (PhoenixRuntime runtime) -> {
// System.out.println("Received <phoenix-update-confirm>");
// });
PhoenixRuntime runtime = new PhoenixRuntime(settings, new PhoenixInterface() {
@Override
public void boot() {
LogHelper.boot("Booting: <" + pid + ">");
long preBootTime = System.currentTimeMillis();
isProd = args[2].contentEquals("prod");
LogHelper.boot("Connecting to mariadb:nopalmo");
try {
databaseTools = new DatabaseTools(args[1]);
LogHelper.boot("Connected. . .");
} catch (SQLException | ClassNotFoundException e1) {
e1.printStackTrace();
LogHelper.boot("Failed to connect\nShutting down. . .");
System.exit(4);
}
LogHelper.boot("Init reaction/emote list");
Reactions.init();
LogHelper.boot("Initialized reaction/emote list. . .");
LogHelper.boot("Init commands list");
commandManager.init();
LogHelper.boot("Initialized commands list. . .");
try {
// bot = JDABuilder.createDefault(args[0]).setChunkingFilter(ChunkingFilter.ALL)
// .setMemberCachePolicy(MemberCachePolicy.ALL).enableIntents(GatewayIntent.GUILD_MEMBERS)
// .setActivity(Activity.watching("Loading users...")).setIdle(true)
// .addEventListeners(new GuildMessageReceivedListener())
// .addEventListeners(new DirectMessageReceivedListener()).build().awaitReady();
bot = JDABuilder.createDefault(args[0])
.setActivity(Activity.of(ActivityType.WATCHING, "the loading bar. . ."))
.setStatus(OnlineStatus.DO_NOT_DISTURB)
.setMaxBufferSize(Integer.MAX_VALUE)
.setChunkingFilter(ChunkingFilter.ALL).setMemberCachePolicy(MemberCachePolicy.ALL)
.enableIntents(GatewayIntent.DIRECT_MESSAGE_REACTIONS,
GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS,
GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS,
GatewayIntent.GUILD_MESSAGES // , GatewayIntent.GUILD_VOICE_STATES
)
.enableCache(// CacheFlag.CLIENT_STATUS,
CacheFlag.EMOTE, // CacheFlag.ACTIVITY,
CacheFlag.MEMBER_OVERRIDES // , CacheFlag.VOICE_STATE
)
// .setIdle(true)
.setAutoReconnect(true)
// .addEventListeners(new GuildMessageReceivedListener())
// .addEventListeners(new DirectMessageReceivedListener())
.addEventListeners(new MessageReceivedListener())
.setEnableShutdownHook(true)
.build().awaitReady();
} catch (Exception e) {
LogHelper.crash(e);
}
LogHelper.boot("Using account: " + bot.getSelfUser().getName());
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();
}
public void loop() {
long lastTime = System.currentTimeMillis();
long fifteenMins = lastTime;
long fiveMins = lastTime;
long threeMins = lastTime;
long lastTimeUpdateStatus = lastTime;
long lastTimeCheckUpdate = lastTime;
long dynamicWait = Global.getDynamicWait();
while (running) {
long now = System.currentTimeMillis();
if (now > lastTime + dynamicWait) { // dynamic wait loop
lastTime = now;
try {
bot.getSelfUser();
} catch (Exception e) {
e.printStackTrace();
}
}
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;
}
} }
} }
}, "owo"); });
LogHelper.boot("Testing Lock. . ."); runtime.setLockedRunnable(() -> {
System.out.println("System is locked\nSending <phoenix-update> instead. . . ");
try {
if (Locks.dirLock("nopalmo.lock")) {
LogHelper.boot("Failed to lock. . .\nShutting down. . .");
System.exit(3); try {
} else { Socket cSocket = new Socket("127.0.0.1", settings.commonPort);
LogHelper.boot("Nopalmo is locked. . ."); DataOutputStream dOut = new DataOutputStream(cSocket.getOutputStream());
dOut.writeUTF("phoenix-update");
dOut.flush();
dOut.close();
cSocket.close();
} catch (IOException e) {
e.printStackTrace();
} }
} catch (Exception e) {
LogHelper.crash(e);
}
// settings.getRuntime().shutdown(0);
});
long preBootTime = System.currentTimeMillis(); runtime.launch();
isProd = args[2].contentEquals("prod");
LogHelper.boot("Connecting to mariadb:nopalmo");
try {
databaseTools = new DatabaseTools(args[1]);
LogHelper.boot("Connected. . .");
} catch (SQLException | ClassNotFoundException e1) {
e1.printStackTrace();
LogHelper.boot("Failed to connect\nShutting down. . .");
System.exit(4);
}
LogHelper.boot("Init reaction/emote list");
Reactions.init();
LogHelper.boot("Initialized reaction/emote list. . .");
LogHelper.boot("Init commands list");
commandManager.init();
LogHelper.boot("Initialized commands list. . .");
try {
// bot = JDABuilder.createDefault(args[0]).setChunkingFilter(ChunkingFilter.ALL)
// .setMemberCachePolicy(MemberCachePolicy.ALL).enableIntents(GatewayIntent.GUILD_MEMBERS)
// .setActivity(Activity.watching("Loading users...")).setIdle(true)
// .addEventListeners(new GuildMessageReceivedListener())
// .addEventListeners(new DirectMessageReceivedListener()).build().awaitReady();
bot = JDABuilder.createDefault(args[0])
.setActivity(Activity.of(ActivityType.WATCHING, "the loading bar. . ."))
.setStatus(OnlineStatus.DO_NOT_DISTURB)
.setMaxBufferSize(Integer.MAX_VALUE)
.setChunkingFilter(ChunkingFilter.ALL).setMemberCachePolicy(MemberCachePolicy.ALL)
.enableIntents(GatewayIntent.DIRECT_MESSAGE_REACTIONS,
GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS,
GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS,
GatewayIntent.GUILD_MESSAGES // , GatewayIntent.GUILD_VOICE_STATES
)
.enableCache(// CacheFlag.CLIENT_STATUS,
CacheFlag.EMOTE, // CacheFlag.ACTIVITY,
CacheFlag.MEMBER_OVERRIDES // , CacheFlag.VOICE_STATE
)
// .setIdle(true)
.setAutoReconnect(true)
// .addEventListeners(new GuildMessageReceivedListener())
// .addEventListeners(new DirectMessageReceivedListener())
.addEventListeners(new MessageReceivedListener())
.setEnableShutdownHook(true)
.build().awaitReady();
} catch (Exception e) {
LogHelper.crash(e);
}
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();
} }
private static void loop() {
long lastTime = System.currentTimeMillis();
long fifteenMins = lastTime;
long fiveMins = lastTime;
long threeMins = lastTime;
long lastTimeUpdateStatus = lastTime;
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

@ -139,6 +139,10 @@ public class DatabaseTools {
} }
} }
public static void addUser(long idLong) {
}
} }
public class Guild { public class Guild {

View file

@ -0,0 +1,14 @@
package pkg.deepCurse.nopalmo.database;
import java.util.HashMap;
public class RamDisk {
public static HashMap<String, Boolean> bools = new HashMap<String, Boolean>();
// public static
public static void init() {
bools.put("shouldRun", true);
}
}

View file

@ -1,5 +1,8 @@
package pkg.deepCurse.nopalmo.manager; package pkg.deepCurse.nopalmo.manager;
import java.util.ArrayList;
import java.util.List;
public class Argument { public class Argument {
// README // README
@ -30,6 +33,7 @@ public class Argument {
private String permissionLevel = null; private String permissionLevel = null;
private boolean isRequired = false; private boolean isRequired = false;
private boolean isDeveloper = false; private boolean isDeveloper = false;
private List<String> aliases = new ArrayList<String>();
public static final String argumentPrefix = "-"; // This exists for the sole reason of customization and will 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 // generally not change, ever, its recommended you keep it to
@ -136,7 +140,7 @@ public class Argument {
return isWildcard; return isWildcard;
} }
public boolean getPrefixRequirement() { public boolean isPrefixRequired() {
return this.requiresPrefix; return this.requiresPrefix;
} }
@ -214,4 +218,15 @@ public class Argument {
return this; return this;
} }
public Argument addAliases(String... alias) {
for (String i : alias) {
this.aliases.add(i);
}
return this;
}
public List<String> getAliases() {
return this.aliases;
}
} }

View file

@ -24,6 +24,7 @@ import pkg.deepCurse.nopalmo.command.commands.info.Git;
import pkg.deepCurse.nopalmo.command.commands.info.Help; import pkg.deepCurse.nopalmo.command.commands.info.Help;
import pkg.deepCurse.nopalmo.command.commands.info.Info; import pkg.deepCurse.nopalmo.command.commands.info.Info;
import pkg.deepCurse.nopalmo.command.commands.info.Ping; import pkg.deepCurse.nopalmo.command.commands.info.Ping;
import pkg.deepCurse.nopalmo.command.commands.info.Reload;
import pkg.deepCurse.nopalmo.command.commands.testing.GuildCommand; import pkg.deepCurse.nopalmo.command.commands.testing.GuildCommand;
import pkg.deepCurse.nopalmo.command.commands.testing.PrivateCommand; import pkg.deepCurse.nopalmo.command.commands.testing.PrivateCommand;
import pkg.deepCurse.nopalmo.core.Boot; import pkg.deepCurse.nopalmo.core.Boot;
@ -45,6 +46,7 @@ public class CommandManager {
} }
public void init() { public void init() {
commandMap.clear();
addCommand(new Help(this));// guild addCommand(new Help(this));// guild
addCommand(new Ping()); // dual addCommand(new Ping()); // dual
addCommand(new Git()); // dual addCommand(new Git()); // dual
@ -52,15 +54,16 @@ public class CommandManager {
addCommand(new Test()); // guild addCommand(new Test()); // guild
addCommand(new Info()); // guild direct addCommand(new Info()); // guild direct
addCommand(new GuildCommand()); // guild addCommand(new GuildCommand()); // guild
addCommand(new PrivateCommand()); addCommand(new PrivateCommand()); // private
addCommand(new Reload()); // dual
} }
private void addCommand(CommandInterface c) { private void addCommand(CommandInterface c) {
if (!commandMap.containsKey(c.getCommandName())) {
commandMap.put(c.getCommandName(), c); for (String i : c.getCommandCalls()) {
} else { // if (!commandMap.containsKey(i)) {
commandMap.remove(c.getCommandName()); commandMap.put(i, c);
commandMap.put(c.getCommandName(), c); // }
} }
} }
@ -93,7 +96,9 @@ public class CommandManager {
} else { } else {
return; return;
} }
Users.addUser(event.getAuthor().getIdLong());
final String[] split = message.replaceFirst("(?i)" + Pattern.quote(splicer), "").split("\\s+"); final String[] split = message.replaceFirst("(?i)" + Pattern.quote(splicer), "").split("\\s+");
final String commandCall = split[0].toLowerCase(); final String commandCall = split[0].toLowerCase();
@ -261,7 +266,7 @@ public class CommandManager {
((PrivateCommandInterface) command).runPrivateCommand(commandBlob, argumentList); ((PrivateCommandInterface) command).runPrivateCommand(commandBlob, argumentList);
} }
if (command instanceof GuildCommandInterface && !event.isFromGuild()) { if (command instanceof GuildCommandInterface && !event.isFromGuild() && !(command instanceof PrivateCommandInterface)) {
event.getChannel() event.getChannel()
.sendMessage( .sendMessage(
"Sorry, but you need to be in a " "Sorry, but you need to be in a "
@ -269,7 +274,7 @@ public class CommandManager {
commandBlob.getAuthorID()) ? "guild" : "server") commandBlob.getAuthorID()) ? "guild" : "server")
+ " to use this command. . .") + " to use this command. . .")
.queue(); .queue();
} else if (command instanceof PrivateCommandInterface && event.isFromGuild()) { } else if (command instanceof PrivateCommandInterface && event.isFromGuild() && !(command instanceof GuildCommandInterface)) {
event.getChannel().sendMessage("Sorry, but this command will only run in dms. . .").queue(); event.getChannel().sendMessage("Sorry, but this command will only run in dms. . .").queue();
} }
} }

View file

@ -19,7 +19,7 @@ public class StatusManager {
activityList.add(Activity.watching( activityList.add(Activity.watching(
Boot.bot.getUserCache().asList().size() + " users in " + Boot.bot.getGuilds().size() + " servers")); Boot.bot.getUserCache().asList().size() + " users in " + Boot.bot.getGuilds().size() + " servers"));
activityList.add(Activity.watching("for " + Global.prefix + "help")); activityList.add(Activity.watching("for " + Global.prefix + "help"));
activityList.add(Activity.competing("your mothers love")); activityList.add(Activity.listening("Infected Mushroom"));
// activityList.add(EntityBuilder.createActivity("owo", null, ActivityType.CUSTOM_STATUS)); // activityList.add(EntityBuilder.createActivity("owo", null, ActivityType.CUSTOM_STATUS));
} }

View file

@ -0,0 +1,22 @@
package pkg.deepCurse.nopalmo.server.socket;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
public class Socks {
public static void sendStringSock(String address, int port, String input) {
try {
Socket cSocket = new Socket(address, port);
DataOutputStream dOut = new DataOutputStream(cSocket.getOutputStream());
dOut.writeUTF(input);
dOut.flush();
dOut.close();
cSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}