const express = require("express"), path = require("path"), fs = require("fs"), fetch = require("node-fetch") var app = express() var statuses = { "online": { "text": "Online", "color": "rgb(100, 255, 100)" }, "dnd": { "text": "DND", "color": "rgb(255, 100, 100)" }, "idle": { "text": "Idle", "color": "rgb(255, 255, 75)" }, "offline": { "text": "Offline", "color": "rgb(125, 125, 125)" } } const PORT = process.env.PORT || 8080 app.use(express.static(path.join(__dirname, 'static'))) app.listen(PORT, () => { console.log("Now listening on PORT: " + PORT) }) app.get('/embedCard', async (req, res) => { var discID = req.query.discordid var server = 'https://' + (req.query.server || 'api.lanyard.rest') res.header("Content-Type", "text/html") var html = fs.readFileSync(path.join(__dirname, 'resources/embedCard.html')).toString() var result = (await fetch(`${server}/v1/users/${discID}`).then(response => response.json())).data var user = result.discord_user var replacers = { "DISPLAY_NAME": user.display_name || user.global_name, "USERNAME": user.username, "DISCORD_ID": user.id, "STATUS": statuses[result.discord_status].text, "STATUS_COLOR": statuses[result.discord_status].color, "CUSTOM_STATUS": "" } if (result && result.activities.length > 0) { if (result.activities[0].type == 4) { replacers.CUSTOM_STATUS = `Custom Status: "${result.activities[0].state}"` } } if (user.discriminator != 0) { replacers.USERNAME += user.discriminator } for (let index = 0; index < Object.keys(replacers).length; index++) { const key = Object.keys(replacers)[index] const val = replacers[key]; while (html.includes("{" + key + "}")) { html = html.replace("{" + key + "}", val) } } res.send(html) }) app.get('/getUser', async (req, res) => { var discID = req.query.discordid var server = 'https://' + (req.query.server || 'api.lanyard.rest') res.header("Content-Type", "text/html") var html = fs.readFileSync(path.join(__dirname, 'resources/userPage.html')).toString() try { var data = (await fetch(`${server}/v1/users/${discID}`).then(response => response.json())) } catch (error) { res.send(`

Error!

Code: ${error}
Try clearing cache and trying again.

`) return } var result = data.data if (data.error) { res.send(`

Error!

Code: ${data.error.code}
Message: ${data.error.message}
Double check the main page to ensure you've set things up right!

`) return } var user = result.discord_user var replacers = { "DISPLAY_NAME": user.display_name || user.global_name, "USERNAME": user.username, "DISCORD_ID": user.id, "STATUS": user.discord_status, "BASE_LINK": "localhost:8080/" } if (user.discriminator != 0) { replacers.USERNAME += "#" + user.discriminator } for (let index = 0; index < Object.keys(replacers).length; index++) { const key = Object.keys(replacers)[index] const val = replacers[key]; while (html.includes("{" + key + "}")) { html = html.replace("{" + key + "}", val) } } res.send(html) })