Skip to content

Commit

Permalink
fix: use official retroachievements api url
Browse files Browse the repository at this point in the history
  • Loading branch information
surskitt committed Dec 28, 2023
1 parent cd176f4 commit f0c14c5
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 58 deletions.
37 changes: 37 additions & 0 deletions demo/kube/deploy-retroachievements.yaml.tmpl
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
2 changes: 1 addition & 1 deletion demo/kube/deploy-tiny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: tiny
image: ghcr.io/shanedabes/tiny:v0.9.0
image: ghcr.io/surskitt/tiny:v0.9.0
volumeMounts:
- name: tiny-config
mountPath: /tiny.yml
Expand Down
12 changes: 12 additions & 0 deletions demo/kube/pvc-retroachievements.yaml
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
10 changes: 7 additions & 3 deletions demo/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
---
apiVersion: skaffold/v2beta23
apiVersion: skaffold/v2beta26
kind: Config
build:
artifacts:
- image: retroachievements
context: ./..
docker:
dockerfile: Dockerfile
ko:
dependencies:
paths:
- '*.go'
ignore:
- '*_test.go'
deploy:
kubectl:
manifests:
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/gowon-irc/gowon-retroachievements
go 1.17

require (
github.com/ShiraazMoollatjie/retroachievementsgo v0.0.0-20200114192927-16283851521e
github.com/boltdb/bolt v1.3.1
github.com/carlmjohnson/requests v0.23.5
github.com/eclipse/paho.mqtt.golang v1.3.5
github.com/gowon-irc/go-gowon v0.0.0-20211113200040-cb1a970bd247
github.com/jessevdk/go-flags v1.5.0
Expand All @@ -13,6 +13,6 @@ require (
require (
github.com/gorilla/websocket v1.4.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
)
43 changes: 39 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/ShiraazMoollatjie/retroachievementsgo v0.0.0-20200114192927-16283851521e h1:wt4kIdoE0ql985Wo0xhoPi8gzIT+zAeejaOgx5yKrGM=
github.com/ShiraazMoollatjie/retroachievementsgo v0.0.0-20200114192927-16283851521e/go.mod h1:ywNbLMgMP8b+Q1n1w4gHDjEdRfdWzgD9geeRr2UgCfE=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/carlmjohnson/requests v0.23.5 h1:NPANcAofwwSuC6SIMwlgmHry2V3pLrSqRiSBKYbNHHA=
github.com/carlmjohnson/requests v0.23.5/go.mod h1:zG9P28thdRnN61aD7iECFhH5iGGKX2jIjKQD9kqYH+o=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eclipse/paho.mqtt.golang v1.3.4/go.mod h1:eTzb4gxwwyWpqBUHGQZ4ABAV7+Jgm1PklsYT/eo8Hcc=
Expand All @@ -22,16 +22,51 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/thoj/go-ircevent v0.0.0-20210419090348-35410aa86c49/go.mod h1:I0ZT9x8wStY6VOxtNOrLpnDURFs7HS0z1e1vhuKUEVc=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 h1:Jcxah/M+oLZ/R4/z5RzfPzGbPXnVDPkEDtf2JnuxN+U=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
73 changes: 26 additions & 47 deletions retroachivements.go
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
}

0 comments on commit f0c14c5

Please sign in to comment.