function to receive interaction
This commit is contained in:
14
dist/api.js
vendored
14
dist/api.js
vendored
@@ -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')
|
||||
|
||||
12
src/api.ts
12
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<uniteApiData|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')
|
||||
Reference in New Issue
Block a user