Migrated CH to the new audit system.

keep-around/3c354c0f00ae6e9d0b7ccd747b995217fbd6c147
Pingex aka Raphaël 9 years ago
parent e97cff9f68
commit 3c354c0f00

@ -1,5 +1,7 @@
package net.pingex.dcf.commands;
import net.pingex.dcf.commands.audit.AuditManager;
import net.pingex.dcf.commands.audit.AuditResult;
import net.pingex.dcf.commands.parser.BasicParser;
import net.pingex.dcf.commands.parser.ICommandParser;
import net.pingex.dcf.commands.parser.ParserException;
@ -67,23 +69,20 @@ public class CommandHandler
return;
}
// Enabled check
if(!targetCommand.get().isEnabled())
// Audit
AuditResult result = AuditManager.doAudit(new Context(targetCommand.get(), arguments, event.getMessage(), event.getClient()));
if(result.getOpcode().equals(AuditResult.ResultCode.FAIL))
{
LOGGER.debug("User {} attempted to run a disabled command !", event.getMessage().getAuthor().getID());
DiscordInteractionsUtil.sendMessage(event.getMessage().getChannel(), "Command is disabled.");
LOGGER.info("Denied command {} for user #{}. OPCode: {}, Reason: {}", targetCommand.get().getName(), event.getMessage().getAuthor().getID(), result.getOpcode(), result.getMessage());
DiscordInteractionsUtil.sendMessage(event.getMessage().getChannel(), result.getMessage());
return;
}
if(result.getOpcode().equals(AuditResult.ResultCode.WARN))
DiscordInteractionsUtil.sendMessage(event.getMessage().getChannel(), "Warning: " + result.getMessage());
// Scope check
if(!targetCommand.get().getScope().test(event.getMessage().getChannel()))
{
LOGGER.debug("User {} attempted to run a command outside of its intended scope.", event.getMessage().getAuthor().getID());
DiscordInteractionsUtil.sendMessage(event.getMessage().getChannel(), "Cannot run this command outside of its intended scope. Valid scope is: " + targetCommand.get().getScope() + ".");
return;
}
LOGGER.info("Accepted command {} for user #{}. OPCode: {}, Reason: {}", targetCommand.get().getName(), event.getMessage().getAuthor().getID(), result.getOpcode(), result.getMessage() != null ? result.getMessage() : "N/A");
// Authorize
// Authorize TODO
if(!PermissionsHandler.canRunCommand(event.getMessage(), targetCommand.get()))
{
LOGGER.debug("User {} attempted to run a forbidden command !", event.getMessage().getAuthor().getID());