-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use official retroachievements api url
- Loading branch information
Showing
7 changed files
with
125 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: retroachievements | ||
labels: | ||
app.kubernetes.io/name: retroachievements | ||
spec: | ||
selector: | ||
matchLabels: | ||
app.kubernetes.io/name: retroachievements | ||
template: | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: retroachievements | ||
spec: | ||
containers: | ||
- name: retroachievements | ||
image: retroachievements | ||
imagePullPolicy: IfNotPresent | ||
securityContext: | ||
runAsUser: 0 | ||
runAsGroup: 0 | ||
env: | ||
- name: GOWON_BROKER | ||
value: mosquitto:1883 | ||
- name: GOWON_RA_API_KEY | ||
value: api_key | ||
- name: GOWON_RA_USERNAME | ||
value: user | ||
volumeMounts: | ||
- name: retroachievements | ||
mountPath: /data | ||
volumes: | ||
- name: retroachievements | ||
persistentVolumeClaim: | ||
claimName: retroachievements |
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 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: retroachievements | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
storageClassName: local-path | ||
resources: | ||
requests: | ||
storage: 20Mi |
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
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 |
---|---|---|
@@ -1,75 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
const ( | ||
raAchievementsURL = "https://ra.hfc-essentials.com/user_by_range.php?user=%s&key=%s&member=%s&mode=json" | ||
"github.com/carlmjohnson/requests" | ||
) | ||
|
||
var ( | ||
achievementStartTime = time.Date(2010, 10, 2, 6, 0, 0, 0, time.UTC) | ||
const ( | ||
raAchievementsURL = "https://retroachievements.org/API/API_GetAchievementsEarnedBetween.php" | ||
) | ||
|
||
type AchievementsByDateResp struct { | ||
AchievementList [][]Achievement `json:"achievement"` | ||
} | ||
|
||
type Achievement struct { | ||
Date string `json:"Date"` | ||
HardcoreMode int `json:"HardcoreMode"` | ||
AchievementID int `json:"AchievementID"` | ||
Title string `json:"Title"` | ||
Description string `json:"Description"` | ||
BadgeName string `json:"BadgeName"` | ||
Points int `json:"Points"` | ||
Author string `json:"Author"` | ||
GameTitle string `json:"GameTitle"` | ||
GameIcon string `json:"GameIcon"` | ||
GameID int `json:"GameID"` | ||
ConsoleName string `json:"ConsoleName"` | ||
CumulScore int `json:"CumulScore"` | ||
BadgeURL string `json:"BadgeURL"` | ||
GameURL string `json:"GameURL"` | ||
HardcoreMode int `json:"HardcoreMode"` | ||
Title string `json:"Title"` | ||
Description string `json:"Description"` | ||
Points int `json:"Points"` | ||
GameTitle string `json:"GameTitle"` | ||
ConsoleName string `json:"ConsoleName"` | ||
} | ||
|
||
func formatAchievement(user string, a Achievement) string { | ||
return fmt.Sprintf("%s's last retro achievement: %s (%s) - %s (%s)", user, a.Title, a.Description, a.GameTitle, a.ConsoleName) | ||
return fmt.Sprintf("%s's last retro achievement: %s (%s) - %s (%s) - %d points", user, a.Title, a.Description, a.GameTitle, a.ConsoleName, a.Points) | ||
} | ||
|
||
func ra(apiUser, apiKey, user string) (string, error) { | ||
url := fmt.Sprintf(raAchievementsURL, apiUser, apiKey, user) | ||
|
||
j := &AchievementsByDateResp{} | ||
|
||
res, err := http.Get(url) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
defer res.Body.Close() | ||
|
||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
err = json.Unmarshal(body, &j) | ||
t := fmt.Sprint(time.Now().Unix()) | ||
|
||
var j []Achievement | ||
err := requests. | ||
URL(raAchievementsURL). | ||
Param("z", apiUser). | ||
Param("y", apiKey). | ||
Param("u", user). | ||
Param("f", "0"). | ||
Param("t", t). | ||
Param("mode", "json"). | ||
ToJSON(&j). | ||
Fetch(context.Background()) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if len(j.AchievementList[0]) == 0 { | ||
if len(j) == 0 { | ||
return fmt.Sprintf("No achievements found for user %s", user), nil | ||
} | ||
|
||
out := formatAchievement(user, j.AchievementList[0][len(j.AchievementList[0])-1]) | ||
out := formatAchievement(user, j[len(j)-1]) | ||
|
||
return out, nil | ||
} |