Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RetroAchievements plugin #1620

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,23 @@ jobs:
user: lowlighter
plugins_errors_fatal: yes
if: ${{ success() || failure() }}
- name: 🎮 RetroAchievements - Generate RetroAchievements metrics
uses: lowlighter/metrics@master
with:
filename: metrics.plugin.retroachievements.svg
token: NOT_NEEDED
plugin_retroachievements: yes
plugin_retroachievements_token: ${{ secrets.RETROACHIEVEMENTS_TOKEN }}
plugin_retroachievements_username: TheROG
plugin_retroachievements_target: TheROG
plugin_retroachievements_showachievements: yes
plugin_retroachievements_lastsin: 2
plugin_retroachievements_achievementslimit: 5
output_action: none
delay: 120
user: lowlighter
plugins_errors_fatal: yes
if: ${{ success() || failure() }}
- name: 📸 Website screenshot - XKCD of the day
uses: lowlighter/metrics@master
with:
Expand Down
31 changes: 31 additions & 0 deletions action.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions settings.example.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 139 additions & 0 deletions source/plugins/community/retroachievements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<!--header-->
<table>
<tr><td colspan="2"><a href="/README.md#-plugins">← Back to plugins index</a></td></tr>
<tr><th colspan="2"><h3>🎮 RetroAchievements</h3></th></tr>
<tr><td colspan="2" align="center"><p>Shows your profile, last played game and achievements from RetroAchievements.</p>
</td></tr>
<tr><th>Authors</th><td><a href="https://github.com/LuanRoger">@LuanRoger</a></td></tr>
<tr>
<th rowspan="3">Supported features<br><sub><a href="metadata.yml">→ Full specification</a></sub></th>
<td><a href="/source/templates/classic/README.md"><code>📗 Classic template</code></a></td>
</tr>
<tr>
<td><code>👤 Users</code></td>
</tr>
<tr>
<td><code>🗝️ plugin_retroachievements_token</code></td>
</tr>
<tr>
<td colspan="2" align="center">
<img src="https://via.placeholder.com/468x60?text=No%20preview%20available" alt=""></img>
<img width="900" height="1" alt="">
</td>
</tr>
</table>
<!--/header-->

## ➡️ Available options

<!--options-->
<table>
<tr>
<td align="center" nowrap="nowrap">Option</i></td><td align="center" nowrap="nowrap">Description</td>
</tr>
<tr>
<td nowrap="nowrap"><h4><code>plugin_retroachievements</code></h4></td>
<td rowspan="2"><p>Enable RetroAchievements plugin</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap">✨ On <code>master</code>/<code>main</code><br>
<b>type:</b> <code>boolean</code>
<br>
<b>default:</b> no<br></td>
</tr>
<tr>
<td nowrap="nowrap"><h4><code>plugin_retroachievements_token</code></h4></td>
<td rowspan="2"><p>RetroAchievements&#39;s API Token</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap">🔐 Token<br>
✨ On <code>master</code>/<code>main</code><br>
<b>type:</b> <code>token</code>
<br></td>
</tr>
<tr>
<td nowrap="nowrap"><h4><code>plugin_retroachievements_username</code></h4></td>
<td rowspan="2"><p>RetroAchievements&#39;s Username realted to the API Token</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap">✨ On <code>master</code>/<code>main</code><br>
<b>type:</b> <code>string</code>
<br></td>
</tr>
<tr>
<td nowrap="nowrap"><h4><code>plugin_retroachievements_target</code></h4></td>
<td rowspan="2"><p>The terget user to show the profile</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap">✨ On <code>master</code>/<code>main</code><br>
<b>type:</b> <code>string</code>
<br></td>
</tr>
<tr>
<td nowrap="nowrap"><h4><code>plugin_retroachievements_showachievements</code></h4></td>
<td rowspan="2"><p>Show last achievements unlocked</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap">✨ On <code>master</code>/<code>main</code><br>
<b>type:</b> <code>boolean</code>
<br>
<b>default:</b> yes<br></td>
</tr>
<tr>
<td nowrap="nowrap"><h4><code>plugin_retroachievements_lastsin</code></h4></td>
<td rowspan="2"><p>Number of days to look back for last achievements unlocked</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap">✨ On <code>master</code>/<code>main</code><br>
<b>type:</b> <code>number</code>
<br>
<b>default:</b> 7<br></td>
</tr>
<tr>
<td nowrap="nowrap"><h4><code>plugin_retroachievements_achievementslimit</code></h4></td>
<td rowspan="2"><p>Number of achievements to show</p>
<img width="900" height="1" alt=""></td>
</tr>
<tr>
<td nowrap="nowrap">✨ On <code>master</code>/<code>main</code><br>
<b>type:</b> <code>number</code>
<br>
<b>default:</b> 3<br></td>
</tr>
</table>
<!--/options-->

## 🗝️ Obtaining the Web API Key

You must to have a [RetroAchievements](https://retroachievements.org) account to get the API Key.
You can get it by following the steps below:

1. Enter with your RetroAchievement account.
2. Go to the Keys section on the [Control Panel page](https://retroachievements.org/controlpanel.php) (Settings).
3. Generate a new key and copy it.

## ℹ️ Examples workflows

<!--examples-->
```yaml
name: Generate RetroAchievements metrics
uses: lowlighter/metrics@latest
with:
filename: metrics.plugin.retroachievements.svg
token: NOT_NEEDED
plugin_retroachievements: yes
plugin_retroachievements_token: ${{ secrets.RETROACHIEVEMENTS_TOKEN }}
plugin_retroachievements_username: TheROG
plugin_retroachievements_target: TheROG
plugin_retroachievements_showachievements: yes
plugin_retroachievements_lastsin: 2
plugin_retroachievements_achievementslimit: 5

```
<!--/examples-->
12 changes: 12 additions & 0 deletions source/plugins/community/retroachievements/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: Generate RetroAchievements metrics
uses: lowlighter/metrics@latest
with:
filename: metrics.plugin.retroachievements.svg
token: NOT_NEEDED
plugin_retroachievements: yes
plugin_retroachievements_token: ${{ secrets.RETROACHIEVEMENTS_TOKEN }}
plugin_retroachievements_username: TheROG
plugin_retroachievements_target: TheROG
plugin_retroachievements_showachievements: yes
plugin_retroachievements_lastsin: 2
plugin_retroachievements_achievementslimit: 5
87 changes: 87 additions & 0 deletions source/plugins/community/retroachievements/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
export default async function (
{q, imports, data, account},
{token = "", enabled = false, extras = false} = {}
) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if (
!q.retroachievements ||
!imports.metadata.plugins.retroachievements.enabled(enabled, {extras})
)
return null

//Load input data
const {username, target, showachievements, lastsin, achievementslimit} =
imports.metadata.plugins.retroachievements.inputs({data, account, q})
const retroachievementsUrl = "https://retroachievements.org"

const profile = await imports.axios.get(
`https://retroachievements.org/API/API_GetUserProfile.php?z=${username}&u=${target}&y=${token}`
)
const {
data:{
User:user,
UserPic,
TotalPoints:totalPoints,
RichPresenceMsg:presenceMessage,
LastGameID:lastGameId,
},
} = profile
const profilePic = await imports.imgb64(`${retroachievementsUrl}${UserPic}`, {width:64, height:64})

const lastPlayedGame = await imports.axios.get(
`https://retroachievements.org/API/API_GetGameInfoAndUserProgress.php?z=${username}&u=${target}&g=${lastGameId}&y=${token}`
)
const {
data:{
Title:title,
ImageIcon,
Genre:genre,
ConsoleName:consoleName,
NumAchievements:totalAchievements,
NumAwardedToUser:awardedAchievements,
UserCompletion:progress,
},
} = lastPlayedGame
const gameIcon = await imports.imgb64(`${retroachievementsUrl}${ImageIcon}`, {width:64, height:64})

let lastGameAchievements = null
if (showachievements) {
const minutesToLookBack = lastsin * 1440 //Minutes in a day
const lastUnlocked = await imports.axios.get(
`https://retroachievements.org/API/API_GetUserRecentAchievements.php?z=${username}&y=${token}&u=${target}&m=${minutesToLookBack}`
)

let achievementsData = await Promise.all(lastUnlocked.data.map(async achievement => ({
title:achievement.Title,
description:achievement.Description,
badgeUrl:await imports.imgb64(`${retroachievementsUrl}${achievement.BadgeURL}`, {width:64, height:64}),
})))
lastGameAchievements = achievementsData.slice(0, achievementslimit)
}

return {
profile:{
user,
profilePic,
totalPoints,
presenceMessage,
},
lastPlayedGame:{
title,
gameIcon,
genre,
consoleName,
totalAchievements,
awardedAchievements,
progress,
},
lastUnlocked:lastGameAchievements,
}
}
catch (error) {
//Handle errors
throw imports.format.error(error)
}
}
54 changes: 54 additions & 0 deletions source/plugins/community/retroachievements/metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: 🎮 RetroAchievements
category: community
description: |
Shows your profile, last played game and achievements from RetroAchievements.
examples:
default: https://raw.githubusercontent.com/LuanRoger/LuanRoger/main/retroachievements.svg
authors:
- LuanRoger
supports:
- user
scopes: []
inputs:

plugin_retroachievements:
description: |
Enable RetroAchievements plugin
type: boolean
default: no

plugin_retroachievements_token:
description: |
RetroAchievements's API Token
type: token
default: ""

plugin_retroachievements_username:
description: |
RetroAchievements's Username realted to the API Token
type: string
default: ""

plugin_retroachievements_target:
description: |
The terget user to show the profile
type: string
default: ""

plugin_retroachievements_showachievements:
description: |
Show last achievements unlocked
type: boolean
default: yes

plugin_retroachievements_lastsin:
description: |
Number of days to look back for last achievements unlocked
type: number
default: 7

plugin_retroachievements_achievementslimit:
description: |
Number of achievements to show
type: number
default: 3
3 changes: 2 additions & 1 deletion source/templates/classic/partials/_.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
"16personalities",
"fortune",
"splatoon",
"steam"
"steam",
"retroachievements"
]
Loading
Loading