UNPKG

mcapitr

Version:

A Node.js wrapper for the MCAPI.TR service, which provides various Minecraft server information

54 lines (47 loc) 1.67 kB
class MCAPITR { constructor() { this.baseURL = "https://mcapi.tr/api"; } /** * Checks the status of a Minecraft server * @param {string} address - Server address (IP or domain) * @param {Object} options - Optional parameters * @param {boolean} [options.legacy=false] - For servers older than 1.7.2 * @param {boolean} [options.bedrock=false] - For Bedrock edition servers * @returns {Promise} Server status */ async serverStatus(address, options = {}) { try { const params = new URLSearchParams(options); const response = await fetch( `${this.baseURL}/status/${address}?${params}` ); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } catch (error) { throw new Error(`Failed to get server status: ${error.message}`); } } /** * Gets the favicon URL of a Minecraft server * @param {string} address - Server address (IP or domain) * @param {Object} options - Optional parameters * @param {boolean} [options.legacy=false] - For servers older than 1.7.2 * @returns {string} Server favicon URL */ serverIcon(address, options = {}) { const params = new URLSearchParams({ address, ...options }); return `${this.baseURL}/icon/dynamic?${params}`; } /** * Gets the MOTD banner URL of a Minecraft server * @param {string} address - Server address (IP or domain) * @returns {string} Server banner URL */ serverBanner(address) { return `${this.baseURL}/banner/${address}`; } } module.exports = MCAPITR;