diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt index dfdbd479..f5742471 100644 --- a/.github/actions/spelling/allow.txt +++ b/.github/actions/spelling/allow.txt @@ -12,6 +12,7 @@ https IPlayer ISteam leetcode +MBTI Nie npx personaname diff --git a/.github/readme/imgs/plugin_16personalities_profile.png b/.github/readme/imgs/plugin_16personalities_profile.png new file mode 100644 index 00000000..d55d3302 Binary files /dev/null and b/.github/readme/imgs/plugin_16personalities_profile.png differ diff --git a/source/plugins/community/16personalities/README.md b/source/plugins/community/16personalities/README.md new file mode 100644 index 00000000..3eff2a87 --- /dev/null +++ b/source/plugins/community/16personalities/README.md @@ -0,0 +1,12 @@ + + + +## ➡️ Available options + + + + +## ℹ️ Examples workflows + + + diff --git a/source/plugins/community/16personalities/examples.yml b/source/plugins/community/16personalities/examples.yml new file mode 100644 index 00000000..d395dbf7 --- /dev/null +++ b/source/plugins/community/16personalities/examples.yml @@ -0,0 +1,12 @@ +- name: MBTI Personality profile + uses: lowlighter/metrics@latest + with: + filename: metrics.plugin.16personalities.svg + token: ${{ secrets.METRICS_TOKEN }} + base: "" + plugin_16personalities: yes + plugin_16personalities_url: ${{ secrets.SIXTEEN_PERSONALITIES_URL }} + plugin_16personalities_sections: personality, traits + plugin_16personalities_scores: no + test: + modes: [] \ No newline at end of file diff --git a/source/plugins/community/16personalities/index.mjs b/source/plugins/community/16personalities/index.mjs new file mode 100644 index 00000000..e5cffc91 --- /dev/null +++ b/source/plugins/community/16personalities/index.mjs @@ -0,0 +1,63 @@ +//Setup +export default async function({login, q, imports, data, account}, {enabled = false, extras = false} = {}) { + //Plugin execution + try { + //Check if plugin is enabled and requirements are met + if ((!q["16personalities"]) || (!imports.metadata.plugins["16personalities"].enabled(enabled, {extras}))) + return null + + //Load inputs + let {url, sections, scores} = imports.metadata.plugins["16personalities"].inputs({data, account, q}) + if (!url) + throw {error: {message: "URL is not set"}} + + //Start puppeteer and navigate to page + console.debug(`metrics/compute/${login}/plugins > 16personalities > starting browser`) + const browser = await imports.puppeteer.launch() + console.debug(`metrics/compute/${login}/plugins > 16personalities > started ${await browser.version()}`) + const page = await browser.newPage() + console.debug(`metrics/compute/${login}/plugins > 16personalities > loading ${url}`) + await page.goto(url, {waitUntil: imports.puppeteer.events}) + + //Fetch raw data + const raw = await page.evaluate(() => ({ + color:getComputedStyle(document.querySelector(".card__bg")).backgroundColor, //eslint-disable-line no-undef + type:document.querySelector(".type__code").innerText, + personality:[...document.querySelectorAll(".personality-cards .sp-personality-card")].map(card => ({ + category:card.querySelector(".card__title").innerText, + value:card.querySelector(".card__subtitle").innerText, + image:card.querySelector(".card__image").src, + text:card.querySelector(".card__text").innerText + })), + traits:[...document.querySelectorAll("#traits .card__body")].map(card => ({ + category:card.querySelector(".card__title").innerText, + value:card.querySelector(".card__subtitle").innerText, + score:card.querySelector(".center__num").innerText, + text:card.querySelector("p").innerText + })) + })) + + //Format data + const {color} = raw + const type = raw.type.replace("(", "").replace(")", "").trim() + const personality = await Promise.all(raw.personality.map(async ({category, value, image, text}) => ({ + category, + value:value.replace(`(${type})`, "").trim(), + image:await imports.imgb64(image), + text:text.replace(`${category}\n${value}\n`, "").trim() + }))) + const traits = raw.traits.map(({category, value, score, text}) => ({ + category, + value:`${value[0]}${value.substring(1).toLocaleLowerCase()}`, + score:scores ? Number(score.replace("%", ""))/100 : NaN, + text:text.split(".").slice(1).join("."), + })) + + //Results + return {sections, color, type, personality, traits} + } + //Handle errors + catch (error) { + throw imports.format.error(error) + } +} \ No newline at end of file diff --git a/source/plugins/community/16personalities/metadata.yml b/source/plugins/community/16personalities/metadata.yml new file mode 100644 index 00000000..89e8d39f --- /dev/null +++ b/source/plugins/community/16personalities/metadata.yml @@ -0,0 +1,56 @@ +name: 🧠 16personalities +category: community +description: | + This plugin displays personality profile from a [16personalities profile](https://www.16personalities.com/profile). +disclaimer: | + This plugin is not affiliated, associated, authorized, endorsed by, or in any way officially connected with [16personalities](https://www.16personalities.com). + All product and company names are trademarks™ or registered® trademarks of their respective holders. +examples: + default: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.16personalities.svg +authors: + - lowlighter +supports: + - user +scopes: [] +inputs: + + plugin_16personalities: + description: | + Enable 16personalities plugin + type: boolean + default: no + + plugin_16personalities_url: + description: | + Profile URL + + This can be obtained after doing the [test on 16personalities](https://www.16personalities.com/free-personality-test) and registering an email. + Login with the generated password received in your mailbox and copy the link that is displayed when sharing the profile. + + + + type: string + default: "" + example: https://www.16personalities.com/profiles/xxxxxxxxxxxxx + + plugin_16personalities_sections: + description: | + Displayed sections + + - `personality` will display personality type + - `profile` will display role and strategy + - `traits` will display mind, energy, nature, tactics and identity traits + type: array + format: comma-separated + default: personality + example: personality, profile, traits + values: + - personality + - profile + - traits + + plugin_16personalities_scores: + description: | + Display traits scores + type: boolean + default: yes \ No newline at end of file diff --git a/source/templates/classic/partials/16personalities.ejs b/source/templates/classic/partials/16personalities.ejs new file mode 100644 index 00000000..48883f79 --- /dev/null +++ b/source/templates/classic/partials/16personalities.ejs @@ -0,0 +1,72 @@ +<% if (plugins["16personalities"]) { %> +
+

+ + <%= !plugins["16personalities"].error ? `${plugins["16personalities"].type} personality` : "Personality" %> (results from 16personalities) +

+ <% if (plugins["16personalities"].error) { %> +
+
+
+ + <%= plugins["16personalities"].error.message %> +
+
+
+ <% } else { %> + <% if ((plugins["16personalities"].sections.includes("personality"))||(plugins["16personalities"].sections.includes("profile"))) { %> +
+
+ <% for (const {category, value, image, text} of plugins["16personalities"].personality) { if (((!plugins["16personalities"].sections.includes("personality"))&&(/personality/i.test(category)))||((!plugins["16personalities"].sections.includes("profile"))&&(!/personality/i.test(category)))) continue %> +
+ +
+ ;"><%= value %> <%= category.toLocaleLowerCase() %> + <%= text %> +
+
+ <% } %> +
+
+ <% } %> + <% if (plugins["16personalities"].sections.includes("traits")) { %> +
+
+ <% for (const {category, value, score, text} of plugins["16personalities"].traits) { %> +
+ + + <% if (!Number.isNaN(score)) { %> + + <%= Math.round(score*100) %> + <% } else { %> + + <%= (/energy/i.test(category))&&(/intuitive/i.test(value)) ? "N" : value.charAt(0) %> + <% } %> + +
+ <%= value %> <%= category.toLocaleLowerCase() %> + <%= text %> +
+
+ <% } %> +
+
+ <% } %> + + <% } %> +
+<% } %> \ No newline at end of file diff --git a/source/templates/classic/partials/_.json b/source/templates/classic/partials/_.json index a7886e43..dcc317eb 100644 --- a/source/templates/classic/partials/_.json +++ b/source/templates/classic/partials/_.json @@ -41,6 +41,7 @@ "sponsors", "sponsorships", "poopmap", + "16personalities", "fortune", "splatoon", "steam" diff --git a/tests/secrets.json b/tests/secrets.json index 809c6094..04d55bb6 100644 --- a/tests/secrets.json +++ b/tests/secrets.json @@ -15,5 +15,6 @@ "STEAM_TOKEN":"MOCKED_TOKEN", "SPLATOON_TOKEN":"{}", "SPLATOON_STATINK_TOKEN":"MOCKED_TOKEN", - "POOPMAP_TOKEN":"MOCKED_TOKEN" + "POOPMAP_TOKEN":"MOCKED_TOKEN", + "SIXTEEN_PERSONALITIES_URL":"https://www.16personalities.com/profiles/xxxxxxxxxxxxx" } \ No newline at end of file