### Create New Server with ApplicationClient Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Illustrates creating a new server with specified configurations like name, description, owner, allocation, limits, and feature limits using ServerBuilder. ```typescript const newServer = new ServerBuilder() .setName('Hello world!') .setDescription('This is my fancy game server') .setOwnerId(1) // The user id for the owner .setAllocationId(1) // The allocation id for the server .setLimits({ memory: 512, swap: 0, disk: 5120, io: 500, cpu: 100, threads: undefined, }) .setFeatureLimits({ databases: 1, backups: 5, allocations: 2, }); // TODO Env setup (variables, egg, etc.) await applicationClient.createServer(newServer).then((server) => { console.log('The server is currently ' + server.status); }); ``` -------------------------------- ### Initialize ApplicationClient Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Demonstrates how to initialize the ApplicationClient with API key and panel URL for managing Pterodactyl resources. ```typescript import { ApplicationClient } from 'pterodactyl.ts'; const applicationClient = new ApplicationClient({ apikey: process.env.PTERODACTYL_API_KEY, panel: process.env.PTERODACTYL_PANEL, }); ``` -------------------------------- ### Create New User with ApplicationClient Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Shows how to build and create a new user using the UserBuilder and ApplicationClient, setting essential user details. ```typescript const newUser = new UserBuilder() .setEmail('mail@example.de') .setFirstName('Max') .setLastName('Mustermann') .setUsername('exampleGamer420') .setPassword(process.env.MAX_PASSWORD); await applicationClient.createUser(newUser); ``` -------------------------------- ### Initialize UserClient Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Shows how to initialize the UserClient with API key and panel URL for user-specific operations. ```typescript import { UserClient } from 'pterodactyl.ts'; const userClient = new UserClient({ apikey: process.env.PTERODACTYL_API_KEY, panel: process.env.PTERODACTYL_PANEL, }); ``` -------------------------------- ### Create Server Backup with UserClient Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Shows how to create a new server backup with custom options like name, locked status, and ignored directories using BackupBuilder. ```typescript const newBackup = new BackupBuilder() .setName('Backup of server') .setLocked(true) .setIgnored(['logs', 'cache']); server.createBackup(newBackup); ``` -------------------------------- ### File Operations with UserClient Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Demonstrates uploading, reading, downloading, and compressing files on a server using the UserClient. ```typescript import fs from 'fs'; const server = await userClient.getServer('someId'); // Accepts a filepath, buffer or blob await server.uploadFile('/', 'hello.world', 'hello.world'); server.getFiles('/').then((files) => { console.log('Files in "/": ' + files.map((file) => file.name).join(', ')); const helloWorldFile = files.find((file) => file.name === 'hello.world'); if (!helloWorldFile) { console.error('File not found'); return; } helloWorldFile.getContent().then((contents) => { console.log('Contents of hello.world: ' + contents); }); helloWorldFile.downloadUrl().then((url) => { console.log('You can download hello.world via: ' + url); }); helloWorldFile.compress().then(async (archive) => { console.log('Compressed hello.world'); await archive.downloadStream().then((stream) => { stream.pipe(fs.createWriteStream('hello.world.tar.gz')); }); archive.delete(); }); }); ``` -------------------------------- ### Create New Allocations with ApplicationClient Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Demonstrates how to create new server allocations for a specific node, including IP, alias, and port ranges. ```typescript const newAllocation = new AllocationBuilder() .setIp('1.2.3.4') .setAlias('example.com') .addPort(25565) .addPort('3000-3005') .addPorts([25566, 25567]); await applicationClient.getNode(0).then((node) => { node.createAllocation(newAllocation); }); ``` -------------------------------- ### Create Server Schedules and Tasks in TypeScript Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Illustrates how to build and create server schedules with multiple tasks using the Pterodactyl TypeScript library. It covers defining tasks with different actions (backup, command, power) and configuring schedule details like name, time, and recurrence. ```typescript const newTask = new ScheduleTaskBuilder() .setAction('backup') .setContinueOnFailure(true) .setPayload('cache, logs'); // For backups the payload are the ignored files const newTask2 = new ScheduleTaskBuilder() .setAction('command') .setPayload('say Backup completed!'); // For commands the payload contains the command const newTask3 = new ScheduleTaskBuilder() .setAction('power') .setPayload(SERVER_SIGNAL.RESTART); // For power actions the payload contains the server signal const newSchedule = new ScheduleBuilder() .setActive(true) .setName('Daily Backup') .setMinute('0') .setHour('0') .setMonth('*') .setDayOfMonth('*') .setDayOfWeek('*') .setOnlyWhenOnline(false); server.createSchedule(newSchedule).then(async (schedule) => { await schedule.createTask(newTask); await schedule.createTask(newTask2); await schedule.createTask(newTask3); }); ``` -------------------------------- ### Manage Server Subusers with TypeScript Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Demonstrates how to create, update, and delete subusers for a server using the Pterodactyl TypeScript library. It involves building subuser data with permissions and interacting with server objects. Dependencies include the `pterodactyl.ts` library and server instances. ```typescript import { USER_PERMISSION } from 'pterodactyl.ts'; const newSubUser = new SubUserBuilder() .setEmail('mail@example.de') .setPermissions([USER_PERMISSION.ACTIVITY_READ, USER_PERMISSION.CONTROL_RESTART]) .addPermission(USER_PERMISSION.CONTROL_CONSOLE); await server.createSubuser(newSubUser).then(async (subUser) => { await subUser.updatePermissions([USER_PERMISSION.CONTROL_START, USER_PERMISSION.CONTROL_STOP]); console.log('The user has ' + subUser.permissions.length + ' permissions'); await subUser.delete(); }); ``` -------------------------------- ### Establish Server Console Connection Source: https://github.com/bothimtv/pterodactyl.ts/blob/main/README.md Connects to a server's console to receive live logs and send commands. Includes handling console output and disconnecting. ```typescript // Get a specific server from your account import { SocketEvent } from 'pterodactyl.ts'; const server = await userClient.getServer('someId'); /** * Console connection */ // The authentication is done automatically const socket = await server.getConsoleSocket(); await socket.connect(true); // Get the logs, when the server is offline you'll receive a generated log message const logs = await socket.getLogs(); // Get live console logging socket.on(SocketEvent.CONSOLE_OUTPUT, (log) => { console.log(log); }); socket.disconnect(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.