feat(plugins/community/splatoon): add stat.ink integration

This commit is contained in:
lowlighter
2022-11-21 19:03:33 -05:00
parent 7c342bf915
commit 24029ffa89
9 changed files with 73 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -20,6 +20,8 @@ on:
required: true
SPLATOON_TOKEN:
required: true
SPLATOON_STATINK_TOKEN:
required: true
SPOTIFY_TOKENS:
required: true
STOCK_TOKEN:

View File

@@ -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 }}

View File

@@ -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)).

View File

@@ -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:

View File

@@ -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(

View File

@@ -62,3 +62,20 @@ inputs:
default: 1
min: 0
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: ""

View File

@@ -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 {

View File

@@ -13,5 +13,6 @@
"STOCK_TOKEN":"MOCKED_TOKEN",
"CHESS_TOKEN":"MOCKED_TOKEN",
"SPLATOON_TOKEN":"{}",
"SPLATOON_STATINK_TOKEN":"MOCKED_TOKEN",
"POOPMAP_TOKEN":"MOCKED_TOKEN"
}