UNPKG

@jozsefsallai/userv

Version:
64 lines (63 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const node_iro_1 = require("node-iro"); const servers_1 = require("../lib/servers"); const check_1 = require("../lib/check"); class Check extends core_1.Command { getInputType(input) { if (input[0].toLowerCase() === 's' && parseInt(input.slice(1))) { return 'name'; } const splitInput = input.split('.'); if (splitInput.length !== 4) { return false; } for (let i = 0; i < splitInput.length; i++) { if (!parseInt(splitInput[i])) { return false; } } return 'ip'; } async getNameByIp(ip) { const allServers = await servers_1.default.get(); const targetServer = allServers.find((server) => server.ip === ip); if (!targetServer) { return null; } return targetServer.name; } async run() { const { args } = await this.parse(Check); const type = this.getInputType(args.server); if (!type) { return this.error('You have provided an invalid argument.'); } let checkName = args.server; if (type === 'ip') { const name = await this.getNameByIp(args.server); if (!name) { return this.error('The specified IP address could not be found in the database.'); } checkName = name; } const status = await (0, check_1.check)(checkName); if (!status.ok) { return this.error(status.message); } const output = status.up ? (0, node_iro_1.default)(`✔️ ${status.message}`, node_iro_1.green) : (0, node_iro_1.default)(`❌ ${status.message}`, node_iro_1.red); return this.log(output); } } exports.default = Check; Check.description = 'Check if a certain uCoz/Narod/uWeb server is available.'; Check.examples = [ `$ userv check s32 The server s32 (195.216.243.232) from the uCoz family is currently AVAILABLE.`, `$ userv check 195.216.243.232 The server s32 (195.216.243.232) from the uCoz family is currently AVAILABLE.`, ]; Check.args = [{ name: 'server', required: true }];