diff --git a/.github/readme/imgs/plugin_splatoon_statink.png b/.github/readme/imgs/plugin_splatoon_statink.png new file mode 100644 index 00000000..212e00e7 Binary files /dev/null and b/.github/readme/imgs/plugin_splatoon_statink.png differ diff --git a/.github/scripts/files/examples.yml b/.github/scripts/files/examples.yml index 6da9b359..ede5df7c 100644 --- a/.github/scripts/files/examples.yml +++ b/.github/scripts/files/examples.yml @@ -20,6 +20,8 @@ on: required: true SPLATOON_TOKEN: required: true + SPLATOON_STATINK_TOKEN: + required: true SPOTIFY_TOKENS: required: true STOCK_TOKEN: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 311cd88f..66dec2e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,6 +160,7 @@ jobs: PAGESPEED_TOKEN: ${{ secrets.PAGESPEED_TOKEN }} GOOGLE_MAP_TOKEN: ${{ secrets.GOOGLE_MAP_TOKEN }} SPLATOON_TOKEN: ${{ secrets.SPLATOON_TOKEN }} + SPLATOON_STATINK_TOKEN: ${{ secrets.SPLATOON_STATINK_TOKEN }} SPOTIFY_TOKENS: ${{ secrets.SPOTIFY_TOKENS }} STOCK_TOKEN: ${{ secrets.STOCK_TOKEN }} TWITTER_TOKEN: ${{ secrets.TWITTER_TOKEN }} diff --git a/source/plugins/community/splatoon/README.md b/source/plugins/community/splatoon/README.md index 3037dd5d..71d9d0e9 100644 --- a/source/plugins/community/splatoon/README.md +++ b/source/plugins/community/splatoon/README.md @@ -118,6 +118,19 @@ deno run --allow-run=deno --allow-read=profile.json --allow-write=profile.json - ![Authentication](/.github/readme/imgs/plugin_splatoon_auth.png) +## 🐙 [stat.ink](https://stat.ink) integration + +It is possible to make this plugin automatically export fetched games to [stat.ink](https://stat.ink) by adding the following: + +```yaml +plugin_splatoon_statink: yes +plugin_splatoon_statink_token: ${{ secrets.SPLATOON_STATINK_TOKEN }} +``` + +[stat.ink](https://stat.ink) API key can be found on user profile: + +![stat.ink](/.github/readme/imgs/plugin_splatoon_statink.png) + ## 👨‍💻 About Data are fetched using [spacemeowx2/s3si.ts](https://github.com/spacemeowx2/s3si.ts) tool (which is itself based on [frozenpandaman/s3s](https://github.com/frozenpandaman/s3s)). diff --git a/source/plugins/community/splatoon/examples.yml b/source/plugins/community/splatoon/examples.yml index 9307ac2c..1b671c80 100644 --- a/source/plugins/community/splatoon/examples.yml +++ b/source/plugins/community/splatoon/examples.yml @@ -1,4 +1,4 @@ -- name: Example +- name: Splatnet data uses: lowlighter/metrics@latest with: filename: metrics.plugin.splatoon.svg @@ -6,6 +6,21 @@ base: "" plugin_splatoon: yes plugin_splatoon_token: ${{ secrets.SPLATOON_TOKEN }} + test: + skip: true + prod: + skip: true + +- name: Splatnet data with stat.ink integration + uses: lowlighter/metrics@latest + with: + filename: metrics.plugin.splatoon.svg + token: ${{ secrets.METRICS_TOKEN }} + base: "" + plugin_splatoon: yes + plugin_splatoon_token: ${{ secrets.SPLATOON_TOKEN }} + plugin_splatoon_statink: yes + plugin_splatoon_statink_token: ${{ secrets.SPLATOON_STATINK_TOKEN }} extras_css: | h2 { display: none !important; } test: diff --git a/source/plugins/community/splatoon/index.mjs b/source/plugins/community/splatoon/index.mjs index b003b0f7..ce0998ef 100644 --- a/source/plugins/community/splatoon/index.mjs +++ b/source/plugins/community/splatoon/index.mjs @@ -2,7 +2,7 @@ import assets from "./assets.mjs" //Setup -export default async function({login, q, imports, data, account}, {enabled = false, extras = false, token} = {}) { +export default async function({login, q, imports, data, account}, {enabled = false, extras = false, token, "statink.token":_statink_token} = {}) { //Plugin execution try { //Check if plugin is enabled and requirements are met @@ -10,7 +10,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal return null //Load inputs - const {modes, "versus.limit": _versus_limit, "salmon.limit": _salmon_limit} = imports.metadata.plugins.splatoon.inputs({data, account, q}) + const {modes, "versus.limit": _versus_limit, "salmon.limit": _salmon_limit, statink} = imports.metadata.plugins.splatoon.inputs({data, account, q}) //Save profile { @@ -19,7 +19,18 @@ export default async function({login, q, imports, data, account}, {enabled = fal const parsed = JSON.parse(token) if (!parsed?.loginState?.sessionToken) throw new Error("Configuration is missing sessionToken") - await imports.fs.writeFile(profile, token) + if (statink) { + console.debug(`metrics/compute/${login}/plugins > splatoon > stat.ink integration is enabled`) + if (_statink_token) { + parsed.statInkApiKey = _statink_token + console.debug(`metrics/compute/${login}/plugins > splatoon > stat.ink api key set`) + } + else { + data.warnings.push({warning:{message:'"plugin_splatoon_statink" is set without "plugin_splatoon_statink_token"'}}) + console.debug(`metrics/compute/${login}/plugins > splatoon > stat.ink api key missing`) + } + } + await imports.fs.writeFile(profile, JSON.stringify(parsed)) } //Fetch data @@ -27,7 +38,12 @@ export default async function({login, q, imports, data, account}, {enabled = fal files: ["profile.json", "profile.json.swap", "export", "cache"], net: ["api.imink.app", "accounts.nintendo.com", "api.accounts.nintendo.com", "api-lp1.znc.srv.nintendo.net", "api.lp1.av5ja.srv.nintendo.net"], } - await imports.run(`deno run --no-prompt --cached-only --no-remote --allow-read="${allowed.files}" --allow-write="${allowed.files}" --allow-net="${allowed.net}" index.ts --exporter file --no-progress`, {cwd: `${imports.__module(import.meta.url)}/s3si`}, {prefixed: false}) + const exporters = ["file"] + if (statink) { + exporters.push("stat.ink") + allowed.net.push("stat.ink") + } + await imports.run(`deno run --no-prompt --cached-only --no-remote --allow-read="${allowed.files}" --allow-write="${allowed.files}" --allow-net="${allowed.net}" index.ts --exporter="${exporters}" --no-progress`, {cwd: `${imports.__module(import.meta.url)}/s3si`}, {prefixed: false}) //Read fetched data const fetched = (await Promise.all( diff --git a/source/plugins/community/splatoon/metadata.yml b/source/plugins/community/splatoon/metadata.yml index 0c61777b..8d72b5a0 100644 --- a/source/plugins/community/splatoon/metadata.yml +++ b/source/plugins/community/splatoon/metadata.yml @@ -61,4 +61,21 @@ inputs: type: number default: 1 min: 0 - max: 6 \ No newline at end of file + max: 6 + + plugin_splatoon_statink: + description: | + stat.ink integration + + If set, fetched data will also be uploaded to stat.ink + Requires [`plugin_splatoon_statink_token`](/source/plugins/community/splatoon/README.md#plugin_splatoon_statink_token) to be set + type: boolean + default: no + extras: + - metrics.api.statink + + plugin_splatoon_statink_token: + description: | + stat.ink token + type: token + default: "" \ No newline at end of file diff --git a/source/plugins/community/splatoon/token.ts b/source/plugins/community/splatoon/token.ts index eb331481..3631580c 100644 --- a/source/plugins/community/splatoon/token.ts +++ b/source/plugins/community/splatoon/token.ts @@ -21,12 +21,13 @@ const allowed = { files:["profile.json", "profile.json.swap", "cache", "export"], net:["api.imink.app", "accounts.nintendo.com", "api.accounts.nintendo.com", "api-lp1.znc.srv.nintendo.net", "api.lp1.av5ja.srv.nintendo.net"] } +const script = import.meta.resolve("./s3si/index.ts") const args = [ "run", "--no-prompt", "--cached-only", "--no-remote", `--allow-read="${allowed.files}"`, `--allow-write="${allowed.files}"`, `--allow-net="${allowed.net}"`, - "s3si/index.ts", + script, '--exporter=none' ] try { diff --git a/tests/secrets.json b/tests/secrets.json index e251769e..97ffeb99 100644 --- a/tests/secrets.json +++ b/tests/secrets.json @@ -13,5 +13,6 @@ "STOCK_TOKEN":"MOCKED_TOKEN", "CHESS_TOKEN":"MOCKED_TOKEN", "SPLATOON_TOKEN":"{}", + "SPLATOON_STATINK_TOKEN":"MOCKED_TOKEN", "POOPMAP_TOKEN":"MOCKED_TOKEN" } \ No newline at end of file