2020-06-16 16:14:31 +02:00
|
|
|
import { load } from 'cheerio'
|
2020-06-16 10:48:36 +02:00
|
|
|
import { log } from '../utils'
|
2020-06-16 16:14:31 +02:00
|
|
|
import fetch from 'node-fetch'
|
2020-06-16 15:16:31 +02:00
|
|
|
|
2020-06-16 10:48:36 +02:00
|
|
|
export default async function fetchDiscord() {
|
2020-06-16 12:32:47 +02:00
|
|
|
const url = 'https://discord.com/invite/TnXjkR5'
|
|
|
|
const start = Date.now()
|
2020-06-11 15:32:17 +02:00
|
|
|
|
2020-06-16 16:14:31 +02:00
|
|
|
const response = await fetch(url)
|
|
|
|
const body = await response.text()
|
|
|
|
const data = await load(body, { normalizeWhitespace: true })
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 16:14:31 +02:00
|
|
|
// extract members count from meta description
|
|
|
|
const metaDescription = data('meta[name="description"]').attr('content')
|
|
|
|
const regex = /\d+/ // one or more digits
|
|
|
|
const number = metaDescription.match(regex)
|
|
|
|
const members = parseInt(number[0])
|
2020-06-16 12:32:47 +02:00
|
|
|
|
|
|
|
log(
|
2020-06-16 15:16:31 +02:00
|
|
|
'✓ Discord. ' +
|
2020-06-16 12:32:47 +02:00
|
|
|
`Total: ${members} members. ` +
|
|
|
|
`Elapsed: ${new Date() - start}ms`
|
|
|
|
)
|
2020-06-11 15:32:17 +02:00
|
|
|
|
2020-06-16 15:35:28 +02:00
|
|
|
return { members }
|
2020-06-11 15:32:17 +02:00
|
|
|
}
|