@ -3,6 +3,9 @@ package net.pingex.dcf.commands.audit.basic;
import net.pingex.dcf.commands.Context ;
import net.pingex.dcf.commands.audit.AuditResult ;
import net.pingex.dcf.commands.audit.IAuditComponentProvider ;
import net.pingex.dcf.commands.options.ICommandOption ;
import net.pingex.dcf.commands.options.ScopeOption ;
import java.util.Optional ;
/ * *
* This component checks whether the command is invoked in the right scope .
@ -12,9 +15,12 @@ public class ScopeCheck implements IAuditComponentProvider
@Override
public AuditResult doAudit ( Context context )
{
if ( context . getCommand ( ) . getScope ( ) . test ( context . getChannel ( ) ) )
Optional < ICommandOption > option = context . getCommand ( ) . getOptions ( ) . stream ( ) . filter ( i - > i instanceof ScopeOption ) . findFirst ( ) ;
if ( ! option . isPresent ( ) ) return new AuditResult ( AuditResult . ResultCode . NOOP , "ScopeOption not present." ) ;
if ( ( ( ScopeOption ) option . get ( ) ) . getScope ( ) . test ( context . getChannel ( ) ) )
return new AuditResult ( AuditResult . ResultCode . PASS , null ) ;
else return new AuditResult ( AuditResult . ResultCode . FAIL , "Cannot run this command outside of its intended scope. Valid scope is: " + context . getCommand ( ) . getScope ( ) + "." ) ;
else return new AuditResult ( AuditResult . ResultCode . FAIL , "Cannot run this command outside of its intended scope. Valid scope is: " + ( ( ScopeOption ) option . get ( ) ) . getScope ( ) + "." ) ;
}
@Override