UNPKG

growtopia-api

Version:

An unofficial Growtopia API to gather item informations, name matches, sprites and server status.

41 lines (40 loc) 1.87 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const moment = require("moment-timezone"); const axios_1 = require("axios"); function serverStatus() { return __awaiter(this, void 0, void 0, function* () { const growtopiaTime = moment().tz("America/New_York"); try { const res = yield axios_1.default.get("https://www.growtopiagame.com/detail").then(res => res.data); const playerCount = parseInt(res.online_user); const wotdURL = res.world_day_images.full_size; const wotdName = wotdURL.slice(wotdURL.lastIndexOf("/") + 1, wotdURL.lastIndexOf(".")).toUpperCase(); return { date: growtopiaTime.format("MMM Do"), time: growtopiaTime.format("h:mm:ss"), playerCount, wotdName, wotdURL, }; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw error === null || error === void 0 ? void 0 : error.response; } else { throw error; } } }); } exports.default = serverStatus;