diff --git a/src/main/java/net/pingex/dcf/commands/Context.java b/src/main/java/net/pingex/dcf/commands/Context.java new file mode 100644 index 0000000..9eff771 --- /dev/null +++ b/src/main/java/net/pingex/dcf/commands/Context.java @@ -0,0 +1,59 @@ +package net.pingex.dcf.commands; + +import sx.blah.discord.api.IDiscordClient; +import sx.blah.discord.handle.obj.IMessage; +import java.util.List; + +/** + * A Context contains all informations related to a command invokation, like the Command being invoked, its provided arguments and the originating message. + */ +public class Context +{ + /** + * The command being executed + */ + private Command targetCommand; + + /** + * Arguments provided + */ + private List arguments; + + /** + * The originating reference message + */ + private IMessage originatingMessage; + + /** + * Discord client for context + */ + private IDiscordClient client; + + public Context(Command targetCommand, List arguments, IMessage originatingMessage, IDiscordClient client) + { + this.targetCommand = targetCommand; + this.arguments = arguments; + this.originatingMessage = originatingMessage; + this.client = client; + } + + public Command getTargetCommand() + { + return targetCommand; + } + + public List getArguments() + { + return arguments; + } + + public IMessage getOriginatingMessage() + { + return originatingMessage; + } + + public IDiscordClient getClient() + { + return client; + } +} diff --git a/src/main/java/net/pingex/dcf/commands/audit/AuditResult.java b/src/main/java/net/pingex/dcf/commands/audit/AuditResult.java new file mode 100644 index 0000000..4e87a8a --- /dev/null +++ b/src/main/java/net/pingex/dcf/commands/audit/AuditResult.java @@ -0,0 +1,102 @@ +package net.pingex.dcf.commands.audit; + +import java.util.Map; + +/** + * This class contains results for an audit. + */ +public class AuditResult +{ + /** + * Result code for this audit + */ + private ResultCode opCode; + + /** + * Details message about what happened. Mostly used with FAIL and WARN opcodes. + */ + private String message; + + /** + * Sub audits. + */ + private Map subAuditsResults; + + /** + * Full constructor, with sub audits. + * @param opCode The result code of the operation. + * @param message Optional message, pass `null` for no message. + * @param subAuditsResults A result for each sub audit. + */ + public AuditResult(ResultCode opCode, String message, Map subAuditsResults) + { + this.opCode = opCode; + this.message = message; + this.subAuditsResults = subAuditsResults; + } + + /** + * Constructor without sub audits. + * @param opCode The result code of the operation. + * @param message Optional message, pass `null` for no message. + */ + public AuditResult(ResultCode opCode, String message) + { + this.opCode = opCode; + this.message = message; + } + + /** + * Result code for this audit + */ + public ResultCode getOpCode() + { + return opCode; + } + + /** + * Details message about what happened. Mostly used with FAIL and WARN opcodes. + */ + public String getMessage() + { + return message; + } + + /** + * Sub audits. + * @return A map of these subaudits. + * @throws UnsupportedOperationException in case there is not sub audits. + */ + public Map getSubAuditsResults() throws UnsupportedOperationException + { + if(subAuditsResults != null) + return subAuditsResults; + else throw new UnsupportedOperationException(); + } + + /** + * All the possible result codes for an andit and its component. + */ + public enum ResultCode + { + /** + * The test passed without any issue. + */ + PASS, + + /** + * The audit failed. + */ + FAIL, + + /** + * The test passed with a warning (contained in the message field) + */ + WARN, + + /** + * Test has been ignored. + */ + NOOP + } +} diff --git a/src/main/java/net/pingex/dcf/commands/audit/package-info.java b/src/main/java/net/pingex/dcf/commands/audit/package-info.java new file mode 100644 index 0000000..461df46 --- /dev/null +++ b/src/main/java/net/pingex/dcf/commands/audit/package-info.java @@ -0,0 +1,6 @@ +/** + * Commands Audit allows command invokations to be checked for runnability. + * New audit components can be added later with minimal impact on existent code. + * Audit examples: permissions, arguments, scope, etc + */ +package net.pingex.dcf.commands.audit; \ No newline at end of file