function to receive interaction

This commit is contained in:
2022-01-27 18:48:37 -06:00
parent 0a9918a508
commit a461fad0c1
2 changed files with 25 additions and 1 deletions

14
dist/api.js vendored
View File

@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.getPlayer = void 0; exports.getPlayerInteraction = exports.getPlayer = void 0;
const cheerio = __importStar(require("cheerio")); const cheerio = __importStar(require("cheerio"));
const https_1 = __importDefault(require("https")); 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 //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; 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') //await getPlayer('IanWhysp')

View File

@@ -1,4 +1,5 @@
import * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { CommandInteraction } from 'discord.js';
import { IncomingMessage } from 'http'; import { IncomingMessage } from 'http';
import http from 'https'; import http from 'https';
@@ -148,4 +149,15 @@ export async function getPlayer(name: string): Promise<uniteApiData|null> {
return null; return null;
} }
export async function getPlayerInteraction(interaction: CommandInteraction): Promise<void> {
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') //await getPlayer('IanWhysp')