Get the current map rotation for Apex Legends using the "!apex map" prefix command
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const puppeteer = require('autocode-puppeteer');
let apexURL = 'https://apexmap.kuroi.io/';
if (context.params.event.content.startsWith('!apex map')) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(apexURL);
await page.waitForSelector('.map-title');
let mapName = await page.$$eval('.map-title', (el) => {
return el[0].textContent;
});
let mapCountdown = await page.$$eval('.map-countdown', (el) => {
return el[0].textContent;
});
let mapBG = await page.$$eval('.app-background', (el) => {
return el[0].getAttribute('style').match(/url\("\/(.*?)"\)/)[1];
});
await browser.close();
await lib.discord.channels['@0.1.1'].messages.create({
"channel_id": `${context.params.event.channel_id}`,
"content": "",
"tts": false,
"embed": {
"type": "rich",
"title": `Current Apex Legends Map: ${mapName}`,
"description": `Time remaining: **${mapCountdown}**`,
"color": 0xff5555,
"image": {
"url": apexURL + mapBG,
}
}
});
}