Audits preliminary work

keep-around/23b8b9e8830874d5f04b57600c3660bddce1287b
Pingex aka Raphaël 9 years ago
parent c2ad1056d9
commit 8e5dec8aa6

@ -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<String> arguments;
/**
* The originating reference message
*/
private IMessage originatingMessage;
/**
* Discord client for context
*/
private IDiscordClient client;
public Context(Command targetCommand, List<String> arguments, IMessage originatingMessage, IDiscordClient client)
{
this.targetCommand = targetCommand;
this.arguments = arguments;
this.originatingMessage = originatingMessage;
this.client = client;
}
public Command getTargetCommand()
{
return targetCommand;
}
public List<String> getArguments()
{
return arguments;
}
public IMessage getOriginatingMessage()
{
return originatingMessage;
}
public IDiscordClient getClient()
{
return client;
}
}

@ -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<IAuditComponentProvider, AuditResult> 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<IAuditComponentProvider, AuditResult> 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<IAuditComponentProvider, AuditResult> 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
}
}

@ -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;