1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
12 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
13 | };
|
14 | Object.defineProperty(exports, "__esModule", { value: true });
|
15 | const got_1 = __importDefault(require("got"));
|
16 | const configs_1 = require("../configs");
|
17 | const Player_1 = require("../utils/Player");
|
18 | exports.avatar = (name) => __awaiter(void 0, void 0, void 0, function* () {
|
19 | try {
|
20 | const response = yield got_1.default.get(`https://secure.runescape.com/m=avatar-rs/g=runescape/${encodeURI(name)}/chat.png`);
|
21 | return response.url;
|
22 | }
|
23 | catch (error) {
|
24 | console.log(error.response.body);
|
25 |
|
26 | }
|
27 | });
|
28 | exports.player = (name, gamemode = "normal") => __awaiter(void 0, void 0, void 0, function* () {
|
29 | if (typeof name !== "string") {
|
30 | return new Error("Username must be a string");
|
31 | }
|
32 | if (!["normal", "ironman", "hardcore"].includes(gamemode)) {
|
33 | return new Error("Invalid Gamemode, expected to see 'normal', 'ironman' or 'hardcore'");
|
34 | }
|
35 | try {
|
36 | const response = yield got_1.default(configs_1.runescape.hiscores.endpoints[gamemode], {
|
37 | searchParams: {
|
38 | player: encodeURI(name),
|
39 | },
|
40 | });
|
41 | return new Player_1.Player(name, response.body);
|
42 | }
|
43 | catch (error) {
|
44 | console.log(error.response.body);
|
45 |
|
46 | }
|
47 | });
|
48 |
|
\ | No newline at end of file |