removed dev comments
This commit is contained in:
30
dist/api.js
vendored
30
dist/api.js
vendored
@@ -25,30 +25,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.getPlayerInteraction = 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
|
|
||||||
//while names cant have spaces, the name slot in ogtitle could be shown as "No Player Name" which has spaces
|
|
||||||
const uniteApiRegex = {
|
const uniteApiRegex = {
|
||||||
//$1 = name, $2 = id
|
//$1 = name, $2 = id
|
||||||
ogtitle: /unite api - (.+) \((.*)\)/i,
|
ogtitle: /unite api - (.+) \((.*)\)/i,
|
||||||
//$1 = level, $2 = rank, $3 = elo/class (rest is found by splitting each line)
|
//$1 = level, $2 = rank, $3 = elo/class (rest is found by splitting each line)
|
||||||
ogdescription: [
|
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
|
* gets the html of the uniteApi page for the player
|
||||||
* @param name name of player
|
* @param name name of player
|
||||||
@@ -127,7 +112,7 @@ function readHTML(html) {
|
|||||||
{
|
{
|
||||||
//will be only text after "pokemon unite:"
|
//will be only text after "pokemon unite:"
|
||||||
let line = lines[0].split(':').slice(1).join(':').trim();
|
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
|
if (regex[0].test(line)) { //is master/has elo
|
||||||
let regexData = line.match(regex[0]);
|
let regexData = line.match(regex[0]);
|
||||||
if (!regexData || regexData.length < 4)
|
if (!regexData || regexData.length < 4)
|
||||||
@@ -161,15 +146,6 @@ function readHTML(html) {
|
|||||||
break;
|
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;
|
return foundData;
|
||||||
|
|||||||
34
src/api.ts
34
src/api.ts
@@ -3,19 +3,13 @@ import { CommandInteraction } from 'discord.js';
|
|||||||
import { IncomingMessage } from 'http';
|
import { IncomingMessage } from 'http';
|
||||||
import http from 'https';
|
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 = {
|
const uniteApiRegex = {
|
||||||
//$1 = name, $2 = id
|
//$1 = name, $2 = id
|
||||||
ogtitle: /unite api - (.+) \((.*)\)/i,
|
ogtitle: /unite api - (.+) \((.*)\)/i,
|
||||||
//$1 = level, $2 = rank, $3 = elo/class (rest is found by splitting each line)
|
//$1 = level, $2 = rank, $3 = elo/class (rest is found by splitting each line)
|
||||||
ogdescription: [
|
ogdescription: [ //just the first line
|
||||||
//line 1
|
/lv\.(\d+) (\w+) \((\d+)\)/i, //master
|
||||||
[
|
/lv\.(\d+) (\w+): class (\d+)/i //other
|
||||||
/lv\.(\d+) (\w+) \((\d+)\)/i, //master
|
|
||||||
/lv\.(\d+) (\w+): class (\d+)/i //other
|
|
||||||
],
|
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,16 +25,6 @@ type uniteApiData = {
|
|||||||
wins: string,
|
wins: string,
|
||||||
winrate: 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
|
* 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:"
|
//will be only text after "pokemon unite:"
|
||||||
let line = lines[0].split(':').slice(1).join(':').trim();
|
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
|
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];
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user