Templating
Templating in DaalBot
Section titled “Templating in DaalBot”DaalBot offers a powerful templating system that allows you to create dynamic and personalized messages for your server. By using placeholders and variables, you can customize responses based on user input, server data, and more.
Basic Syntax
Section titled “Basic Syntax”Templating in DaalBot uses the following syntax for placeholders %%{placeholder}%%. You can use these placeholders in various areas of DaalBot for things such as logging, welcome messages, and custom commands.
Available Placeholders
Section titled “Available Placeholders”The available placeholders may vary depending on the context in which you’re using them. For example, in welcome messages, you might have access to placeholders like %%{user.username}%% or %%{server.name}%%. Refer to the specific documentation for each feature to see which placeholders are supported.
Advanced Templating
Section titled “Advanced Templating”DaalBot also supports more advanced templating features, such as default values and conditional statements. This allows you to create more complex templates that can adapt based on certain conditions.
Default Values
Section titled “Default Values”You can provide default values for placeholders in case the data is not available. You can do this by using the following syntax: %%{placeholder|default_value}%%. If the placeholder data is not available, DaalBot will use the specified default value instead.
You can actually chain multiple defaults like so: %%{placeholder|default1|default2}%%. DaalBot will use the first available value in the chain. If you just want to use a string as a default, you can wrap it in quotes: %%{placeholder|"Default String"}%%.
Conditional Statements
Section titled “Conditional Statements”You can create simple conditional statements using the following syntax: %%{#condition[true_value][false_value]}%%. If the condition is met, DaalBot will use the first value; otherwise, it will use the second value. For example:
Welcome, %%{#user.isAdmin=true["Admin"]["User"]}%%!.
A condition is made up of three parts: the placeholder to check, the operator to use, and the value to compare against.
Placeholder Modification: You can convert a placeholder into lowercase by putting a _ and uppercase using -
Supported operators are below:
=Equal to (type coercion)==Strictly equal to (type and value)!=Not equal to (type coercion)!==Strictly not equal to (type and value)>Greater than<Less than>=Greater than or equal to<=Less than or equal to^=Starts with*=Contains (raw, be wary to not clbuttic yourself)~=Contains word$=Ends with
Nesting Placeholders
Section titled “Nesting Placeholders”You can simply put another placeholder inside a placeholder to nest them. For example: %%{user.%%{custom_field_name}%%}%%. This will first resolve the inner placeholder and then use that value to resolve the outer placeholder. You can nest as many levels deep as you want wherever you want, but remember that Just because you can, doesn’t mean you should! Nesting too deeply can make your templates hard to read and maintain. Also, be aware that excessive nesting may lead to performance issues as each level of nesting requires additional processing to resolve the placeholders correctly or even placeholder resolution failures if you cause a stack overflow, but that’s unlikely unless you go overboard.
Arrays
Section titled “Arrays”You can loop through an array using the Array*varName[expression] syntax, for example a leaderboard like so:
game.leaderboard*player[player.name]
Slicing
Section titled “Slicing”You can slice an array using the Array<start,end> so to get the first 10 entries that would be Array<0,9> (Note: Arrays start from 0). Like with JavaScript you can just use negative numbers so to instead get the last 10 items it would be Array<-1,-10>.
Accessing specific entries
Section titled “Accessing specific entries”Accessing array entries is as simple as it is in JavaScript simple do Array[index]
Escaping
Section titled “Escaping”You can escape sequences by doing the following:
%%{,}%%,|, &\- Put a\before[, &]- So long as it is within double quotes (") it shouldn’t be processed. To be clear it has to be directly under the quotes if it’s in a nested placeholder.
Examples
Section titled “Examples”Welcome message
Section titled “Welcome message”Welcome into the server%%{#_user.displayName^="[cool] "[" looking especially cool today"][""]}%%... %%{user.displayName}%%
Output:
Welcome to the server looking especially cool today... [Cool] PickleLord
Leaderboard
Section titled “Leaderboard”game.leaderboard<0,9>*player["%%{player.name}%%: %%{player.score}%%\n"]
Output:
Alice - 20Bob - 10Charlie - 5