-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsteam.go
43 lines (35 loc) · 1005 Bytes
/
steam.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package sm_report
import (
"fmt"
"github.com/Acidic9/go-steam/steamapi"
"github.com/Acidic9/go-steam/steamid"
"github.com/fanjindong/go-cache"
"github.com/r4g3baby/sm-report/config"
"strconv"
"time"
)
type steamUser struct {
SteamID steamid.ID64
Name string
AvatarURL string
ProfileURL string
}
var userCache = cache.NewMemCache(cache.WithClearInterval(1 * time.Hour))
func getSteamUser(steamID uint64) (*steamUser, error) {
strID := strconv.FormatUint(steamID, 10)
if value, ok := userCache.Get(strID); ok {
return value.(*steamUser), nil
}
profile, err := steamapi.NewKey(config.Config.SteamKey).GetSinglePlayerSummaries(steamID)
if err != nil {
return nil, err
}
steamUser := &steamUser{
SteamID: steamid.NewID64(steamID),
Name: profile.PersonaName,
AvatarURL: profile.AvatarFull,
ProfileURL: fmt.Sprintf("https://steamcommunity.com/profiles/%s", strID),
}
userCache.Set(strID, steamUser, cache.WithEx(12*time.Hour))
return steamUser, nil
}