2020-06-16 10:48:36 +02:00
|
|
|
import puppeteer from 'puppeteer'
|
|
|
|
import { log } from '../utils'
|
2020-06-11 15:32:17 +02:00
|
|
|
|
2020-06-16 10:48:36 +02:00
|
|
|
export default async function fetchDiscord() {
|
2020-06-11 15:32:17 +02:00
|
|
|
const url = 'https://discord.com/invite/TnXjkR5'
|
|
|
|
const start = Date.now()
|
|
|
|
|
2020-06-16 10:48:36 +02:00
|
|
|
const browser = await puppeteer.launch({ headless: true })
|
|
|
|
const page = await browser.newPage()
|
|
|
|
await page.goto(url)
|
|
|
|
|
|
|
|
const members = await page.evaluate(() => {
|
|
|
|
// get the activity count element
|
|
|
|
const membersElement = document.querySelector('[class*="activityCount"] > div:last-child span')
|
2020-06-16 11:12:27 +02:00
|
|
|
const membersElementText = membersElement.innerText
|
|
|
|
const number = membersElementText.replace(' Members', '')
|
|
|
|
return number
|
2020-06-16 10:48:36 +02:00
|
|
|
})
|
2020-06-11 15:32:17 +02:00
|
|
|
|
|
|
|
log(
|
2020-06-16 10:48:36 +02:00
|
|
|
'Re-fetched Discord. ' +
|
2020-06-11 15:32:17 +02:00
|
|
|
`Total: ${members} members. ` +
|
|
|
|
`Elapsed: ${new Date() - start}ms`
|
|
|
|
)
|
|
|
|
|
2020-06-16 11:12:27 +02:00
|
|
|
return { members: Number(members) }
|
2020-06-11 15:32:17 +02:00
|
|
|
}
|