Compare commits
2 Commits
5167a25626
...
5ce68086b8
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ce68086b8 | |||
| 5ee97cfd08 |
111
dist/api.js
vendored
111
dist/api.js
vendored
@@ -18,15 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
@@ -38,11 +29,15 @@ const https_1 = __importDefault(require("https"));
|
||||
//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 - ([\w\d ]+) \((.*)\)/i,
|
||||
//$1 = level, $2 = rank, $3 = elo, $4 = battles, $5 = wins, $6 = win rate
|
||||
ogdescription: /pokémon unite : lv\.(\d+) (\w+) \((\d+)\)\n battles : (\d+)\n Wins : (\d+)\n win rate : (\d+)%/i,
|
||||
//for non-masters (no elo)
|
||||
//ogdescription: /pokémon unite : lv\.(\d+) (\w+): class (\d+) *\n battles : (\d+) *\n wins : (\d+) *\n win rate : (\d+)%/i,
|
||||
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
|
||||
],
|
||||
]
|
||||
};
|
||||
/*
|
||||
og:title
|
||||
@@ -60,7 +55,7 @@ Pokémon Unite : Lv.40 Master (1741)
|
||||
* @returns the html of the page through a promise (rejects if the page status is not 200)
|
||||
*/
|
||||
function getHTML(name) {
|
||||
name = name.replace(/[^\w\d]/g, '');
|
||||
//name = name.replace(/[^\w\d]/g, '');
|
||||
return new Promise((resolve, reject) => {
|
||||
const init = {
|
||||
host: 'uniteapi.dev',
|
||||
@@ -96,13 +91,14 @@ function readHTML(html) {
|
||||
id: "",
|
||||
level: "",
|
||||
rank: "",
|
||||
elo: "",
|
||||
elo: null,
|
||||
class: null,
|
||||
battles: "",
|
||||
wins: "",
|
||||
winrate: ""
|
||||
};
|
||||
//filter down to just ones named "og:..."
|
||||
metaElems = metaElems.filter(el => { var _a; return (_a = el.attribs.property) === null || _a === void 0 ? void 0 : _a.startsWith('og:'); });
|
||||
metaElems = metaElems.filter(el => el.attribs.property?.startsWith('og:'));
|
||||
metaElems.forEach(el => {
|
||||
let attr = el.attribs;
|
||||
if (attr.property === 'og:title') {
|
||||
@@ -113,7 +109,62 @@ function readHTML(html) {
|
||||
}
|
||||
}
|
||||
else if (attr.property === 'og:description') {
|
||||
let data = uniteApiRegex.ogdescription.exec(attr.content);
|
||||
//all lines
|
||||
let lines = attr.content.split('\n').map(l => l.trim()), extraLines = [];
|
||||
//ensure first line is correct
|
||||
while (lines.length && !/pok.mon unite/i.test(lines[0])) {
|
||||
let line = lines.shift();
|
||||
if (line)
|
||||
extraLines.push(line);
|
||||
}
|
||||
if (!lines.length)
|
||||
throw 'Unable to read data, please try again';
|
||||
//bring the first lines removed back into the data
|
||||
lines = [
|
||||
...lines,
|
||||
...extraLines.filter(d => d)
|
||||
];
|
||||
//line 1
|
||||
//Pokémon Unite : Lv.40 Veteran: Class 3
|
||||
//Pokémon Unite : Lv.40 Master (1741)
|
||||
{
|
||||
//will be only text after "pokemon unite:"
|
||||
let line = lines[0].split(':').slice(1).join(':').trim();
|
||||
let regex = uniteApiRegex.ogdescription[0];
|
||||
if (regex[0].test(line)) { //is master/has elo
|
||||
let regexData = line.match(regex[0]);
|
||||
if (!regexData || regexData.length < 4)
|
||||
throw 'Unable to read data, please try again';
|
||||
foundData.level = regexData[1];
|
||||
foundData.rank = regexData[2];
|
||||
foundData.elo = regexData[3];
|
||||
}
|
||||
else { //is not master/has a class
|
||||
let regexData = line.match(regex[1]);
|
||||
if (!regexData || regexData.length < 4)
|
||||
throw 'Unable to read data, please try again';
|
||||
foundData.level = regexData[1];
|
||||
foundData.rank = regexData[2];
|
||||
foundData.class = regexData[3];
|
||||
}
|
||||
}
|
||||
lines.shift();
|
||||
//rest of lines
|
||||
lines.forEach(line => {
|
||||
let split = line.split(':').map(l => l.trim()), key = split[0].toLowerCase().replace(/[^\w]/g, ''), value = split[1];
|
||||
switch (key) {
|
||||
case 'battles':
|
||||
foundData.battles = value;
|
||||
break;
|
||||
case 'wins':
|
||||
foundData.wins = value;
|
||||
break;
|
||||
case 'winrate':
|
||||
foundData.winrate = value;
|
||||
break;
|
||||
}
|
||||
});
|
||||
/*let data = uniteApiRegex.ogdescription.exec(attr.content);
|
||||
if (data !== null && data.length >= 7) {
|
||||
foundData.level = data[1];
|
||||
foundData.rank = data[2];
|
||||
@@ -121,7 +172,7 @@ function readHTML(html) {
|
||||
foundData.battles = data[4];
|
||||
foundData.wins = data[5];
|
||||
foundData.winrate = data[6];
|
||||
}
|
||||
}*/
|
||||
}
|
||||
});
|
||||
return foundData;
|
||||
@@ -141,26 +192,26 @@ function verifyData(data) {
|
||||
* @param name name of player
|
||||
* @returns player data
|
||||
*/
|
||||
function getPlayer(name) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let html = yield getHTML(name);
|
||||
async function getPlayer(name) {
|
||||
let html = await getHTML(name);
|
||||
let data = readHTML(html);
|
||||
if (verifyData(data))
|
||||
return data;
|
||||
return null;
|
||||
});
|
||||
}
|
||||
exports.getPlayer = getPlayer;
|
||||
function getPlayerInteraction(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
/**
|
||||
* calls getPlayer() with the name from the interaction
|
||||
* @param interaction discord interaction
|
||||
*/
|
||||
async function getPlayerInteraction(interaction) {
|
||||
let username = interaction.options.getString('username', true);
|
||||
yield interaction.deferReply();
|
||||
let data = yield getPlayer(username);
|
||||
await interaction.deferReply();
|
||||
let data = await getPlayer(username);
|
||||
if (data === null)
|
||||
yield interaction.editReply('Unable to find user');
|
||||
await interaction.editReply('Unable to find user');
|
||||
else
|
||||
yield interaction.editReply('```\n' + JSON.stringify(data, null, 2) + '\n```');
|
||||
});
|
||||
await interaction.editReply('```\n' + JSON.stringify(data, null, 2) + '\n```');
|
||||
}
|
||||
exports.getPlayerInteraction = getPlayerInteraction;
|
||||
//await getPlayer('IanWhysp')
|
||||
|
||||
16
dist/discord.js
vendored
16
dist/discord.js
vendored
@@ -1,17 +1,9 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.registerCommands = void 0;
|
||||
const rest_1 = require("@discordjs/rest");
|
||||
const v9_1 = require("discord-api-types/v9");
|
||||
// list of commands to register with discord
|
||||
const commands = [
|
||||
{
|
||||
name: 'queue',
|
||||
@@ -60,20 +52,18 @@ const commands = [
|
||||
* @param clientId discord bot client id
|
||||
* @param guildIds discord guild id(s)
|
||||
*/
|
||||
function registerCommands(token, clientId, guildIds) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
async function registerCommands(token, clientId, guildIds) {
|
||||
const rest = new rest_1.REST({ version: '9' }).setToken(token);
|
||||
if (typeof guildIds === 'string')
|
||||
guildIds = [guildIds];
|
||||
for (let i = 0; i < guildIds.length; i++) {
|
||||
try {
|
||||
yield rest.put(v9_1.Routes.applicationGuildCommands(clientId, guildIds[i]), { body: commands });
|
||||
await rest.put(v9_1.Routes.applicationGuildCommands(clientId, guildIds[i]), { body: commands });
|
||||
console.log(`[${guildIds[i]}] registered command`);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.registerCommands = registerCommands;
|
||||
|
||||
28
dist/index.js
vendored
28
dist/index.js
vendored
@@ -18,15 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const discord_js_1 = require("discord.js");
|
||||
const fs = __importStar(require("fs"));
|
||||
@@ -34,33 +25,36 @@ const api_1 = require("./api");
|
||||
const discord_1 = require("./discord");
|
||||
const queue_1 = require("./queue");
|
||||
const CLIENT = new discord_js_1.Client({ intents: [discord_js_1.Intents.FLAGS.GUILDS] });
|
||||
//init logs with a timestamp
|
||||
console.log(new Date().toISOString() + '\n\n');
|
||||
//get token
|
||||
if (!fs.existsSync('./token')) {
|
||||
fs.writeFileSync('./token', '');
|
||||
console.error('Missing Discord Token, please enter the bot token into the token file');
|
||||
process.exit(1);
|
||||
}
|
||||
const TOKEN = fs.readFileSync('./token').toString();
|
||||
//discord connections
|
||||
CLIENT.on('ready', client => {
|
||||
console.log(`Logged in as ${client.user.tag}`);
|
||||
client.guilds.fetch().then(guilds => (0, discord_1.registerCommands)(TOKEN, client.user.id, guilds.map(g => g.id)));
|
||||
});
|
||||
CLIENT.on('interactionCreate', (interaction) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
CLIENT.on('interactionCreate', async (interaction) => {
|
||||
if (!interaction.isCommand())
|
||||
return;
|
||||
try {
|
||||
if (interaction.commandName === 'queue')
|
||||
yield (0, queue_1.createQueue)(interaction);
|
||||
await (0, queue_1.createQueue)(interaction);
|
||||
else if (interaction.commandName === 'join')
|
||||
yield (0, queue_1.joinQueue)(interaction);
|
||||
await (0, queue_1.joinQueue)(interaction);
|
||||
else if (interaction.commandName === 'leave')
|
||||
yield (0, queue_1.leaveQueue)(interaction);
|
||||
await (0, queue_1.leaveQueue)(interaction);
|
||||
else if (interaction.commandName === 'ready')
|
||||
yield (0, queue_1.readyQueue)(interaction);
|
||||
await (0, queue_1.readyQueue)(interaction);
|
||||
else if (interaction.commandName === 'queueinfo')
|
||||
yield (0, queue_1.queueInfo)(interaction);
|
||||
await (0, queue_1.queueInfo)(interaction);
|
||||
else if (interaction.commandName === 'elo')
|
||||
yield (0, api_1.getPlayerInteraction)(interaction);
|
||||
await (0, api_1.getPlayerInteraction)(interaction);
|
||||
}
|
||||
catch (e) {
|
||||
if (typeof e === 'string') {
|
||||
@@ -72,5 +66,5 @@ CLIENT.on('interactionCreate', (interaction) => __awaiter(void 0, void 0, void 0
|
||||
else
|
||||
console.error(e);
|
||||
}
|
||||
}));
|
||||
});
|
||||
CLIENT.login(TOKEN);
|
||||
|
||||
39
dist/queue.js
vendored
39
dist/queue.js
vendored
@@ -1,13 +1,4 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.queueInfo = exports.readyQueue = exports.leaveQueue = exports.joinQueue = exports.createQueue = void 0;
|
||||
const discord_js_1 = require("discord.js");
|
||||
@@ -43,8 +34,7 @@ function getInfo(interaction) {
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be created
|
||||
*/
|
||||
function createQueue(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
async function createQueue(interaction) {
|
||||
let { channelId } = interaction, member = getMember(interaction), teamsize = interaction.options.getInteger('teamsize', true);
|
||||
if (QUEUE.has(channelId))
|
||||
throw 'There is already an active queue in this channel, type `/join` to join'; //and you are already in it
|
||||
@@ -55,8 +45,7 @@ function createQueue(interaction) {
|
||||
initiator: member,
|
||||
teamsize: teamsize
|
||||
});
|
||||
yield interaction.reply(`Queue for teams of ${teamsize} has been created, and you have joined`);
|
||||
});
|
||||
await interaction.reply(`Queue for teams of ${teamsize} has been created, and you have joined`);
|
||||
}
|
||||
exports.createQueue = createQueue;
|
||||
/**
|
||||
@@ -64,15 +53,13 @@ exports.createQueue = createQueue;
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be joined
|
||||
*/
|
||||
function joinQueue(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
async function joinQueue(interaction) {
|
||||
let member = getMember(interaction), info = getInfo(interaction);
|
||||
if (info.players.map(m => m.id).includes(member.id))
|
||||
throw 'You are already in the active queue';
|
||||
info.players.push(member);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
yield interaction.reply('Joined the queue');
|
||||
});
|
||||
await interaction.reply('Joined the queue');
|
||||
}
|
||||
exports.joinQueue = joinQueue;
|
||||
/**
|
||||
@@ -80,15 +67,13 @@ exports.joinQueue = joinQueue;
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be left
|
||||
*/
|
||||
function leaveQueue(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
async function leaveQueue(interaction) {
|
||||
let member = getMember(interaction), info = getInfo(interaction);
|
||||
if (!info.players.map(m => m.id).includes(member.id))
|
||||
throw 'You aren\'t in the active queue';
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
yield interaction.reply('Left the queue');
|
||||
});
|
||||
await interaction.reply('Left the queue');
|
||||
}
|
||||
exports.leaveQueue = leaveQueue;
|
||||
/**
|
||||
@@ -96,8 +81,7 @@ exports.leaveQueue = leaveQueue;
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be readied
|
||||
*/
|
||||
function readyQueue(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
async function readyQueue(interaction) {
|
||||
let member = getMember(interaction), info = getInfo(interaction), { initiator } = info;
|
||||
if (member.id !== initiator.id)
|
||||
throw 'Only the queue initiator can ready the queue';
|
||||
@@ -117,8 +101,7 @@ function readyQueue(interaction) {
|
||||
team.forEach(m => str.push(` ${m.user.tag}`));
|
||||
teamsStr.push(str.join('\n'));
|
||||
});
|
||||
yield interaction.reply('```\n' + teamsStr.join('\n\n') + '\n```');
|
||||
});
|
||||
await interaction.reply('```\n' + teamsStr.join('\n\n') + '\n```');
|
||||
}
|
||||
exports.readyQueue = readyQueue;
|
||||
/**
|
||||
@@ -126,14 +109,12 @@ exports.readyQueue = readyQueue;
|
||||
* @param interaction
|
||||
* @throws string message if it cannot be read
|
||||
*/
|
||||
function queueInfo(interaction) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
async function queueInfo(interaction) {
|
||||
let info = getInfo(interaction);
|
||||
yield interaction.reply('```' + `
|
||||
await interaction.reply('```' + `
|
||||
players: ${info.players.map(p => p.user.tag).join('\n ')}
|
||||
initiator: ${info.initiator.user.tag}
|
||||
teamsize: ${info.teamsize}
|
||||
` + '```');
|
||||
});
|
||||
}
|
||||
exports.queueInfo = queueInfo;
|
||||
|
||||
107
src/api.ts
107
src/api.ts
@@ -7,11 +7,16 @@ import http from 'https';
|
||||
//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 - ([\w\d ]+) \((.*)\)/i,
|
||||
//$1 = level, $2 = rank, $3 = elo, $4 = battles, $5 = wins, $6 = win rate
|
||||
ogdescription: /pokémon unite : lv\.(\d+) (\w+) \((\d+)\)\n battles : (\d+)\n Wins : (\d+)\n win rate : (\d+)%/i,
|
||||
//for non-masters (no elo)
|
||||
//ogdescription: /pokémon unite : lv\.(\d+) (\w+): class (\d+) *\n battles : (\d+) *\n wins : (\d+) *\n win rate : (\d+)%/i,
|
||||
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
|
||||
],
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
type uniteApiData = {
|
||||
@@ -20,7 +25,8 @@ type uniteApiData = {
|
||||
|
||||
level: string,
|
||||
rank: string,
|
||||
elo: string,
|
||||
class: string|null,
|
||||
elo: string|null,
|
||||
battles: string,
|
||||
wins: string,
|
||||
winrate: string
|
||||
@@ -43,7 +49,7 @@ Pokémon Unite : Lv.40 Master (1741)
|
||||
*/
|
||||
function getHTML(name: string): Promise<string> {
|
||||
|
||||
name = name.replace(/[^\w\d]/g, '');
|
||||
//name = name.replace(/[^\w\d]/g, '');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -91,7 +97,8 @@ function readHTML(html: string): uniteApiData {
|
||||
|
||||
level: "",
|
||||
rank: "",
|
||||
elo: "",
|
||||
elo: null,
|
||||
class: null,
|
||||
battles: "",
|
||||
wins: "",
|
||||
winrate: ""
|
||||
@@ -110,7 +117,86 @@ function readHTML(html: string): uniteApiData {
|
||||
foundData.id = data[2];
|
||||
}
|
||||
} else if (attr.property === 'og:description') {
|
||||
let data = uniteApiRegex.ogdescription.exec(attr.content);
|
||||
|
||||
//all lines
|
||||
let lines = attr.content.split('\n').map(l => l.trim()),
|
||||
extraLines: string[] = [];
|
||||
|
||||
//ensure first line is correct
|
||||
while (lines.length && !/pok.mon unite/i.test(lines[0])) {
|
||||
let line = lines.shift();
|
||||
if (line)
|
||||
extraLines.push(line);
|
||||
}
|
||||
|
||||
if (!lines.length)
|
||||
throw 'Unable to read data, please try again';
|
||||
|
||||
//bring the first lines removed back into the data
|
||||
lines = [
|
||||
...lines,
|
||||
...extraLines.filter(d => d)
|
||||
];
|
||||
|
||||
//line 1
|
||||
//Pokémon Unite : Lv.40 Veteran: Class 3
|
||||
//Pokémon Unite : Lv.40 Master (1741)
|
||||
{
|
||||
//will be only text after "pokemon unite:"
|
||||
let line = lines[0].split(':').slice(1).join(':').trim();
|
||||
|
||||
let regex = uniteApiRegex.ogdescription[0];
|
||||
|
||||
if (regex[0].test(line)) { //is master/has elo
|
||||
|
||||
let regexData = line.match(regex[0]);
|
||||
|
||||
if (!regexData || regexData.length < 4)
|
||||
throw 'Unable to read data, please try again';
|
||||
|
||||
foundData.level = regexData[1];
|
||||
foundData.rank = regexData[2];
|
||||
foundData.elo = regexData[3];
|
||||
|
||||
} else { //is not master/has a class
|
||||
|
||||
let regexData = line.match(regex[1]);
|
||||
|
||||
if (!regexData || regexData.length < 4)
|
||||
throw 'Unable to read data, please try again';
|
||||
|
||||
foundData.level = regexData[1];
|
||||
foundData.rank = regexData[2];
|
||||
foundData.class = regexData[3];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
lines.shift();
|
||||
|
||||
//rest of lines
|
||||
lines.forEach(line => {
|
||||
|
||||
let split = line.split(':').map(l => l.trim()),
|
||||
key = split[0].toLowerCase().replace(/[^\w]/g, ''),
|
||||
value = split[1];
|
||||
|
||||
switch(key) {
|
||||
case 'battles':
|
||||
foundData.battles = value;
|
||||
break;
|
||||
case 'wins':
|
||||
foundData.wins = value;
|
||||
break;
|
||||
case 'winrate':
|
||||
foundData.winrate = value;
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*let data = uniteApiRegex.ogdescription.exec(attr.content);
|
||||
if (data !== null && data.length >= 7) {
|
||||
foundData.level = data[1];
|
||||
foundData.rank = data[2];
|
||||
@@ -118,7 +204,8 @@ function readHTML(html: string): uniteApiData {
|
||||
foundData.battles = data[4];
|
||||
foundData.wins = data[5];
|
||||
foundData.winrate = data[6];
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2016",
|
||||
"target": "es2020",
|
||||
"module": "commonjs",
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
|
||||
Reference in New Issue
Block a user