{
  "name": "utils",
  "author": "Takaro",
  "supportedGames": [
    "all"
  ],
  "takaroVersion": ">=0.0.1",
  "versions": [
    {
      "tag": "0.0.2",
      "description": "A collection of useful commands",
      "configSchema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"additionalProperties\":false}",
      "uiSchema": "{}",
      "commands": [
        {
          "name": "ping",
          "trigger": "ping",
          "helpText": "Replies with pong, useful for testing if the connection works.",
          "function": "import { data } from '@takaro/helpers';\nasync function main() {\n    await data.player.pm('Pong!');\n}\nawait main();\n//# sourceMappingURL=ping.js.map",
          "arguments": []
        },
        {
          "name": "help",
          "trigger": "help",
          "helpText": "The text you are reading right now, displays information about commands.",
          "function": "import { data, takaro, TakaroUserError, checkPermission } from '@takaro/helpers';\nasync function main() {\n    const enabledModules = await takaro.module.moduleInstallationsControllerGetInstalledModules({\n        filters: { gameserverId: [data.gameServerId] },\n    });\n    const moduleCommands = await Promise.all(enabledModules.data.data.map(async (mod) => {\n        // Check if the module itself is enabled\n        if (!mod.systemConfig.enabled) {\n            return [];\n        }\n        const installedVersion = await takaro.module.moduleVersionControllerGetModuleVersion(mod.versionId);\n        const commands = installedVersion.data.data.commands;\n        // Filter out disabled commands\n        return commands.filter((command) => {\n            const commandConfig = mod.systemConfig.commands && mod.systemConfig.commands[command.name];\n            return commandConfig && commandConfig.enabled;\n        });\n    }));\n    const allCommandsFlat = moduleCommands.flat();\n    // Filter commands based on player permissions\n    const accessibleCommands = allCommandsFlat.filter((command) => {\n        // If command has no required permissions, it's accessible to all\n        if (!command.requiredPermissions || command.requiredPermissions.length === 0) {\n            return true;\n        }\n        // Check if player has all required permissions\n        return command.requiredPermissions.every((permission) => checkPermission(data.pog, permission));\n    });\n    if (data.arguments.command === 'search') {\n        // Check if a search term was actually provided (not the default 'none')\n        if (data.arguments.searchTerm === 'none') {\n            throw new TakaroUserError('Please provide a search term. Usage: /help search <term>');\n        }\n        // Search functionality\n        const searchTerm = data.arguments.searchTerm.toLowerCase();\n        const matchingCommands = accessibleCommands.filter((command) => {\n            // Check if command name contains search term\n            const nameMatch = command.name.toLowerCase().includes(searchTerm);\n            // Check if help text contains search term\n            const helpTextMatch = command.helpText.toLowerCase().includes(searchTerm);\n            return nameMatch || helpTextMatch;\n        });\n        if (matchingCommands.length === 0) {\n            await data.player.pm(`No commands found matching \"${data.arguments.searchTerm}\".`);\n        }\n        else {\n            await data.player.pm(`Commands matching \"${data.arguments.searchTerm}\":`);\n            await Promise.all(matchingCommands.map(async (command) => {\n                await data.player.pm(`${command.name}: ${command.helpText}`);\n            }));\n        }\n    }\n    else if (data.arguments.command === 'all') {\n        await data.player.pm('Available commands:');\n        if (accessibleCommands.length === 0) {\n            await data.player.pm('No commands available to you.');\n        }\n        else {\n            await Promise.all(accessibleCommands.map(async (command) => {\n                await data.player.pm(`${command.name}: ${command.helpText}`);\n            }));\n        }\n    }\n    else {\n        const requestedCommand = allCommandsFlat.find((c) => {\n            return c.name === data.arguments.command;\n        });\n        if (requestedCommand) {\n            // Check if player has permission to use this command\n            const hasAccess = !requestedCommand.requiredPermissions ||\n                requestedCommand.requiredPermissions.length === 0 ||\n                requestedCommand.requiredPermissions.every((permission) => checkPermission(data.pog, permission));\n            if (!hasAccess) {\n                throw new TakaroUserError(`You don't have permission to use the \"${data.arguments.command}\" command.`);\n            }\n            await data.player.pm(`${requestedCommand.name}: ${requestedCommand.helpText}`);\n        }\n        else {\n            throw new TakaroUserError(`Unknown command \"${data.arguments.command}\", use this command without arguments to see all available commands.`);\n        }\n    }\n}\nawait main();\n//# sourceMappingURL=help.js.map",
          "arguments": [
            {
              "name": "command",
              "type": "string",
              "helpText": "The command to get help for, or \"search\" to search for commands",
              "defaultValue": "all",
              "position": 0
            },
            {
              "name": "searchTerm",
              "type": "string",
              "helpText": "Search term to find commands (when first argument is \"search\")",
              "defaultValue": "none",
              "position": 1
            }
          ]
        }
      ],
      "hooks": [],
      "cronJobs": [],
      "functions": [],
      "permissions": []
    }
  ]
}