-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins/community/chess): add plugin (#1215) [skip ci]
- Loading branch information
1 parent
d6636c0
commit 2239bc9
Showing
18 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!--header--> | ||
<!--/header--> | ||
|
||
## ➡️ Available options | ||
|
||
<!--options--> | ||
<!--/options--> | ||
|
||
## ℹ️ Examples workflows | ||
|
||
<!--examples--> | ||
<!--/examples--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
- name: Last chess game from lichess.org | ||
uses: lowlighter/metrics@latest | ||
with: | ||
filename: metrics.plugin.chess.svg | ||
token: NOT_NEEDED | ||
base: "" | ||
plugin_chess: yes | ||
plugin_chess_token: ${{ secrets.CHESS_TOKEN }} | ||
plugin_chess_platform: lichess.org | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//Imports | ||
import { Chess } from "chess.js" | ||
|
||
//Setup | ||
export default async function({login, q, imports, data, account}, {enabled = false, token = "", extras = false} = {}) { | ||
//Plugin execution | ||
try { | ||
//Check if plugin is enabled and requirements are met | ||
if ((!q.chess) || (!imports.metadata.plugins.chess.enabled(enabled, {extras}))) | ||
return null | ||
|
||
//Load inputs | ||
const {user, platform, animation} = imports.metadata.plugins.chess.inputs({data, account, q}) | ||
for (const [key, defaulted] of Object.entries({size:40, delay:1, duration:4})) { | ||
if (Number.isNaN(Number(animation[key]))) | ||
animation[key] = defaulted | ||
if (animation[key] < 0) | ||
animation[key] = defaulted | ||
} | ||
|
||
//Fetch PGN | ||
console.debug(`metrics/compute/${login}/plugins > chess > fetching last game from ${platform}`) | ||
let PGN | ||
switch (platform) { | ||
case "lichess.org": | ||
PGN = (await imports.axios.get(`https://lichess.org/api/games/user/${user}?max=1`, {headers: {Authorization: `Bearer ${token}`}})).data | ||
break | ||
case "": | ||
throw {error: {message: "Unspecified platform"}} | ||
default: | ||
throw {error: {message: `Unsupported platform "${platform}"`}} | ||
} | ||
|
||
//Parse PGN | ||
const board = new Chess() | ||
board.loadPgn(PGN) | ||
const moves = board.history({verbose: true}) | ||
const meta = board.header() | ||
const result = Object.fromEntries(meta.Result.split("-").map((score, i) => [i ? "black" : "white", Number(score)])) | ||
|
||
//Results | ||
return {platform, meta, moves, animation, result} | ||
} | ||
//Handle errors | ||
catch (error) { | ||
throw imports.format.error(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: ♟️ Chess | ||
category: community | ||
description: | | ||
This plugin displays the last game you played on a supported chess platform. | ||
disclaimer: | | ||
This plugin is not affiliated, associated, authorized, endorsed by, or in any way officially connected with any of the supported provider. | ||
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.chess.svg | ||
authors: | ||
- lowlighter | ||
supports: | ||
- user | ||
- organization | ||
- repository | ||
scopes: [] | ||
inputs: | ||
|
||
plugin_chess: | ||
description: | | ||
Enable chess plugin | ||
type: boolean | ||
default: no | ||
|
||
plugin_chess_token: | ||
description: | | ||
Chess platform token | ||
type: token | ||
default: "" | ||
extras: | ||
- metrics.api.chess.any | ||
|
||
plugin_chess_user: | ||
description: | | ||
AniList login | ||
type: string | ||
default: .user.login | ||
preset: no | ||
|
||
plugin_chess_platform: | ||
description: | | ||
Chess platform | ||
type: string | ||
default: "" | ||
values: | ||
- lichess.org | ||
|
||
plugin_chess_animation: | ||
description: | | ||
Animation settings | ||
- `size` is the size of a single chessboard square in pixels (board will be 8 times larger) | ||
- `delay` is the delay before starting animation (in seconds) | ||
- `duration` is the duration of the animation of a move (in seconds) | ||
type: json | ||
default: | | ||
{ | ||
"size": 40, | ||
"delay": 3, | ||
"duration": 0.6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
"achievements", | ||
"screenshot", | ||
"code", | ||
"chess", | ||
"sponsors", | ||
"poopmap", | ||
"fortune" | ||
|
Oops, something went wrong.