Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARCHIVER_ADDR=
S3_ENDPOINT=
S3_ACCESS=
S3_SECRET=
S3_BUCKET=
PRODUCTION_MODE=
41 changes: 9 additions & 32 deletions cmd/cleanuser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ import (
"strconv"
"strings"

"github.com/TicketsBot-cloud/gdl/objects/channel/message"
"github.com/TicketsBot-cloud/logarchiver/pkg/config"
"github.com/TicketsBot-cloud/logarchiver/pkg/model"
v1 "github.com/TicketsBot-cloud/logarchiver/pkg/model/v1"
v2 "github.com/TicketsBot-cloud/logarchiver/pkg/model/v2"
"github.com/TicketsBot-cloud/logarchiver/pkg/s3client"
"github.com/TicketsBot-cloud/logarchiver/pkg/utils"
"github.com/TicketsBot/common/encryption"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)

var (
Expand All @@ -39,17 +35,11 @@ func main() {
panic("either -ticket, -all or -csv must be set")
}

client, err := minio.New(cfg.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
Secure: cfg.Secure,
})

s3Client, err := s3client.NewFromCliConfig(cfg)
if err != nil {
panic(err)
}

s3Client := s3client.NewS3Client(client, cfg.Bucket)

var count int
if *csv != "" {
tickets := parseCsv(*csv)
Expand Down Expand Up @@ -77,7 +67,7 @@ func main() {
}

for _, key := range keys {
ticketId, err := strconv.Atoi(key[strings.LastIndex(key, "/")+1:])
ticketId, err := s3client.TicketIDFromKey(key)
if err != nil {
fmt.Printf("error occurred while parsing id of %s: %v\n", key, err)
continue
Expand Down Expand Up @@ -130,23 +120,9 @@ func clean(client *s3client.S3Client, guildId uint64, ticketId int) (int, error)
panic(err)
}

var transcript v2.Transcript

version := model.GetVersion(data)
switch version {
case model.V1:
var messages []message.Message
if err := json.Unmarshal(data, &messages); err != nil {
panic(err)
}

transcript = v1.ConvertToV2(messages)
case model.V2:
if err := json.Unmarshal(data, &transcript); err != nil {
panic(err)
}
default:
panic(fmt.Sprintf("Unknown version %d", version))
transcript, err := utils.Decode(data)
if err != nil {
return 0, err
}

transcript.Entities.Users[*userId] = v2.User{
Expand Down Expand Up @@ -204,9 +180,10 @@ func parseCsv(file string) map[uint64][]int {
ticketIdIdx := -1

for i, h := range header {
if h == "guild_id" {
switch h {
case "guild_id":
guildIdIdx = i
} else if h == "ticket_id" || h == "id" {
case "ticket_id", "id":
ticketIdIdx = i
}
}
Expand Down
12 changes: 2 additions & 10 deletions cmd/deletetranscript/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (

"github.com/TicketsBot-cloud/logarchiver/pkg/config"
"github.com/TicketsBot-cloud/logarchiver/pkg/s3client"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"

_ "github.com/joho/godotenv/autoload"
)
Expand All @@ -29,25 +27,19 @@ func main() {
panic("guild id must be set")
}

m, err := minio.New(cfg.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
Secure: cfg.Secure,
})

client, err := s3client.NewFromCliConfig(cfg)
if err != nil {
panic(err)
}

client := s3client.NewS3Client(m, cfg.Bucket)

if *all {
keys, err := client.GetAllKeysForGuild(context.Background(), *guildId)
if err != nil {
panic(err)
}

for _, key := range keys {
ticketId, err := strconv.Atoi(key[strings.LastIndex(key, "/")+1:])
ticketId, err := s3client.TicketIDFromKey(key)
if err != nil {
fmt.Printf("error occurred while parsing id of %s: %v\n", key, err)
continue
Expand Down
41 changes: 6 additions & 35 deletions cmd/exportguild/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ import (
"flag"
"fmt"
"os"
"strconv"
"strings"

"github.com/TicketsBot-cloud/gdl/objects/channel/message"
"github.com/TicketsBot-cloud/logarchiver/pkg/config"
"github.com/TicketsBot-cloud/logarchiver/pkg/model"
v1 "github.com/TicketsBot-cloud/logarchiver/pkg/model/v1"
v22 "github.com/TicketsBot-cloud/logarchiver/pkg/model/v2"
"github.com/TicketsBot-cloud/logarchiver/pkg/s3client"
"github.com/TicketsBot-cloud/logarchiver/pkg/utils"
"github.com/TicketsBot/common/encryption"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"golang.org/x/sync/errgroup"
)

Expand All @@ -37,17 +31,11 @@ func main() {
flag.Parse()
conf := config.Parse[config.CliConfig]()

// create minio client
m, err := minio.New(conf.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(conf.AccessKey, conf.SecretKey, ""),
Secure: conf.Secure,
})
client, err := s3client.NewFromCliConfig(conf)
if err != nil {
panic(err)
}

client := s3client.NewS3Client(m, conf.Bucket)

// likely to be file exists
_ = os.Mkdir(fmt.Sprintf("export/%d", *guildId), 0)

Expand All @@ -69,11 +57,10 @@ func main() {
}()

group, _ := errgroup.WithContext(context.Background())
for i := 0; i < workers; i++ {
for range workers {
group.Go(func() error {
for key := range keyCh {
id := key[strings.LastIndex(key, "/")+1:]
parsed, err := strconv.Atoi(id)
parsed, err := s3client.TicketIDFromKey(key)
must(err)

if after != nil && *after > 0 && parsed < *after {
Expand Down Expand Up @@ -104,24 +91,8 @@ func export(id int, client *s3client.S3Client) {
must(err)

if *convert || (userWhitelist != nil && *userWhitelist > 0) {
var transcript v22.Transcript

version := model.GetVersion(data)
switch version {
case model.V1:
var messages []message.Message
if err := json.Unmarshal(data, &messages); err != nil {
panic(err)
}

transcript = v1.ConvertToV2(messages)
case model.V2:
if err := json.Unmarshal(data, &transcript); err != nil {
panic(err)
}
default:
panic(fmt.Sprintf("Unknown version %d", version))
}
transcript, err := utils.Decode(data)
must(err)

data, err = json.Marshal(transcript)
must(err)
Expand Down
37 changes: 0 additions & 37 deletions cmd/exportuser/cachedata.go

This file was deleted.

44 changes: 10 additions & 34 deletions cmd/exportuser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ import (
"time"

"github.com/TicketsBot-cloud/gdl/cache"
"github.com/TicketsBot-cloud/gdl/objects/channel/message"
"github.com/TicketsBot-cloud/logarchiver/pkg/config"
"github.com/TicketsBot-cloud/logarchiver/pkg/model"
v1 "github.com/TicketsBot-cloud/logarchiver/pkg/model/v1"
v2 "github.com/TicketsBot-cloud/logarchiver/pkg/model/v2"
"github.com/TicketsBot-cloud/logarchiver/pkg/s3client"
"github.com/TicketsBot-cloud/logarchiver/pkg/utils"
"github.com/TicketsBot/common/encryption"
"github.com/TicketsBot/database"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"go.uber.org/zap"
)

Expand All @@ -34,7 +30,7 @@ var (

func main() {
flag.Parse()
conf := config.Parse()
conf := config.Parse[config.CliConfig]()

// likely to be file exists
_ = os.Mkdir(fmt.Sprintf("export_user/%d", *userId), 0)
Expand Down Expand Up @@ -125,18 +121,12 @@ func main() {
getTranscripts(conf, transcriptIds)
}

func getTranscripts(conf config.Config, tickets map[uint64][]int) {
// create minio client
m, err := minio.New(conf.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(conf.AccessKey, conf.SecretKey, ""),
Secure: conf.Secure,
})
func getTranscripts(conf config.CliConfig, tickets map[uint64][]int) {
client, err := s3client.NewFromCliConfig(conf)
if err != nil {
panic(err)
}

client := s3client.NewS3Client(m, conf.Bucket)

logger, err := zap.NewDevelopment()
if err != nil {
panic(err)
Expand Down Expand Up @@ -168,24 +158,10 @@ func getTranscripts(conf config.Config, tickets map[uint64][]int) {
continue
}

// Convert to v2 if needed
var transcript v2.Transcript

version := model.GetVersion(data)
switch version {
case model.V1:
var messages []message.Message
if err := json.Unmarshal(data, &messages); err != nil {
panic(err)
}

transcript = v1.ConvertToV2(messages)
case model.V2:
if err := json.Unmarshal(data, &transcript); err != nil {
panic(err)
}
default:
panic(fmt.Sprintf("Unknown version %d", version))
transcript, err := utils.Decode(data)
if err != nil {
logger.Error("failed to decode transcript", zap.Error(err), zap.Uint64("guildId", guildId), zap.Int("ticketId", ticketId))
continue
}

transcript.Entities.Channels = nil
Expand Down Expand Up @@ -486,8 +462,8 @@ WHERE "activated_by" = $1;`
func getCacheData(cache *cache.PgCache, userId uint64) map[string]interface{} {
data := make(map[string]interface{})

user, ok := cache.GetUser(userId)
if ok {
user, err := cache.GetUser(context.Background(), userId)
if err == nil {
data["user"] = user
} else {
data["user"] = nil
Expand Down
2 changes: 0 additions & 2 deletions cmd/exportuser/userdata.go

This file was deleted.

4 changes: 1 addition & 3 deletions cmd/fix-file-names/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"flag"
"strings"
"sync"
"sync/atomic"
Expand All @@ -16,8 +15,7 @@ import (
const workers = 30

func main() {
flag.Parse()
conf := config.Parse()
conf := config.Parse[config.CliConfig]()

// create minio client
client, err := minio.New(conf.Endpoint, &minio.Options{
Expand Down
6 changes: 0 additions & 6 deletions envvars.md

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.0

toolchain go1.24.2

// replace github.com/TicketsBot-cloud/gdl => ../gdl
replace github.com/TicketsBot-cloud/gdl => ../gdl

require (
github.com/TicketsBot-cloud/gdl v0.0.0-20250509054940-2045fbe19c06
Expand All @@ -18,6 +18,7 @@ require (
github.com/jackc/pgx/v4 v4.18.3
github.com/jackc/pgx/v5 v5.6.0
github.com/joho/godotenv v1.5.1
github.com/klauspost/compress v1.17.9
github.com/minio/minio-go/v7 v7.0.73
go.uber.org/zap v1.23.0
golang.org/x/sync v0.8.0
Expand All @@ -44,7 +45,6 @@ require (
github.com/jackc/puddle v1.3.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/TicketsBot-cloud/gdl v0.0.0-20250509054940-2045fbe19c06 h1:PzziB2S58d9agJtpaPVrYMTuBiJICr2QIGQoqL6l3z0=
github.com/TicketsBot-cloud/gdl v0.0.0-20250509054940-2045fbe19c06/go.mod h1:CdwBR2egPtxUXjD2CgC9ZwfuB8dz9HPePM8nuG6dt7Y=
github.com/TicketsBot/common v0.0.0-20230723121853-8d873b27086e h1:K7c0kRXxaW14dl9G9rQ78eGP+Lu+F7qPxTud/j68SQQ=
github.com/TicketsBot/common v0.0.0-20230723121853-8d873b27086e/go.mod h1:rZuaTbjajlxscl628aBgUGiUZcOVLvF6pfsPL+2JOac=
github.com/TicketsBot/database v0.0.0-20220217133004-d190910ad66f h1:kBIHaAxyIGqxgwz/ZRggNGjyIdZ3ctWZqjJ9Svrn4L4=
Expand Down
Loading
Loading