Add functional ban records
All checks were successful
Build and push container image / build (push) Successful in 41s
All checks were successful
Build and push container image / build (push) Successful in 41s
This commit is contained in:
parent
5e7c96930d
commit
7e486cb8ce
@ -1,4 +1,6 @@
|
||||
tokens.json
|
||||
renovate.json
|
||||
GCP_SERVICE.json
|
||||
# I don't have a clue why that file is in all caps... Thanks Google.
|
||||
.gitignore
|
||||
.gitea/*
|
@ -39,8 +39,8 @@ func commandsJSON() (commandList []discord.ApplicationCommandCreate) {
|
||||
},
|
||||
},
|
||||
discord.ApplicationCommandOptionString{
|
||||
Name: "google-sheets",
|
||||
Description: "Set the Google Sheets URL that will be used to display ban records",
|
||||
Name: "google-spreadsheet-id",
|
||||
Description: "Set the ID of the Google Spreadsheet that will be used to display ban records",
|
||||
Required: false,
|
||||
},
|
||||
},
|
||||
|
@ -6,6 +6,8 @@ services:
|
||||
volumes:
|
||||
- ./tokens.json:/home/corn-util/tokens.json:ro
|
||||
- ./config.json:/home/corn-util/config.json:rw
|
||||
- ./GCP_SERVICE.json:/home/corn-util/GCP_SERVICE.json:ro
|
||||
- ./uuidCache.log:/home/corn-util/uuidCache.log:rw
|
||||
expose:
|
||||
- 23242:23242
|
||||
restart: unless-stopped
|
||||
|
@ -103,7 +103,7 @@ func ListenForCommand(e *events.ApplicationCommandInteractionCreate) {
|
||||
case "config":
|
||||
type jsonDataStruct struct {
|
||||
BanRecords string `json:"banRecords"`
|
||||
GoogleSheets string `json:"googleSheets"`
|
||||
GoogleSpreadsheetID string `json:"googleSpreadsheetId"`
|
||||
}
|
||||
readData, _ := loaders.DataLoader.Read(&loaders.JSON{}, "config.json")
|
||||
jsonData := jsonDataStruct{}
|
||||
@ -111,7 +111,7 @@ func ListenForCommand(e *events.ApplicationCommandInteractionCreate) {
|
||||
json.Unmarshal(jsonDataBytes, &jsonData)
|
||||
|
||||
banRecordsCh, _ := e.SlashCommandInteractionData().OptChannel("ban-records")
|
||||
googleSheetsURL, _ := e.SlashCommandInteractionData().OptString("google-sheets")
|
||||
googleSpreadsheet_Id, _ := e.SlashCommandInteractionData().OptString("google-spreadsheet-id")
|
||||
|
||||
if !isGuildManager(e) {
|
||||
DumpErrToInteraction(e, fmt.Errorf(noPermText))
|
||||
@ -136,12 +136,12 @@ func ListenForCommand(e *events.ApplicationCommandInteractionCreate) {
|
||||
Inline: &TRUE,
|
||||
},
|
||||
{
|
||||
Name: "Google Sheets",
|
||||
Name: "Google Spreadsheet ID",
|
||||
Value: func() string {
|
||||
if jsonData.GoogleSheets == "" {
|
||||
if jsonData.GoogleSpreadsheetID == "" {
|
||||
return noConfigValText
|
||||
} else {
|
||||
return fmt.Sprintf("`%v`", jsonData.GoogleSheets)
|
||||
return fmt.Sprintf("`%v`", jsonData.GoogleSpreadsheetID)
|
||||
}
|
||||
}(),
|
||||
Inline: &TRUE,
|
||||
@ -159,8 +159,7 @@ func ListenForCommand(e *events.ApplicationCommandInteractionCreate) {
|
||||
if _, err := e.Client().Rest().CreateMessage(banRecordsCh.ID, discord.MessageCreate{
|
||||
Embeds: []discord.Embed{
|
||||
{
|
||||
Description: "This is a placeholder embed for ban records.\n" +
|
||||
"Once the bot is configured, this will be updated with the latest ban records from Google Sheets.",
|
||||
Description: "Ban records on Google Sheets will now be sent in this channel.",
|
||||
Color: mainEmbedColor,
|
||||
},
|
||||
},
|
||||
@ -186,10 +185,16 @@ func ListenForCommand(e *events.ApplicationCommandInteractionCreate) {
|
||||
data["banRecords"] = jsonData.BanRecords
|
||||
}
|
||||
|
||||
if googleSheetsURL != "" {
|
||||
data["googleSheets"] = googleSheetsURL
|
||||
if googleSpreadsheet_Id != "" {
|
||||
if strings.Contains(googleSpreadsheet_Id, "docs.google.com/spreadsheets/d/") {
|
||||
googleSpreadsheet_Id = strings.Split(googleSpreadsheet_Id, "/")[5]
|
||||
log.Warnf("detected the url: \"%v\", splitting...", googleSpreadsheet_Id)
|
||||
} else {
|
||||
data["googleSheets"] = jsonData.GoogleSheets
|
||||
googleSpreadsheet_Id = strings.Split(googleSpreadsheet_Id, "/")[0]
|
||||
}
|
||||
data["googleSpreadsheetId"] = googleSpreadsheet_Id
|
||||
} else {
|
||||
data["googleSpreadsheetId"] = jsonData.GoogleSpreadsheetID
|
||||
}
|
||||
|
||||
err := loaders.DataLoader.Write(&loaders.JSON{}, "config.json", data)
|
||||
|
7
go.mod
7
go.mod
@ -10,11 +10,16 @@ require (
|
||||
github.com/mackerelio/go-osstat v0.2.4
|
||||
github.com/shirou/gopsutil/v3 v3.23.9
|
||||
github.com/zcalusic/sysinfo v1.0.2
|
||||
golang.org/x/oauth2 v0.13.0
|
||||
gopkg.in/Iwark/spreadsheet.v2 v2.0.0-20230915040305-7677e8164883
|
||||
)
|
||||
|
||||
require (
|
||||
cloud.google.com/go/compute v1.23.1 // indirect
|
||||
cloud.google.com/go/compute/metadata v0.2.3 // indirect
|
||||
github.com/disgoorg/json v1.1.0 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20231016141302-07b5767bb0ed // indirect
|
||||
@ -26,4 +31,6 @@ require (
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
)
|
||||
|
43
go.sum
43
go.sum
@ -1,3 +1,7 @@
|
||||
cloud.google.com/go/compute v1.23.1 h1:V97tBoDaZHb6leicZ1G6DLK2BAaZLJ/7+9BB/En3hR0=
|
||||
cloud.google.com/go/compute v1.23.1/go.mod h1:CqB3xpmPKKt3OJpW2ndFIXnA9A4xAy/F3Xp1ixncW78=
|
||||
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
|
||||
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -14,6 +18,11 @@ github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+m
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
@ -49,23 +58,57 @@ github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFA
|
||||
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
||||
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
||||
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
|
||||
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
github.com/zcalusic/sysinfo v1.0.2 h1:nwTTo2a+WQ0NXwo0BGRojOJvJ/5XKvQih+2RrtWqfxc=
|
||||
github.com/zcalusic/sysinfo v1.0.2/go.mod h1:kluzTYflRWo6/tXVMJPdEjShsbPpsFRyy+p1mBQPC30=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
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/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY=
|
||||
golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0=
|
||||
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/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/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.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
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.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
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/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
||||
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/Iwark/spreadsheet.v2 v2.0.0-20230915040305-7677e8164883 h1:P76GtA9CSDE7tooNd+JRcG5Qzxq8Y236qtgCBxN8WRM=
|
||||
gopkg.in/Iwark/spreadsheet.v2 v2.0.0-20230915040305-7677e8164883/go.mod h1:AJiLW20RvjD8NFw7OxNQFAWXlvIJeb9TDTGBsfCzFcM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
13
main.go
13
main.go
@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
botEvents "corn-util/bot/events"
|
||||
"corn-util/bot/loaders"
|
||||
"corn-util/bot/toolbox"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/disgoorg/disgo"
|
||||
"github.com/disgoorg/disgo/bot"
|
||||
@ -49,6 +51,17 @@ func main() {
|
||||
Content: "Container has been reloaded.",
|
||||
}, true, 0)
|
||||
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
defer ticker.Stop()
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
toolbox.RetrieveSheetData()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
s := make(chan os.Signal, 1)
|
||||
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||
<-s
|
||||
|
111
toolbox/google.go
Normal file
111
toolbox/google.go
Normal file
@ -0,0 +1,111 @@
|
||||
package toolbox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"corn-util/bot/loaders"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/disgo/rest"
|
||||
"github.com/disgoorg/log"
|
||||
"github.com/disgoorg/snowflake/v2"
|
||||
"golang.org/x/oauth2/google"
|
||||
"gopkg.in/Iwark/spreadsheet.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
TRUE = true
|
||||
recordAddedColor = 0x57f287
|
||||
recordRemovedColor = 0xed4245
|
||||
uuidCacheFile = "uuidCache.log"
|
||||
)
|
||||
|
||||
type SpreadsheetCells struct {
|
||||
UUID string
|
||||
IGN string
|
||||
}
|
||||
|
||||
func RetrieveSheetData() {
|
||||
// Read the required values from config store
|
||||
type jsonDataStruct struct {
|
||||
GoogleSpreadsheetID string `json:"googleSpreadsheetId"`
|
||||
BanRecords string `json:"banRecords"`
|
||||
}
|
||||
readData, _ := loaders.DataLoader.Read(&loaders.JSON{}, "config.json")
|
||||
jsonData := jsonDataStruct{}
|
||||
jsonDataBytes, _ := json.Marshal(readData)
|
||||
json.Unmarshal(jsonDataBytes, &jsonData)
|
||||
|
||||
spreadsheetId := jsonData.GoogleSpreadsheetID
|
||||
|
||||
ServiceAccount, _ := os.ReadFile("GCP_SERVICE.json")
|
||||
conf, err := google.JWTConfigFromJSON(ServiceAccount, spreadsheet.Scope)
|
||||
if err != nil {
|
||||
log.Errorf("error creating JWT config: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := conf.Client(context.TODO())
|
||||
service := spreadsheet.NewServiceWithClient(client)
|
||||
|
||||
log.Infof("[BAN-RECORDS] Checking for new data...")
|
||||
spreadsheet, err := service.FetchSpreadsheet(spreadsheetId)
|
||||
if err != nil {
|
||||
log.Errorf("error fetching spreadsheet: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
rowData := spreadsheet.Sheets[0].Data.GridData[0].RowData
|
||||
if len(rowData) < 2 {
|
||||
fmt.Println("not enough data in spreadsheet")
|
||||
return
|
||||
}
|
||||
|
||||
cachedUUIDsDATA, err := os.ReadFile(uuidCacheFile)
|
||||
if err != nil {
|
||||
log.Errorf("error reading uuidCacheFile: %v", err)
|
||||
return
|
||||
}
|
||||
cachedUUIDs := make(map[string]bool)
|
||||
for _, line := range strings.Split(string(cachedUUIDsDATA), "\n") {
|
||||
cachedUUIDs[line] = true
|
||||
}
|
||||
|
||||
discordEmbedData := discord.Embed{Color: recordAddedColor}
|
||||
for _, row := range rowData {
|
||||
if len(row.Values) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
uuid := row.Values[0].FormattedValue
|
||||
ign := row.Values[1].FormattedValue
|
||||
if uuid == "UUID" && ign == "IGN" {
|
||||
continue
|
||||
}
|
||||
if cachedUUIDs[uuid] {
|
||||
continue
|
||||
}
|
||||
|
||||
field := discord.EmbedField{Name: ign, Value: fmt.Sprintf("`%v`", uuid)}
|
||||
discordEmbedData.Title = "Ban record added"
|
||||
discordEmbedData.Fields = append(discordEmbedData.Fields, field)
|
||||
cachedUUIDs[uuid] = true
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
for uuid := range cachedUUIDs {
|
||||
sb.WriteString(uuid)
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
err = os.WriteFile(uuidCacheFile, []byte(sb.String()), 0644)
|
||||
if err != nil {
|
||||
log.Errorf("error writing uuidCacheFile: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
channel, _ := rest.Channels.GetChannel(rest.NewChannels(rest.NewClient(loaders.TokenLoader("bot"))), snowflake.MustParse(jsonData.BanRecords))
|
||||
rest.Channels.CreateMessage(rest.NewChannels(rest.NewClient(loaders.TokenLoader("bot"))), channel.ID(), discord.MessageCreate{Embeds: []discord.Embed{discordEmbedData}})
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
package toolbox
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
System/OS-related utilities such as uptime.
|
||||
@ -14,5 +17,11 @@ var timerStart = time.Now()
|
||||
*/
|
||||
func GetUptime() string {
|
||||
uptime := time.Since(timerStart)
|
||||
return uptime.Round(time.Second).String()
|
||||
roundedUp := uptime.Round(time.Second)
|
||||
days := roundedUp / (24 * time.Hour)
|
||||
hours := roundedUp % (24 * time.Hour) / time.Hour
|
||||
if days > 0 {
|
||||
return fmt.Sprintf("%dd,%dh", days, hours)
|
||||
}
|
||||
return roundedUp.String()
|
||||
}
|
||||
|
Reference in New Issue
Block a user