diff --git a/dist/api.js b/dist/api.js index 4713173..a9be464 100644 --- a/dist/api.js +++ b/dist/api.js @@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getPlayer = void 0; +exports.getPlayerInteraction = exports.getPlayer = void 0; const cheerio = __importStar(require("cheerio")); const https_1 = __importDefault(require("https")); //making long regex rather than splitting the string at ":" because regex would be easier to debug than logic in the case the website changes @@ -149,4 +149,16 @@ function getPlayer(name) { }); } exports.getPlayer = getPlayer; +function getPlayerInteraction(interaction) { + return __awaiter(this, void 0, void 0, function* () { + let username = interaction.options.getString('username', true); + interaction.deferReply(); + let data = yield getPlayer(username); + if (data === null) + yield interaction.reply('Unable to find user'); + else + yield interaction.reply('```\n' + JSON.stringify(data, null, 2) + '\n```'); + }); +} +exports.getPlayerInteraction = getPlayerInteraction; //await getPlayer('IanWhysp') diff --git a/src/api.ts b/src/api.ts index 012bde2..058fc8d 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,4 +1,5 @@ import * as cheerio from 'cheerio'; +import { CommandInteraction } from 'discord.js'; import { IncomingMessage } from 'http'; import http from 'https'; @@ -148,4 +149,15 @@ export async function getPlayer(name: string): Promise { return null; } +export async function getPlayerInteraction(interaction: CommandInteraction): Promise { + let username = interaction.options.getString('username', true); + interaction.deferReply(); + + let data = await getPlayer(username); + if (data === null) + await interaction.reply('Unable to find user'); + else + await interaction.reply('```\n'+JSON.stringify(data, null, 2)+'\n```'); +} + //await getPlayer('IanWhysp') \ No newline at end of file