-
Notifications
You must be signed in to change notification settings - Fork 4
internal.hooks
Warning
Hooks are a deprecated (and removed) feature, they have been replaced with String Template
A Hook is a Method that can be called form within a Command that can inject text into the Command. It can take Strings as arguments from strings in the Command, or other nested Hooks in this Command, and outputs a String that is placed into the Command. This can be used put dynamic values into the Command that are calculated at runtime, like a giveaway winner, or the local time. The Hooks output value is then used to replace the call to the Hook in the Command.
Hooks are simple Methods that are registered by annotating them with the @Hook
annotation, in the modules
directory in a directory and filename of your choosing.
For more information see -> Folder-structure
For a Hook to be considered valid, and able to be executed the Hook functions needs to be:
- static
- public, both the function and class
- the return value has to be
String
(if you want to return nothing, return an empty string) - for parameters you can have as many
String
s as you want. You can optionally add a parameter of typeMessage
as your first parameter. Besides Strings and one Message you can't have any other types of parameters! Valid: no arguments n-Strings Message, n-Strings Message
@Hook
public static String Math(String operation, String value1, String value2)
@Hook
public static String senderSubMonths(Message message)
Hook Call Syntax in a Command
A Hook Call is encased in curly braces ({ }
); it starts with the Hook Name, the Name of the Hook function, the name has to be an exact match but ignore the casing.
If the braces and the name are separated by a space is not significant.
The the parameter follow after the name, if the Hook requires Parameters. All parameter that the Hook has have to be be supplied in the Call, you can't omit, or move any Parameters, the ordering is important. This rule does not apply to the Message parameter, if the Hook has it; the Message will be automatically provided by the Bot, you can just ignore it in the call. There are two kinds of suppling a parameter, a string literate, or another Hook call.
A String literal is started and closed with the °
Symbol. A Hook is just started like the first one.
If any Hook fails the Entire top Level Hook is replaced with {ERROR}
in the Command, so you should build robust logging into your Hooks, otherwise debugging will be much more difficult. This behaviour was chosen because it doesn't spam the chat with Error messages and Logs, but communicates, in a minimal form, that an error of some kind happened in this Command.
Das ist ein Test Command {follow {currentTime} {somepreset} °das ist ein beispiel text der im command landet°} danke fürs zuhören!
command text {hookExample °exampleString° {hook2}} weiterer text {hook3} command text ende
String part: | command text | { | hookExample | °exampleString° | { | hook2 | } | } | weiterer text | { | hook3 | } | command text ende |
Type: | text | hookStart | hookName | StringParameter | hookStart | hookName | hookEnd | hookEnd | text | hookStart | hookName | hookEnd | text |
Input: Das ist ein Beispiel Command! @{sender}: {currentTime}
Output: Das ist ein Beispiel Command! @orciument: 19:33:42