utils
- builtin
- by Takaro
- Takaro >=0.0.1
- all
Built-in modules ship with Takaro — no import needed.
A collection of useful commands
Configuration 0
Settings you fill in when installing the module on a server.
This module takes no configuration.
Raw config schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false
} Raw UI schema
{} Commands 2
Chat commands players trigger in game.
-
ping
Replies with pong, useful for testing if the connection works.
Command source
import { data } from '@takaro/helpers'; async function main() { await data.player.pm('Pong!'); } await main(); //# sourceMappingURL=ping.js.map -
help
The text you are reading right now, displays information about commands.
Argument Type Default Help commandstring all The command to get help for, or "search" to search for commands searchTermstring none Search term to find commands (when first argument is "search") Command source
import { data, takaro, TakaroUserError, checkPermission } from '@takaro/helpers'; async function main() { const enabledModules = await takaro.module.moduleInstallationsControllerGetInstalledModules({ filters: { gameserverId: [data.gameServerId] }, }); const moduleCommands = await Promise.all(enabledModules.data.data.map(async (mod) => { // Check if the module itself is enabled if (!mod.systemConfig.enabled) { return []; } const installedVersion = await takaro.module.moduleVersionControllerGetModuleVersion(mod.versionId); const commands = installedVersion.data.data.commands; // Filter out disabled commands return commands.filter((command) => { const commandConfig = mod.systemConfig.commands && mod.systemConfig.commands[command.name]; return commandConfig && commandConfig.enabled; }); })); const allCommandsFlat = moduleCommands.flat(); // Filter commands based on player permissions const accessibleCommands = allCommandsFlat.filter((command) => { // If command has no required permissions, it's accessible to all if (!command.requiredPermissions || command.requiredPermissions.length === 0) { return true; } // Check if player has all required permissions return command.requiredPermissions.every((permission) => checkPermission(data.pog, permission)); }); if (data.arguments.command === 'search') { // Check if a search term was actually provided (not the default 'none') if (data.arguments.searchTerm === 'none') { throw new TakaroUserError('Please provide a search term. Usage: /help search <term>'); } // Search functionality const searchTerm = data.arguments.searchTerm.toLowerCase(); const matchingCommands = accessibleCommands.filter((command) => { // Check if command name contains search term const nameMatch = command.name.toLowerCase().includes(searchTerm); // Check if help text contains search term const helpTextMatch = command.helpText.toLowerCase().includes(searchTerm); return nameMatch || helpTextMatch; }); if (matchingCommands.length === 0) { await data.player.pm(`No commands found matching "${data.arguments.searchTerm}".`); } else { await data.player.pm(`Commands matching "${data.arguments.searchTerm}":`); await Promise.all(matchingCommands.map(async (command) => { await data.player.pm(`${command.name}: ${command.helpText}`); })); } } else if (data.arguments.command === 'all') { await data.player.pm('Available commands:'); if (accessibleCommands.length === 0) { await data.player.pm('No commands available to you.'); } else { await Promise.all(accessibleCommands.map(async (command) => { await data.player.pm(`${command.name}: ${command.helpText}`); })); } } else { const requestedCommand = allCommandsFlat.find((c) => { return c.name === data.arguments.command; }); if (requestedCommand) { // Check if player has permission to use this command const hasAccess = !requestedCommand.requiredPermissions || requestedCommand.requiredPermissions.length === 0 || requestedCommand.requiredPermissions.every((permission) => checkPermission(data.pog, permission)); if (!hasAccess) { throw new TakaroUserError(`You don't have permission to use the "${data.arguments.command}" command.`); } await data.player.pm(`${requestedCommand.name}: ${requestedCommand.helpText}`); } else { throw new TakaroUserError(`Unknown command "${data.arguments.command}", use this command without arguments to see all available commands.`); } } } await main(); //# sourceMappingURL=help.js.map