Skip to content

Commit f5f0277

Browse files
committed
Remove extraneous reaction remove/add, scw healthcheck kill
1 parent ba901ed commit f5f0277

6 files changed

+94
-10
lines changed

discord/eventHandler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ func (bot *Bot) processTransition(phase game.Phase, dgsRequest GameStateRequest)
265265
case game.MENU:
266266
dgs.Edit(bot.SessionManager.GetPrimarySession(), bot.gameStateResponse(dgs, sett))
267267
bot.applyToAll(dgs, false, false)
268-
go dgs.RemoveAllReactions(bot.SessionManager.GetPrimarySession())
268+
//go dgs.RemoveAllReactions(bot.SessionManager.GetPrimarySession())
269269
break
270270
case game.LOBBY:
271271
delay := sett.Delays.GetDelay(oldPhase, phase)
272272
bot.handleTrackedMembers(bot.SessionManager, sett, delay, NoPriority, dgsRequest)
273273

274274
dgs.Edit(bot.SessionManager.GetPrimarySession(), bot.gameStateResponse(dgs, sett))
275-
go dgs.AddAllReactions(bot.SessionManager.GetPrimarySession(), bot.StatusEmojis[true])
275+
276276
break
277277
case game.TASKS:
278278
delay := sett.Delays.GetDelay(oldPhase, phase)

discord/healthCheck_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package discord
2+
3+
import (
4+
"os"
5+
"testing"
6+
)
7+
8+
func TestTerminateScalewayNode(t *testing.T) {
9+
orgId := os.Getenv("SCW_ORGANIZATION_ID")
10+
accessKey := os.Getenv("SCW_ACCESS_KEY")
11+
secretKey := os.Getenv("SCW_SECRET_KEY")
12+
nodeID := os.Getenv("SCW_NODE_ID")
13+
14+
TerminateScalewayNode(orgId, accessKey, secretKey, nodeID)
15+
}

discord/healthcheck.go

+72-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ package discord
22

33
import (
44
"github.com/gorilla/mux"
5+
"github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
6+
"github.com/scaleway/scaleway-sdk-go/scw"
57
"log"
68
"net/http"
9+
"os"
10+
"strings"
711
)
812

913
func StartHealthCheckServer(port string) {
@@ -15,7 +19,7 @@ func StartHealthCheckServer(port string) {
1519
})
1620

1721
r.HandleFunc("/ready", func(w http.ResponseWriter, r *http.Request) {
18-
resp, err := http.Get("https://discordapp.com/api/v7/gateway")
22+
resp, err := http.Get("https://discordapp.com/api/v8/gateway")
1923
if err != nil {
2024
log.Println(err)
2125
w.WriteHeader(http.StatusInternalServerError)
@@ -28,7 +32,74 @@ func StartHealthCheckServer(port string) {
2832
} else {
2933
w.Write([]byte("unready"))
3034
}
35+
36+
if resp.StatusCode == http.StatusTooManyRequests {
37+
orgId := os.Getenv("SCW_ORGANIZATION_ID")
38+
accessKey := os.Getenv("SCW_ACCESS_KEY")
39+
secretKey := os.Getenv("SCW_SECRET_KEY")
40+
nodeID := os.Getenv("SCW_NODE_ID")
41+
if orgId == "" || accessKey == "" || secretKey == "" || nodeID == "" {
42+
log.Println("One of the Scaleway credentials was null, not replacing any nodes!")
43+
return
44+
}
45+
46+
TerminateScalewayNode(orgId, accessKey, secretKey, nodeID)
47+
}
3148
})
3249

3350
http.ListenAndServe(":"+port, r)
3451
}
52+
53+
func TerminateScalewayNode(org, access, secret, nodeID string) {
54+
client, err := scw.NewClient(
55+
// Get your credentials at https://console.scaleway.com/project/credentials
56+
scw.WithDefaultOrganizationID(org),
57+
scw.WithAuth(access, secret),
58+
)
59+
if err != nil {
60+
panic(err)
61+
}
62+
63+
kApi := k8s.NewAPI(client)
64+
65+
nodes, err := kApi.ListNodes(&k8s.ListNodesRequest{
66+
Region: scw.RegionFrPar,
67+
ClusterID: os.Getenv("SCW_CLUSTER_ID"),
68+
PoolID: nil,
69+
OrderBy: "",
70+
Page: nil,
71+
PageSize: nil,
72+
Name: nil,
73+
Status: "",
74+
})
75+
if err != nil {
76+
log.Println(err)
77+
return
78+
}
79+
refUid := formatUUID(nodeID)
80+
log.Println(refUid)
81+
for _, v := range nodes.Nodes {
82+
log.Println(v.ID)
83+
if strings.HasPrefix(v.ID, refUid) {
84+
nodeID = v.ID
85+
break
86+
}
87+
}
88+
89+
_, err = kApi.ReplaceNode(&k8s.ReplaceNodeRequest{
90+
Region: scw.RegionFrPar,
91+
NodeID: nodeID,
92+
})
93+
if err != nil {
94+
log.Println("Error replacing " + refUid + ": " + err.Error())
95+
}
96+
}
97+
98+
func formatUUID(id string) string {
99+
ids := strings.Split(id, "-")
100+
id = ids[len(ids)-1]
101+
if len(id) < 20 {
102+
return ""
103+
}
104+
return id[0:8] + "-" + id[8:12] + "-" + id[12:16] + "-" + id[16:20] + "-" + id[20:]
105+
}

discord/message_handlers.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,5 @@ func (bot *Bot) handleGameStartMessage(s *discordgo.Session, m *discordgo.Messag
415415
bot.RedisInterface.SetDiscordGameState(dgs, lock)
416416

417417
log.Println("Added self game state message")
418-
419-
if dgs.AmongUsData.GetPhase() != game.MENU {
420-
for _, e := range bot.StatusEmojis[true] {
421-
go dgs.AddReaction(s, e.FormatForReaction())
422-
}
423-
dgs.AddReaction(s, "❌")
424-
}
418+
go dgs.AddAllReactions(bot.SessionManager.GetPrimarySession(), bot.StatusEmojis[true])
425419
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/jackc/pgx/v4 v4.9.2
1616
github.com/joho/godotenv v1.3.0
1717
github.com/nicksnyder/go-i18n/v2 v2.1.1
18+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7
1819
golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9 // indirect
1920
golang.org/x/sys v0.0.0-20201113135734-0a15ea8d9b02 // indirect
2021
golang.org/x/text v0.3.4

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ github.com/denverquane/discordgo v0.24.1 h1:6XS7kRGgnZnbYbEkGNOLC6zDWtW2s3XJeVXM
3131
github.com/denverquane/discordgo v0.24.1/go.mod h1:VLV+ZuXWxlP2Tw88Yx7qgVApBy0yEMnvJQ1Us1UE4zE=
3232
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
3333
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
34+
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
3435
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
3536
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
3637
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -178,6 +179,8 @@ github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
178179
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
179180
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
180181
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
182+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7 h1:Do8ksLD4Nr3pA0x0hnLOLftZgkiTDvwPDShRTUxtXpE=
183+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
181184
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
182185
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc h1:jUIKcSPO9MoMJBbEoyE/RJoE8vz7Mb8AjvifMMwSyvY=
183186
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=

0 commit comments

Comments
 (0)