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 res.header("Content-Type", "text/html") var html = fs.readFileSync(path.join(__dirname, 'resources/embedCard.html')).toString() var result = (await fetch(`https://api.lanyard.rest/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 res.header("Content-Type", "text/html") var html = fs.readFileSync(path.join(__dirname, 'resources/userPage.html')).toString() var result = (await fetch(`https://api.lanyard.rest/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": user.discord_status, "BASE_LINK": "https://code-server-production-d69b.up.railway.app/proxy/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) })