From c4b7fa9b4c5c5f497a4e0cbbb37ec3a7cce573c1 Mon Sep 17 00:00:00 2001 From: pxseu <57842793+pxseu@users.noreply.github.com> Date: Sun, 4 Jul 2021 23:49:54 +0200 Subject: [PATCH] fix: use import statement --- package.json | 1 + src/renderCard.tsx | 142 ++++++++++++++++++++++++++++++--------------- yarn.lock | 5 ++ 3 files changed, 100 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index b328852..08456e9 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "styled-components": "^5.3.0" }, "devDependencies": { + "@types/escape-html": "^1.0.1", "@types/image-to-base64": "^2.1.0", "@types/react": "17.0.11", "eslint": "7.28.0", diff --git a/src/renderCard.tsx b/src/renderCard.tsx index 83e83fd..b54eff9 100644 --- a/src/renderCard.tsx +++ b/src/renderCard.tsx @@ -4,9 +4,8 @@ import { Badges } from "../public/assets/badges/BadgesEncoded"; import { getFlags } from "./getFlags"; import * as LanyardTypes from "./LanyardTypes"; import { encodeBase64 } from "./toBase64"; -import { blue, green, gray, gold, red } from "./defaultAvatars" - -let escape = require('escape-html'); +import { blue, green, gray, gold, red } from "./defaultAvatars"; +import escape from "escape-html"; type Parameters = { theme?: string; @@ -18,7 +17,6 @@ type Parameters = { }; const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise => { - let avatarBorderColor: string = "#747F8D", userStatus: string = "", avatarExtension: string = "webp", @@ -49,31 +47,33 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise< let avatar: String; if (body.data.discord_user.avatar) { - avatar = await encodeBase64(`https://cdn.discordapp.com/avatars/${body.data.discord_user.id}/${body.data.discord_user.avatar}.${avatarExtension}?size=256`); + avatar = await encodeBase64( + `https://cdn.discordapp.com/avatars/${body.data.discord_user.id}/${body.data.discord_user.avatar}.${avatarExtension}?size=256` + ); } else { - let lastDigit = Number(body.data.discord_user.discriminator.substr(-1)) + let lastDigit = Number(body.data.discord_user.discriminator.substr(-1)); if (lastDigit >= 5) { - lastDigit -= 5 + lastDigit -= 5; } // the default avatar that discord uses depends on the last digit of the user's discriminator switch (lastDigit) { - case 1: + case 1: avatar = gray; break; - case 2: + case 2: avatar = green; break; - case 3: + case 3: avatar = gold; break; - case 4: + case 4: avatar = red; break; default: avatar = blue; } } - + switch (body.data.discord_status) { case "online": avatarBorderColor = "#43B581"; @@ -118,8 +118,9 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise< display: flex; flex-direction: row; padding-bottom: 5px; - border-bottom: solid 0.5px ${theme === "dark" ? "hsl(0, 0%, 100%, 10%)" : "hsl(0, 0%, 0%, 10%)" - }; + border-bottom: solid 0.5px ${ + theme === "dark" ? "hsl(0, 0%, 100%, 10%)" : "hsl(0, 0%, 0%, 10%)" + }; ">
- ${escape(body.data.discord_user.username)}${discrim !== "hide" ? - `#${body.data.discord_user.discriminator}` - : "" } + ${escape(body.data.discord_user.username)}${ + discrim !== "hide" + ? `#${ + body.data.discord_user.discriminator + }` + : "" + } - ${flags.map(v => ` + ${flags + .map( + v => ` `).join("")} + " />` + ) + .join("")}
- ${userStatus.length > 0 && hideStatus !== "true" ? ` + ${ + userStatus.length > 0 && hideStatus !== "true" + ? `

- ${body.data.activities[0].emoji && body.data.activities[0].emoji.id ? ` - ` : `` + " />` + : `` } - ${body.data.activities[0].emoji && !body.data.activities[0].emoji.id - ? body.data.activities[0].emoji.name + " " + escape(userStatus) - : escape(userStatus) + ${ + body.data.activities[0].emoji && !body.data.activities[0].emoji.id + ? body.data.activities[0].emoji.name + " " + escape(userStatus) + : escape(userStatus) } -

` : `` + ` + : `` } - ${activity ? ` + ${ + activity + ? `
- ${activity.assets && activity.assets.large_image ? ` - - ` : ` - - `} - ${activity.assets && activity.assets.small_image ? ` - ` : `` + "/>` + : `` }
-

PLAYING A GAME...

+

PLAYING A GAME...

${activity.name}

- ${activity.details ? ` + ${ + activity.details + ? `

${activity.details}

` : `` + ">${activity.details}

` + : `` }
- ` : `` + ` + : `` } - ${body.data.listening_to_spotify === true && body.data.activities[Object.keys(body.data.activities).length - 1].type === 2 ? ` + ${ + body.data.listening_to_spotify === true && + body.data.activities[Object.keys(body.data.activities).length - 1].type === 2 + ? `
-

LISTENING TO SPOTIFY...

+

LISTENING TO SPOTIFY...

By ${escape(body.data.spotify.artist)}

- ` : `` - } - ${!activity && body.data.listening_to_spotify === false - ? `
` - : `` - } + : `` + } diff --git a/yarn.lock b/yarn.lock index c2c4201..29825ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -271,6 +271,11 @@ resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.0.6.tgz#023d72a5c4531b4ce204528971700a78a85a0c50" integrity sha512-Myxw//kzromB9yWgS8qYGuGVf91oBUUJpNvy5eM50sqvmKLbKjwLxohJnkWGTeeI9v9IBMtPLxz5Gc60FIfvCA== +"@types/escape-html@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@types/escape-html/-/escape-html-1.0.1.tgz#b19b4646915f0ae2c306bf984dc0a59c5cfc97ba" + integrity sha512-4mI1FuUUZiuT95fSVqvZxp/ssQK9zsa86S43h9x3zPOSU9BBJ+BfDkXwuaU7BfsD+e7U0/cUUfJFk3iW2M4okA== + "@types/hoist-non-react-statics@*": version "3.3.1" resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"