From 50c297bfeae2c8daff266e6c28125ae78b2727a3 Mon Sep 17 00:00:00 2001 From: ashley zomo Date: Mon, 31 Jan 2022 17:07:59 -0600 Subject: [PATCH] removed dev comments --- dist/api.js | 30 +++--------------------------- src/api.ts | 34 ++++------------------------------ 2 files changed, 7 insertions(+), 57 deletions(-) diff --git a/dist/api.js b/dist/api.js index 9024359..935f4fe 100644 --- a/dist/api.js +++ b/dist/api.js @@ -25,30 +25,15 @@ Object.defineProperty(exports, "__esModule", { value: true }); 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 -//while names cant have spaces, the name slot in ogtitle could be shown as "No Player Name" which has spaces const uniteApiRegex = { //$1 = name, $2 = id ogtitle: /unite api - (.+) \((.*)\)/i, //$1 = level, $2 = rank, $3 = elo/class (rest is found by splitting each line) ogdescription: [ - //line 1 - [ - /lv\.(\d+) (\w+) \((\d+)\)/i, - /lv\.(\d+) (\w+): class (\d+)/i //other - ], + /lv\.(\d+) (\w+) \((\d+)\)/i, + /lv\.(\d+) (\w+): class (\d+)/i //other ] }; -/* -og:title -Unite API - IanWhysp (X188GF7) - -og:description -Pokémon Unite : Lv.40 Master (1741) - Battles : 1089 - Wins : 576 - Win Rate : 52% -*/ /** * gets the html of the uniteApi page for the player * @param name name of player @@ -127,7 +112,7 @@ function readHTML(html) { { //will be only text after "pokemon unite:" let line = lines[0].split(':').slice(1).join(':').trim(); - let regex = uniteApiRegex.ogdescription[0]; + let regex = uniteApiRegex.ogdescription; if (regex[0].test(line)) { //is master/has elo let regexData = line.match(regex[0]); if (!regexData || regexData.length < 4) @@ -161,15 +146,6 @@ function readHTML(html) { break; } }); - /*let data = uniteApiRegex.ogdescription.exec(attr.content); - if (data !== null && data.length >= 7) { - foundData.level = data[1]; - foundData.rank = data[2]; - foundData.elo = data[3]; - foundData.battles = data[4]; - foundData.wins = data[5]; - foundData.winrate = data[6]; - }*/ } }); return foundData; diff --git a/src/api.ts b/src/api.ts index db16548..4e5d1e1 100644 --- a/src/api.ts +++ b/src/api.ts @@ -3,19 +3,13 @@ import { CommandInteraction } from 'discord.js'; import { IncomingMessage } from 'http'; import http from '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 -//while names cant have spaces, the name slot in ogtitle could be shown as "No Player Name" which has spaces const uniteApiRegex = { //$1 = name, $2 = id ogtitle: /unite api - (.+) \((.*)\)/i, //$1 = level, $2 = rank, $3 = elo/class (rest is found by splitting each line) - ogdescription: [ - //line 1 - [ - /lv\.(\d+) (\w+) \((\d+)\)/i, //master - /lv\.(\d+) (\w+): class (\d+)/i //other - ], - + ogdescription: [ //just the first line + /lv\.(\d+) (\w+) \((\d+)\)/i, //master + /lv\.(\d+) (\w+): class (\d+)/i //other ] } @@ -31,16 +25,6 @@ type uniteApiData = { wins: string, winrate: string } -/* -og:title -Unite API - IanWhysp (X188GF7) - -og:description -Pokémon Unite : Lv.40 Master (1741) - Battles : 1089 - Wins : 576 - Win Rate : 52% -*/ /** * gets the html of the uniteApi page for the player @@ -142,7 +126,7 @@ function readHTML(html: string): uniteApiData { //will be only text after "pokemon unite:" let line = lines[0].split(':').slice(1).join(':').trim(); - let regex = uniteApiRegex.ogdescription[0]; + let regex = uniteApiRegex.ogdescription; if (regex[0].test(line)) { //is master/has elo @@ -193,16 +177,6 @@ function readHTML(html: string): uniteApiData { }); - /*let data = uniteApiRegex.ogdescription.exec(attr.content); - if (data !== null && data.length >= 7) { - foundData.level = data[1]; - foundData.rank = data[2]; - foundData.elo = data[3]; - foundData.battles = data[4]; - foundData.wins = data[5]; - foundData.winrate = data[6]; - }*/ - } })