some shit

Signed-off-by: deepCurse <leverplays@gmail.com>
This commit is contained in:
deepCurse 2021-12-13 17:06:27 -04:00
parent 2b59133f15
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"?>
<classpath>
<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">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</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 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="/bontebok"/>
<classpathentry combineaccessrules="false" kind="src" path="/phoenix-runtime"/>
<classpathentry combineaccessrules="false" kind="src" path="/libs-java"/>
<classpathentry kind="output" path="bin"/>
</classpath>

2
.gitignore vendored
View file

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

View file

@ -1,4 +1,5 @@
mix command managers
// DONE mix command managers
finish loop
add socket server for better management / integration
implement pheonix in a smarter way than last time
// DONE add socket server for better management / integration
// 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 default String getUsage(boolean hasPermissionInfo) {
StringBuilder sB = new StringBuilder();
if (getArguments() != null) {
for (Argument i : getArguments().values()) {
if (!i.isDeveloper() || (hasPermissionInfo && i.isDeveloper())) {
sB.append(i.isRequired() ? "<" : "[");
if (i.getPrefixRequirement()) {
sB.append(Argument.argumentPrefix);
for (Argument i : getArguments().values()) {
if ((i.isDeveloper() && hasPermissionInfo) || !i.isDeveloper()) {
if (i.isRequired()) {
sB.append("<");
} else {
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() {
@ -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()
.sendMessage("This is the automatically running argument inside of " + this.getCommandName())
.queue();
// blob.getCommandManager().init();
}).setPrefixRequirement(true).setAutoStartRunnable(true).setDeveloper(true));

View file

@ -32,43 +32,80 @@ public class Help implements GuildCommandInterface {
deniedPages.add(HelpPage.EGG);
deniedPages.add(HelpPage.TESTING);
if (argumentMap.isEmpty() || (isDevEnabled && argumentMap.size() == 1)) {
if (argumentMap.get("commandName") == null) {
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()) {
List<String> commandNameList = commandHash.get(command.getHelpPage());
if (commandNameList == null) {
commandNameList = new ArrayList<String>();
}
commandNameList.add(command.getCommandName());
commandHash.put(command.getHelpPage(), commandNameList);
}
// TODO yet another rewrite
// TODO add command to log a string
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();
int count = 0;
for (String j : commandHash.get(i)) {
if (++count > 3) {
sB.append("\n");
if (count >= 3) {
count = 0;
sB.append("\n");
}
count++;
sB.append("`" + j + "` ");
}
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();
CommandInterface ping = blob.getCommandManager().getCommand("ping");
@ -184,7 +221,8 @@ public class Help implements GuildCommandInterface {
HashMap<String, Argument> args = new HashMap<String, Argument>();
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;
}

View file

@ -30,11 +30,12 @@ public class Info implements GuildCommandInterface, PrivateCommandInterface {
@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.getAuthorID())).queue();
}).setPrefixRequirement(true).setAutoStartRunnable(true).setSkipOriginalTaskOnRunnable(true));
blob.getChannel().sendMessage(!Users.dump(blob.getAuthorID()).isEmpty() ? Users.dump(blob.getAuthorID())
: "Sorry, but this user does not exist in the database").queue();
}).setPrefixRequirement(true).setAutoStartRunnable(true).setSkipOriginalTaskOnRunnable(true).addAliases("u"));
return args;
}
@ -44,6 +45,6 @@ public class Info implements GuildCommandInterface, PrivateCommandInterface {
@Override
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;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.sql.SQLException;
import java.util.List;
import net.dv8tion.jda.api.JDA;
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.manager.CommandManager;
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.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 static JDA bot; // TODO create sharding handler
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;
@ -35,155 +40,194 @@ public class Boot {
public static final CommandManager commandManager = new CommandManager();
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");
PhoenixSettings settings = new PhoenixSettings().setAuthentication(args[3]).setCommandSplitRegex(", ").setCommandManager(new PhoenixCommandManager());
// TODO using join and a while last time + 15000 < current time, then kill and proceed as a failure
settings.commandManager.addCommand("phoenix-update", (PhoenixRuntime runtime, List<String> commandArgs) -> {
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. . .");
try {
if (Locks.dirLock("nopalmo.lock")) {
LogHelper.boot("Failed to lock. . .\nShutting down. . .");
System.exit(3);
} else {
LogHelper.boot("Nopalmo is locked. . .");
runtime.setLockedRunnable(() -> {
System.out.println("System is locked\nSending <phoenix-update> instead. . . ");
try {
Socket cSocket = new Socket("127.0.0.1", settings.commonPort);
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 {

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;
import java.util.ArrayList;
import java.util.List;
public class Argument {
// README
@ -30,6 +33,7 @@ public class Argument {
private String permissionLevel = null;
private boolean isRequired = 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
// generally not change, ever, its recommended you keep it to
@ -136,7 +140,7 @@ public class Argument {
return isWildcard;
}
public boolean getPrefixRequirement() {
public boolean isPrefixRequired() {
return this.requiresPrefix;
}
@ -214,4 +218,15 @@ public class Argument {
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.Info;
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.PrivateCommand;
import pkg.deepCurse.nopalmo.core.Boot;
@ -45,6 +46,7 @@ public class CommandManager {
}
public void init() {
commandMap.clear();
addCommand(new Help(this));// guild
addCommand(new Ping()); // dual
addCommand(new Git()); // dual
@ -52,15 +54,16 @@ public class CommandManager {
addCommand(new Test()); // guild
addCommand(new Info()); // guild direct
addCommand(new GuildCommand()); // guild
addCommand(new PrivateCommand());
addCommand(new PrivateCommand()); // private
addCommand(new Reload()); // dual
}
private void addCommand(CommandInterface c) {
if (!commandMap.containsKey(c.getCommandName())) {
commandMap.put(c.getCommandName(), c);
} else {
commandMap.remove(c.getCommandName());
commandMap.put(c.getCommandName(), c);
for (String i : c.getCommandCalls()) {
// if (!commandMap.containsKey(i)) {
commandMap.put(i, c);
// }
}
}
@ -93,7 +96,9 @@ public class CommandManager {
} else {
return;
}
Users.addUser(event.getAuthor().getIdLong());
final String[] split = message.replaceFirst("(?i)" + Pattern.quote(splicer), "").split("\\s+");
final String commandCall = split[0].toLowerCase();
@ -261,7 +266,7 @@ public class CommandManager {
((PrivateCommandInterface) command).runPrivateCommand(commandBlob, argumentList);
}
if (command instanceof GuildCommandInterface && !event.isFromGuild()) {
if (command instanceof GuildCommandInterface && !event.isFromGuild() && !(command instanceof PrivateCommandInterface)) {
event.getChannel()
.sendMessage(
"Sorry, but you need to be in a "
@ -269,7 +274,7 @@ public class CommandManager {
commandBlob.getAuthorID()) ? "guild" : "server")
+ " to use this command. . .")
.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();
}
}

View file

@ -19,7 +19,7 @@ public class StatusManager {
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"));
activityList.add(Activity.listening("Infected Mushroom"));
// 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();
}
}
}