Skip to content

Attributes

BIGDummyHead edited this page Apr 26, 2022 · 3 revisions

This will probably be one of my favorite sections of this entire library.

Attributes can be used to modify so many things!

We have two major types of attributes. The BaseCommandAttribute and CommandParameterAttribute, the former allows us to control the method that is being invoked and can only be applied overtop of Methods; The latter allows us to manipulate the string[] that the Handler is parsing, we can join multiple strings into one and return it back to the handler to fit a method so that it can be properly invoked.

Base Command Attribute

public class ExampleAttr : BaseCommandAttribute
{  
    public override async Task<bool> BeforeCommandExecute(object classInstance, object[] methodParams)
    {
       //in here we can do a few things, we can modify the method parameter array before the method is invoked.
       //we can also determine if the command is to be executed at all

       return true; //if we return true: the command will execute. if we return false: the command will not execute
       //it is important to see the HandlerConfig.ByPopularVote because that will also determine how this works with other Command attributes
    }
}

public class Module : ICommandModule
{
   public ValueTask OnCommandExecute(MethodInfo method, object instance, object[] invokes, object? returnInstance)
   {
       throw new NotImplementedException();
   }
   
   [Command]
   async Task Say(string arg1)
   {
      Console.WriteLine(arg1);
   }
}

Clone this wiki locally