Skip to content

Commit 43e961e

Browse files
committed
./update accept_command_line_token
1 parent a3b58ca commit 43e961e

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

appsStatus.json

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
{
2-
"frequency": 10,
2+
"frequency": 20,
33
"fallback": "Probably sleeping",
44
"fallback_emoji": ":zzz:",
55
"apps": [
66
{
77
"names": ["steamwebhelper"],
8-
"statusText": "Gaming",
9-
"emoji": ":video_game:",
8+
"vals": [{ "statusText": "Gaming", "emoji": ":video_game:" }],
109
"priority": 0
1110
},
1211
{
1312
"names": ["code"],
14-
"statusText": "Being a l33t hax0r",
15-
"emoji": ":computer:",
16-
"priority": 1
17-
},
18-
{
19-
"names": ["code"],
20-
"statusText": "Doing \"actual work\"",
21-
"emoji": ":computer:",
13+
"vals": [
14+
{
15+
"statusText": "Doing \"actual work\"",
16+
"emoji": ":computer:"
17+
},
18+
{ "statusText": "Being a l33t hax0r", "emoji": ":computer:" }
19+
],
2220
"priority": 1
2321
},
2422
{
2523
"names": ["firefox-bin", "firefox"],
26-
"statusText": "Perusing stackoverflow",
27-
"emoji": ":surfer:",
24+
"vals": [
25+
{
26+
"statusText": "Perusing stackoverflow",
27+
"emoji": ":surfer:"
28+
}
29+
],
2830
"priority": 1
2931
},
3032
{
3133
"names": ["signal-desktop", "signal"],
32-
"statusText": "Just chatting",
33-
"emoji": ":speaking_head:",
34+
"vals": [
35+
{
36+
"statusText": "Just chatting",
37+
"emoji": ":speaking_head:"
38+
}
39+
],
3440
"priority": 2
3541
}
3642
]
37-
}
43+
}

main.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ import (
2222
graphql "github.com/hasura/go-graphql-client"
2323
)
2424

25+
type StatusPair struct {
26+
StatusText string `json:"statusText"`
27+
Emoji string `json:"emoji"`
28+
}
29+
2530
type AppStatus struct {
26-
Names []string `json:"names"`
27-
StatusText string `json:"statusText"`
28-
Priority int32 `json:"priority"`
29-
Emoji string `json:"emoji"`
31+
Names []string `json:"names"`
32+
Vals []StatusPair `json:"vals"`
33+
Priority int32 `json:"priority"`
3034
}
3135

3236
type AppList struct {
@@ -37,11 +41,10 @@ type AppList struct {
3741
}
3842

3943
type ChangeUserStatusInput struct {
40-
ClientMutationId string `json:"clientMutationId"`
41-
// The emoji to represent your status. Can either be a native Unicode emoji or an emoji name with colons, e.g., :grinning:.
42-
Emoji string `json:"emoji"`
43-
ExpiresAt time.Time `json:"expiresAt"`
44-
Message string `json:"message"`
44+
ClientMutationId string `json:"clientMutationId"`
45+
Emoji string `json:"emoji"`
46+
ExpiresAt time.Time `json:"expiresAt"`
47+
Message string `json:"message"`
4548
}
4649

4750
type authedTransport struct {
@@ -197,9 +200,10 @@ func getCurrentApp(activeApps map[string]bool, appList []AppStatus, config AppLi
197200
return config.FallbackStatus, config.FallbackEmoji
198201
}
199202

200-
aRandomApp := allListedRunningApps[rand.Intn(len(allListedRunningApps))]
203+
appsVals := allListedRunningApps[rand.Intn(len(allListedRunningApps))].Vals
204+
aRandomAppStatus := appsVals[rand.Intn(len(appsVals))]
201205

202-
return aRandomApp.StatusText, aRandomApp.Emoji
206+
return aRandomAppStatus.StatusText, aRandomAppStatus.Emoji
203207
}
204208

205209
func manageStatus() {
@@ -224,10 +228,21 @@ func resetOnClose() {
224228
}
225229

226230
func initClient() {
227-
authToken := os.Getenv("GITHUB_PAT")
231+
authTokenEnv := os.Getenv("GITHUB_PAT")
232+
233+
var authTokenCmd = ""
234+
if len(os.Args) > 1 {
235+
authTokenCmd = os.Args[1]
236+
}
237+
238+
if len(authTokenEnv) < 1 && len(authTokenCmd) < 1 {
239+
log.Fatal("GITHUB_PAT env variable not set & no token passed to app.\nUsage: status <token>")
240+
}
241+
242+
var authToken = authTokenEnv
228243

229-
if authToken == "" {
230-
log.Fatal("GITHUB_PAT not set")
244+
if len(authTokenCmd) > 0 {
245+
authToken = authTokenCmd
231246
}
232247

233248
httpClient := http.Client{

0 commit comments

Comments
 (0)