diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/AccessLevel.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/AccessLevel.java
index 63dcd54..606d51e 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/AccessLevel.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/AccessLevel.java
@@ -57,7 +57,7 @@ public class AccessLevel {
* @param requiredPermissions The permissions required if in a guild.
* @param onlyGuild Flag that indicate that this can only occur in a guild.
* @param onlyPrivate Flag that indicate that this can only occur in a private channel.
- * @param user Flag that indicate that only this user can use this, overwrite every other flag .
+ * @param user Flag that indicate that only this user can use this, /!\ overwrite every other flag /!\.
*/
public AccessLevel(@Nonnull EnumSet requiredPermissions, boolean onlyGuild, boolean onlyPrivate, long user) {
this.requiredPermissions = requiredPermissions;
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/Command.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/Command.java
index 92d4fd5..b04d18a 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/Command.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/Command.java
@@ -135,13 +135,13 @@ private void registerCommandPatterns() {
} else if (params[1].isAssignableFrom(Options.class)) {
// CommandEvent, Options
- patterns.add(new CommandPattern((event, args, options) -> invokeMethod(method, options)));
+ patterns.add(new CommandPattern((event, args, options) -> invokeMethod(method, event, options)));
} else {
// CommandEvent, Arg1
patterns.add(new CommandPattern(
translateArguments(method, 1),
- (event, args, options) -> invokeMethod(method, args.get(0))
+ (event, args, options) -> invokeMethod(method, event, args.get(0))
));
}
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/CommandEvent.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/CommandEvent.java
index 9b7d8b9..0a207b4 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/CommandEvent.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/CommandEvent.java
@@ -8,17 +8,31 @@
public class CommandEvent extends MessageReceivedEvent {
- private Command command;
+ private final CommandModule module;
+ private final Command command;
- public CommandEvent(@Nonnull MessageReceivedEvent baseEvent, Command command) {
- this(baseEvent.getJDA(), baseEvent.getResponseNumber(), baseEvent.getMessage(), command);
+ public CommandEvent(@Nonnull final MessageReceivedEvent baseEvent, @Nonnull final CommandModule module,
+ @Nonnull final Command command) {
+ this(baseEvent.getJDA(), baseEvent.getResponseNumber(), baseEvent.getMessage(), module, command);
}
- public CommandEvent(JDA api, long responseNumber, Message message, Command command) {
+ public CommandEvent(@Nonnull final JDA api, final long responseNumber, @Nonnull final Message message,
+ @Nonnull final CommandModule module, @Nonnull final Command command) {
super(api, responseNumber, message);
+ this.module = module;
this.command = command;
}
+ public void fastReply(@Nonnull final String message) {
+ channel.sendMessage(message).complete();
+ }
+
+ @Nonnull
+ public CommandModule getModule() {
+ return module;
+ }
+
+ @Nonnull
public Command getCommand() {
return command;
}
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/CommandModule.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/CommandModule.java
index ed53e22..fdf826a 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/CommandModule.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/CommandModule.java
@@ -3,6 +3,8 @@
import com.jesus_crie.modularbot.ModularBotBuilder;
import com.jesus_crie.modularbot.module.BaseModule;
import com.jesus_crie.modularbot_command.listener.CommandListener;
+import com.jesus_crie.modularbot_command.listener.DiscordCommandListener;
+import com.jesus_crie.modularbot_command.listener.NopCommandListener;
import com.jesus_crie.modularbot_command.processing.CommandProcessor;
import javax.annotation.Nonnull;
@@ -24,13 +26,15 @@ public class CommandModule extends BaseModule {
// Command processor
private CommandProcessor processor = new CommandProcessor();
+ private CommandListener listener = new NopCommandListener();
+
public CommandModule() {
super(INFO);
}
@Override
public void onLoad(@Nonnull ModularBotBuilder builder) {
- builder.addListeners(new CommandListener(this));
+ builder.addListeners(new DiscordCommandListener(this));
}
public void registerCommands(@Nonnull Command... commands) {
@@ -61,4 +65,13 @@ public Command getCommand(@Nonnull String name) {
.findAny()
.orElse(null);
}
+
+ public void setListener(@Nonnull final CommandListener listener) {
+ this.listener = listener;
+ }
+
+ @Nonnull
+ public CommandListener getListener() {
+ return listener;
+ }
}
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/annotations/RegisterPattern.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/annotations/RegisterPattern.java
index 763b9b1..86d0226 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/annotations/RegisterPattern.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/annotations/RegisterPattern.java
@@ -11,7 +11,7 @@
* Use on a method inside a class that extends {@link Command Command} to associate
* a pattern with it.
* The method should be protected or higher and should take 3 arguments in that order:
- * {@link CommandEvent CommandEvent}, {@link java.util.List List}, {@link Options Options}.
+ * {@link CommandEvent CommandEvent}, {@link java.util.List List}, {@link Options Options}.
* The return type doesn't matter.
*/
@Target(ElementType.METHOD)
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/CommandListener.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/CommandListener.java
index 713f847..4382c04 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/CommandListener.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/CommandListener.java
@@ -1,62 +1,90 @@
package com.jesus_crie.modularbot_command.listener;
-import com.jesus_crie.modularbot_command.Command;
import com.jesus_crie.modularbot_command.CommandEvent;
-import com.jesus_crie.modularbot_command.CommandModule;
import com.jesus_crie.modularbot_command.exception.CommandProcessingException;
+import com.jesus_crie.modularbot_command.exception.UnknownOptionException;
import com.jesus_crie.modularbot_command.processing.Options;
-import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
-import net.dv8tion.jda.core.hooks.ListenerAdapter;
+import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.utils.tuple.Pair;
+import javax.annotation.Nonnull;
import java.util.List;
import java.util.Map;
-public class CommandListener extends ListenerAdapter {
+public interface CommandListener {
- private final CommandModule module;
+ /**
+ * Triggered every time a command is typed (= any message that starts with the prefix
+ */
+ void onCommandReceived();
- public CommandListener(CommandModule module) {
- this.module = module;
- }
+ /**
+ * Triggered when a command was typed and it was a real command.
+ * But nothing has been executed yet and no checks have been performed.
+ *
+ * @param command The actual event.
+ */
+ void onCommandFound(@Nonnull final CommandEvent command);
- @Override
- public void onMessageReceived(MessageReceivedEvent event) {
- if (event.getAuthor().getIdLong() == event.getJDA().getSelfUser().getIdLong())
- return;
+ /**
+ * Triggered when a message starts with the prefix but it was a false alert, the command doesn't exist.
+ * An error 404 in a manner.
+ *
+ * @param name The name of the command that was typed.
+ * @param message The message containing the wrong command.
+ */
+ void onCommandNotFound(@Nonnull final String name, @Nonnull final Message message);
- final String prefix = module.getPrefixForGuild(event.getGuild().getIdLong());
- if (!event.getMessage().getContentRaw().startsWith(prefix))
- return;
+ /**
+ * Triggered when a command is found but the user doesn't satisfy the {@link com.jesus_crie.modularbot_command.AccessLevel AccessLevel}
+ * associated with this command.
+ *
+ * @param event The event that was fired.
+ */
+ void onTooLowAccessLevel(@Nonnull final CommandEvent event);
- final String[] parts = event.getMessage().getContentRaw().split(" ", 2);
- final String name = parts[0].substring(prefix.length());
- final Command command = module.getCommand(name);
+ /**
+ * Triggered when a command is found, the user have the correct privileges and what he just typed has been
+ * successfully parsed.
+ *
+ * @param event The event that was fired.
+ * @param processedContent The output of the command processor.
+ * @see com.jesus_crie.modularbot_command.processing.CommandProcessor
+ * @see com.jesus_crie.modularbot_command.processing.CommandProcessor#process(String)
+ */
+ void onCommandSuccessfullyProcessed(@Nonnull final CommandEvent event, @Nonnull final Pair, Map> processedContent);
- if (command == null) {
- // TODO 10/06/2018 notify not found
- return;
- }
+ /**
+ * Triggered when the processing of the command has failed, usually a syntax error.
+ *
+ * @param event The event that was fired.
+ * @param error The error from the command processor.
+ * @see com.jesus_crie.modularbot_command.processing.CommandProcessor
+ */
+ void onCommandFailedProcessing(@Nonnull final CommandEvent event, @Nonnull final CommandProcessingException error);
- final CommandEvent cmdEvent = new CommandEvent(event, command);
+ /**
+ * Triggered when the command was successfully processed but one of the option is not registered in the command.
+ *
+ * @param event The event that was fired.
+ * @param error The error from the {@link com.jesus_crie.modularbot_command.processing.Options}.
+ * @see com.jesus_crie.modularbot_command.processing.Options
+ */
+ void onCommandFailedUnknownOption(@Nonnull final CommandEvent event, @Nonnull final UnknownOptionException error);
- if (!command.getAccessLevel().check(cmdEvent)) {
- // TODO 10/06/2018 notify too low access
- return;
- }
+ /**
+ * Triggered when the command failed to execute because the provided arguments doesn't match any registered pattern.
+ *
+ * @param event The actual event.
+ * @param options The provided options.
+ * @param arguments The provided arguments.
+ */
+ void onCommandFailedNoPatternMatch(@Nonnull final CommandEvent event, @Nonnull final Options options, @Nonnull final List arguments);
- try {
- final Pair, Map> processedContent = module.getCommandProcessor().process(event.getMessage().getContentRaw());
-
- // TODO 13/06/2018 notify command processed successfully
-
- final Options options = new Options(module, command, processedContent.getRight());
- if (!command.execute(module, cmdEvent, options, processedContent.getLeft())) {
- // TODO 13/06/2018 notify not pattern found
- }
-
- } catch (CommandProcessingException e) {
- // TODO 11/06/2018 notify error processing command
- }
- }
+ /**
+ * Triggered when the command is successfully executed.
+ *
+ * @param event The event that triggered the command in the first place.
+ */
+ void onCommandSuccess(@Nonnull final CommandEvent event);
}
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/DiscordCommandListener.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/DiscordCommandListener.java
new file mode 100644
index 0000000..558909c
--- /dev/null
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/DiscordCommandListener.java
@@ -0,0 +1,72 @@
+package com.jesus_crie.modularbot_command.listener;
+
+import com.jesus_crie.modularbot_command.Command;
+import com.jesus_crie.modularbot_command.CommandEvent;
+import com.jesus_crie.modularbot_command.CommandModule;
+import com.jesus_crie.modularbot_command.exception.CommandProcessingException;
+import com.jesus_crie.modularbot_command.exception.UnknownOptionException;
+import com.jesus_crie.modularbot_command.processing.Options;
+import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
+import net.dv8tion.jda.core.hooks.ListenerAdapter;
+import net.dv8tion.jda.core.utils.tuple.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+
+public class DiscordCommandListener extends ListenerAdapter {
+
+ private static final Logger LOG = LoggerFactory.getLogger("DiscordCommandListener");
+
+ private final CommandModule module;
+
+ public DiscordCommandListener(CommandModule module) {
+ this.module = module;
+ }
+
+ @Override
+ public void onMessageReceived(MessageReceivedEvent event) {
+ if (event.getAuthor().getIdLong() == event.getJDA().getSelfUser().getIdLong())
+ return;
+
+ final String prefix = module.getPrefixForGuild(event.getGuild().getIdLong());
+ if (!event.getMessage().getContentRaw().startsWith(prefix))
+ return;
+
+ final String[] parts = event.getMessage().getContentRaw().split(" ", 2);
+ final String name = parts[0].substring(prefix.length());
+ final Command command = module.getCommand(name);
+
+ if (command == null) {
+ module.getListener().onCommandNotFound(name, event.getMessage());
+ return;
+ }
+
+ final CommandEvent cmdEvent = new CommandEvent(event, module, command);
+
+ if (!command.getAccessLevel().check(cmdEvent)) {
+ module.getListener().onTooLowAccessLevel(cmdEvent);
+ return;
+ }
+
+ try {
+ final String fullArgs;
+ if (parts.length == 2) fullArgs = parts[1];
+ else fullArgs = "";
+
+ final Pair, Map> processedContent = module.getCommandProcessor().process(fullArgs);
+
+ module.getListener().onCommandSuccessfullyProcessed(cmdEvent, processedContent);
+
+ final Options options = new Options(module, command, processedContent.getRight());
+ if (!command.execute(module, cmdEvent, options, processedContent.getLeft()))
+ module.getListener().onCommandFailedNoPatternMatch(cmdEvent, options, processedContent.getLeft());
+
+ } catch (CommandProcessingException e) {
+ module.getListener().onCommandFailedProcessing(cmdEvent, e);
+ } catch (UnknownOptionException e) {
+ module.getListener().onCommandFailedUnknownOption(cmdEvent, e);
+ }
+ }
+}
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/NopCommandListener.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/NopCommandListener.java
new file mode 100644
index 0000000..4a082f7
--- /dev/null
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/listener/NopCommandListener.java
@@ -0,0 +1,60 @@
+package com.jesus_crie.modularbot_command.listener;
+
+import com.jesus_crie.modularbot_command.CommandEvent;
+import com.jesus_crie.modularbot_command.exception.CommandProcessingException;
+import com.jesus_crie.modularbot_command.exception.UnknownOptionException;
+import com.jesus_crie.modularbot_command.processing.Options;
+import javafx.util.Pair;
+import net.dv8tion.jda.core.entities.Message;
+
+import javax.annotation.Nonnull;
+import java.util.List;
+import java.util.Map;
+
+public class NopCommandListener implements CommandListener {
+
+ @Override
+ public void onCommandReceived() {
+ /* no-op */
+ }
+
+ @Override
+ public void onCommandFound(@Nonnull CommandEvent command) {
+ /* no-op */
+ }
+
+ @Override
+ public void onCommandNotFound(@Nonnull String name, @Nonnull Message message) {
+ /* no-op */
+ }
+
+ @Override
+ public void onTooLowAccessLevel(@Nonnull CommandEvent event) {
+ /* no-op */
+ }
+
+ @Override
+ public void onCommandSuccessfullyProcessed(@Nonnull CommandEvent event, @Nonnull Pair, Map> processedContent) {
+ /* no-op */
+ }
+
+ @Override
+ public void onCommandFailedProcessing(@Nonnull CommandEvent event, @Nonnull CommandProcessingException error) {
+ /* no-op */
+ }
+
+ @Override
+ public void onCommandFailedUnknownOption(@Nonnull CommandEvent event, @Nonnull UnknownOptionException error) {
+ /* no-op */
+ }
+
+ @Override
+ public void onCommandFailedNoPatternMatch(@Nonnull CommandEvent event, @Nonnull Options options, @Nonnull List arguments) {
+ /* no-op */
+ }
+
+ @Override
+ public void onCommandSuccess(@Nonnull CommandEvent event) {
+ /* no-op */
+ }
+}
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/CommandPattern.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/CommandPattern.java
index 26e65f9..cb0ff1c 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/CommandPattern.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/CommandPattern.java
@@ -68,4 +68,9 @@ private Argument getLastArgument() {
public boolean hasArguments() {
return !arguments.isEmpty();
}
+
+ @Override
+ public String toString() {
+ return "CommandPattern{ " + arguments + " }";
+ }
}
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/CommandProcessor.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/CommandProcessor.java
index a4f84ed..3abc0dd 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/CommandProcessor.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/CommandProcessor.java
@@ -56,10 +56,13 @@ public CommandProcessor(int flags) {
*/
@Nonnull
public Pair, Map> process(@Nonnull String input) throws CommandProcessingException {
- input = input.trim();
-
List arguments = new ArrayList<>();
Map options = new LinkedHashMap<>();
+
+ if (input.length() == 0)
+ return Pair.of(arguments, options);
+
+ input = input.trim();
Cursor cursor = new Cursor(input);
char n;
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/Option.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/Option.java
index 0b38e6e..c4c3bfb 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/Option.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/Option.java
@@ -130,7 +130,7 @@ public char getShortName() {
}
public boolean hasArgument() {
- return argument == null;
+ return argument != null;
}
@Nullable
diff --git a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/Options.java b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/Options.java
index 042336a..b1a9df6 100644
--- a/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/Options.java
+++ b/ModularBot-Command/src/main/java/com/jesus_crie/modularbot_command/processing/Options.java
@@ -5,6 +5,7 @@
import com.jesus_crie.modularbot_command.exception.UnknownOptionException;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -74,6 +75,7 @@ public boolean has(@Nonnull String name) {
* @see #has(Option)
* @see #has(String)
*/
+ @Nullable
public T get(@Nonnull Option option) {
if (!has(option) || !option.hasArgument()) return null;
diff --git a/ModularBot-Command/src/test/java/com/jesus_crie/modularbot_command/CommandTest.java b/ModularBot-Command/src/test/java/com/jesus_crie/modularbot_command/CommandTest.java
index 318b423..dca4f4b 100644
--- a/ModularBot-Command/src/test/java/com/jesus_crie/modularbot_command/CommandTest.java
+++ b/ModularBot-Command/src/test/java/com/jesus_crie/modularbot_command/CommandTest.java
@@ -101,7 +101,7 @@ public WrongCommand() {
}
@RegisterPattern
- public void someInvalidMethod() {
+ public void someInvalidMethod(String s) {
}
}
diff --git a/ModularBot-Core/build.gradle b/ModularBot-Core/build.gradle
index 59acc8c..ca0e52e 100644
--- a/ModularBot-Core/build.gradle
+++ b/ModularBot-Core/build.gradle
@@ -4,3 +4,50 @@ dependencies {
testCompile project(':modularbot-command')
testCompile project(':modularbot-logger')
}
+
+uploadArchives {
+ repositories {
+ mavenDeployer {
+ beforeDeployment {
+ MavenDeployment deployment -> signing.signPom(deployment)
+ }
+
+ repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
+ authentication(userName: ossrhUsername, password: ossrhPassword)
+ }
+
+ snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') {
+ authentication(userName: ossrhUsername, password: ossrhPassword)
+ }
+
+ pom.project {
+ name 'ModularBot - Core'
+ description 'A java framework based on JDA that helps you create your discord bot.'
+ packaging 'jar'
+ url = 'https://github.com/JesusCrie/ModularBot_v2'
+
+ scm {
+ connection = 'scm:git:git://github.com/JesusCrie/ModularBot_v2.git'
+ developerConnection = 'scm:git:ssh://github.com/JesusCrie/ModularBot_v2.git'
+ url = 'https://github.com/JesusCrie/ModularBot_v2'
+ }
+
+ licenses {
+ license {
+ name = 'GNU General Public License v3.0'
+ url = 'https://github.com/JesusCrie/ModularBot_v2/blob/master/LICENSE'
+ }
+ }
+
+ developers {
+ developer {
+ id = 'com.jesus_crie'
+ name = 'Lucas Malandrino'
+ email = 'lucas.malandrino@gmail.com'
+ }
+ }
+
+ }
+ }
+ }
+}
diff --git a/ModularBot-Core/src/test/java/com/jeus_crie/modularbot/ModularTestRun.java b/ModularBot-Core/src/test/java/com/jeus_crie/modularbot/ModularTestRun.java
index 9eabbea..6176c45 100644
--- a/ModularBot-Core/src/test/java/com/jeus_crie/modularbot/ModularTestRun.java
+++ b/ModularBot-Core/src/test/java/com/jeus_crie/modularbot/ModularTestRun.java
@@ -3,10 +3,14 @@
import com.jesus_crie.modularbot.ModularBot;
import com.jesus_crie.modularbot.ModularBotBuilder;
import com.jesus_crie.modularbot.module.BaseModule;
+import com.jesus_crie.modularbot_command.Command;
+import com.jesus_crie.modularbot_command.CommandEvent;
import com.jesus_crie.modularbot_command.CommandModule;
+import com.jesus_crie.modularbot_command.annotations.CommandInfo;
+import com.jesus_crie.modularbot_command.annotations.RegisterPattern;
+import com.jesus_crie.modularbot_command.processing.Option;
+import com.jesus_crie.modularbot_command.processing.Options;
import com.jesus_crie.modularbot_logger.ConsoleLoggerModule;
-import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
-import net.dv8tion.jda.core.hooks.ListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,28 +26,18 @@ public static void main(String[] args) {
.useShutdownNow()
.registerModules(
new ConsoleLoggerModule(),
- new CommandModule(),
- new ModularTestRun()
+ new CommandModule()
)
.build();
CommandModule cmd = bot.getModuleManager().getModule(CommandModule.class);
+ cmd.registerCommands(new StopCommand());
try {
bot.login();
} catch (LoginException e) {
e.printStackTrace();
}
-
- bot.addEventListener(new ListenerAdapter() {
- @Override
- public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
- LOG.info("Message received: " + event.getMessage().getContentRaw());
- if (event.getMessage().getContentRaw().equals("stop dude")) {
- bot.shutdown();
- }
- }
- });
}
private final Logger logger = LoggerFactory.getLogger("ModuleTest");
@@ -56,4 +50,34 @@ protected ModularTestRun() {
public void onShardsReady(final @Nonnull ModularBot bot) {
logger.info("Bot ready !");
}
+
+ @CommandInfo(
+ name = "stop",
+ shortDescription = "Stops the bot",
+ options = {"NAME", "FORCE"})
+ public static class StopCommand extends Command {
+
+ public StopCommand() {
+ super();
+ LOG.info(String.valueOf(patterns));
+ }
+
+ @RegisterPattern
+ public void execute(CommandEvent event, Options options) {
+ if (options.has(Option.FORCE)) {
+ event.fastReply("Force shut down");
+ } else if (options.has(Option.NAME)) {
+ if (options.get(Option.NAME) != null)
+ event.fastReply("Shut down special for " + options.get(Option.NAME));
+ else {
+ event.fastReply("Missing argument for name");
+ return;
+ }
+ } else {
+ event.fastReply("Regular shutdown");
+ }
+
+ event.getModule().getBot().shutdown();
+ }
+ }
}
diff --git a/ModularBot-Logger/src/main/java/com/jesus_crie/modularbot_logger/ConsoleLoggerModule.java b/ModularBot-Logger/src/main/java/com/jesus_crie/modularbot_logger/ConsoleLoggerModule.java
index 6808f6b..88865e4 100644
--- a/ModularBot-Logger/src/main/java/com/jesus_crie/modularbot_logger/ConsoleLoggerModule.java
+++ b/ModularBot-Logger/src/main/java/com/jesus_crie/modularbot_logger/ConsoleLoggerModule.java
@@ -45,7 +45,7 @@ public ConsoleLoggerModule() {
@Override
public void onLoad(@Nonnull ModularBotBuilder builder) {
ModularLogger.addListener(log -> {
- if (log.level.getLevel() > MIN_LEVEL.getLevel()) {
+ if (log.level.getLevel() >= MIN_LEVEL.getLevel()) {
final String message = MessageFormat.format(FORMAT_LOG,
FORMAT_TIME.format(log.time),
diff --git a/build.gradle b/build.gradle
index 404261c..ea2c7b6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -11,11 +11,7 @@ allprojects {
compileJava.options.encoding = 'UTF-8'
- archivesBaseName = 'ModularBot'
-
- jar {
- archiveName "ModularBot-$name-v$version\\.jar"
- }
+ archivesBaseName = name
repositories {
mavenCentral()
@@ -30,6 +26,24 @@ allprojects {
testCompile 'org.junit.jupiter:junit-jupiter-params:5.2.0'
testCompile 'org.hamcrest:hamcrest-junit:2.0.0.0'
}
+
+ task javadocJar(type: Jar) {
+ classifier = 'javadoc'
+ from javadoc
+ }
+
+ task sourcesJar(type: Jar) {
+ classifier = 'sources'
+ from sourceSets.main.allSource
+ }
+
+ artifacts {
+ archives javadocJar, sourcesJar
+ }
+
+ signing {
+ sign configurations.archives
+ }
}
project(':modularbot-core') {
@@ -53,67 +67,3 @@ subprojects {
}
}
}
-
-task javadocJar(type: Jar) {
- classifier = 'javadoc'
- from javadoc
-}
-
-task sourcesJar(type: Jar) {
- classifier = 'sources'
- from sourceSets.main.allSource
-}
-
-artifacts {
- archives javadocJar, sourcesJar
-}
-
-signing {
- sign configurations.archives
-}
-
-uploadArchives { task ->
- repositories {
- mavenDeployer {
- beforeDeployment {
- MavenDeployment deployment -> signing.signPom(deployment)
- }
-
- repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
- authentication(userName: ossrhUsername, password: ossrhPassword)
- }
-
- repository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') {
- authentication(userName: ossrhUsername, password: ossrhPassword)
- }
-
- pom.project {
- name '$task.project.name'
- packaging 'jar'
- url = 'https://github.com/JesusCrie/ModularBot_v2'
-
- scm {
- connection = 'scm:git:git://github.com/JesusCrie/ModularBot_v2.git'
- developerConnection = 'scm:git:ssh://github.com/JesusCrie/ModularBot_v2.git'
- url = 'https://github.com/JesusCrie/ModularBot_v2'
- }
-
- licenses {
- license {
- name = 'GNU General Public License v3.0'
- url = 'https://github.com/JesusCrie/ModularBot_v2/blob/master/LICENSE'
- }
- }
-
- developers {
- developer {
- id = 'com.jesus_crie'
- name = 'Lucas Malandrino'
- email = 'lucas.malandrino@gmail.com'
- }
- }
-
- }
- }
- }
-}