From f2a859d08446a083642fdfc8cc8646f7b2b36764 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Sat, 12 Feb 2022 01:18:29 +0100 Subject: [PATCH] fixed module path; added translate endpoint to chat API --- config_example.yaml | 6 +++- csgo/demo_loader.go | 19 ++++------- csgo/demo_parser.go | 10 +++--- ent/client.go | 16 ++++----- ent/ent.go | 14 ++++---- ent/enttest/enttest.go | 5 +-- ent/hook/hook.go | 3 +- ent/match.go | 2 +- ent/match/where.go | 2 +- ent/match_create.go | 6 ++-- ent/match_delete.go | 4 +-- ent/match_query.go | 8 ++--- ent/match_update.go | 8 ++--- ent/matchplayer.go | 6 ++-- ent/matchplayer/where.go | 3 +- ent/matchplayer_create.go | 14 ++++---- ent/matchplayer_delete.go | 4 +-- ent/matchplayer_query.go | 16 ++++----- ent/matchplayer_update.go | 16 ++++----- ent/messages.go | 4 +-- ent/messages/where.go | 3 +- ent/messages_create.go | 4 +-- ent/messages_delete.go | 4 +-- ent/messages_query.go | 6 ++-- ent/messages_update.go | 6 ++-- ent/mutation.go | 17 +++++----- ent/player.go | 2 +- ent/player/where.go | 2 +- ent/player_create.go | 6 ++-- ent/player_delete.go | 4 +-- ent/player_query.go | 8 ++--- ent/player_update.go | 8 ++--- ent/roundstats.go | 4 +-- ent/roundstats/where.go | 3 +- ent/roundstats_create.go | 4 +-- ent/roundstats_delete.go | 4 +-- ent/roundstats_query.go | 6 ++-- ent/roundstats_update.go | 6 ++-- ent/runtime.go | 7 ++-- ent/runtime/runtime.go | 2 +- ent/spray.go | 4 +-- ent/spray/where.go | 3 +- ent/spray_create.go | 4 +-- ent/spray_delete.go | 4 +-- ent/spray_query.go | 6 ++-- ent/spray_update.go | 6 ++-- ent/weapon.go | 4 +-- ent/weapon/where.go | 3 +- ent/weapon_create.go | 4 +-- ent/weapon_delete.go | 4 +-- ent/weapon_query.go | 6 ++-- ent/weapon_update.go | 6 ++-- go.mod | 2 +- go.sum | 5 +++ main.go | 71 ++++++++++++++++++++++++++++++++++----- utils/utils.go | 36 ++++++++++++++------ 56 files changed, 256 insertions(+), 184 deletions(-) diff --git a/config_example.yaml b/config_example.yaml index fba3d15..3a46832 100644 --- a/config_example.yaml +++ b/config_example.yaml @@ -50,4 +50,8 @@ csgowtfd: # seconds to write a response before timeout write: 30 # seconds before closing idle connections - idle: 120 \ No newline at end of file + idle: 120 + deepl: + base_url: api-free.deepl.com + # get your API key on deepl.com + api_key: \ No newline at end of file diff --git a/csgo/demo_loader.go b/csgo/demo_loader.go index 6979087..51b98f2 100644 --- a/csgo/demo_loader.go +++ b/csgo/demo_loader.go @@ -2,9 +2,9 @@ package csgo import ( "context" - "csgowtfd/ent" - "csgowtfd/utils" "fmt" + "git.harting.dev/csgowtf/csgowtfd/ent" + "git.harting.dev/csgowtf/csgowtfd/utils" "github.com/an0nfunc/go-steam/v3" "github.com/an0nfunc/go-steam/v3/csgo/protocol/protobuf" "github.com/an0nfunc/go-steam/v3/netutil" @@ -356,16 +356,11 @@ func (dml *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { } iMatch, err := dml.db.Match.Get(context.Background(), matchId) - if err != nil { - switch e := err.(type) { - case *ent.NotFoundError: - break - default: - log.Errorf("[DL] Failure trying to lookup match %d in db: %v", matchId, e) - dml.unlockDemo(demo) - continue - } - } else { + if err != nil && !ent.IsNotFound(err) { + log.Errorf("[DL] Failure trying to lookup match %d in db: %v", matchId, err) + dml.unlockDemo(demo) + continue + } else if err == nil { if iMatch.DemoParsed == false && iMatch.Date.After(time.Now().UTC().AddDate(0, 0, -30)) { log.Infof("[DL] Match %d is loaded, but not parsed. Try parsing.", iMatch.ID) demo.MatchId = matchId diff --git a/csgo/demo_parser.go b/csgo/demo_parser.go index f72afd0..95363b8 100644 --- a/csgo/demo_parser.go +++ b/csgo/demo_parser.go @@ -4,12 +4,12 @@ import ( "bytes" "compress/bzip2" "context" - "csgowtfd/ent" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/player" "encoding/gob" "fmt" + "git.harting.dev/csgowtf/csgowtfd/ent" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/player" "github.com/golang/geo/r2" "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs" "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common" @@ -157,7 +157,7 @@ func (dp *DemoParser) MatchPlayerBySteamID(stats []*ent.MatchPlayer, steamId uin for _, tStats := range stats { tPLayer, err := tStats.Edges.PlayersOrErr() if err != nil { - return nil, fmt.Errorf("Unbale to get Stats from statList: %v", err) + return nil, fmt.Errorf("unable to get stats from statList: %w", err) } if tPLayer.ID == steamId { return tStats, nil diff --git a/ent/client.go b/ent/client.go index cd9769e..fb3551c 100644 --- a/ent/client.go +++ b/ent/client.go @@ -7,15 +7,15 @@ import ( "fmt" "log" - "csgowtfd/ent/migrate" + "git.harting.dev/csgowtf/csgowtfd/ent/migrate" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" - "csgowtfd/ent/player" - "csgowtfd/ent/roundstats" - "csgowtfd/ent/spray" - "csgowtfd/ent/weapon" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" diff --git a/ent/ent.go b/ent/ent.go index 5e09a9a..56d2b89 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -3,18 +3,18 @@ package ent import ( - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" - "csgowtfd/ent/player" - "csgowtfd/ent/roundstats" - "csgowtfd/ent/spray" - "csgowtfd/ent/weapon" "errors" "fmt" "entgo.io/ent" "entgo.io/ent/dialect/sql" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" ) // ent aliases to avoid import conflicts in user's code. diff --git a/ent/enttest/enttest.go b/ent/enttest/enttest.go index 7087598..3764078 100644 --- a/ent/enttest/enttest.go +++ b/ent/enttest/enttest.go @@ -4,9 +4,10 @@ package enttest import ( "context" - "csgowtfd/ent" + + "git.harting.dev/csgowtf/csgowtfd/ent" // required by schema hooks. - _ "csgowtfd/ent/runtime" + _ "git.harting.dev/csgowtf/csgowtfd/ent/runtime" "entgo.io/ent/dialect/sql/schema" ) diff --git a/ent/hook/hook.go b/ent/hook/hook.go index 963ce67..ce000a9 100644 --- a/ent/hook/hook.go +++ b/ent/hook/hook.go @@ -4,8 +4,9 @@ package hook import ( "context" - "csgowtfd/ent" "fmt" + + "git.harting.dev/csgowtf/csgowtfd/ent" ) // The MatchFunc type is an adapter to allow the use of ordinary diff --git a/ent/match.go b/ent/match.go index 3c54a1f..a85f1ec 100644 --- a/ent/match.go +++ b/ent/match.go @@ -3,12 +3,12 @@ package ent import ( - "csgowtfd/ent/match" "fmt" "strings" "time" "entgo.io/ent/dialect/sql" + "git.harting.dev/csgowtf/csgowtfd/ent/match" ) // Match is the model entity for the Match schema. diff --git a/ent/match/where.go b/ent/match/where.go index e7e3059..d0c96c4 100644 --- a/ent/match/where.go +++ b/ent/match/where.go @@ -3,11 +3,11 @@ package match import ( - "csgowtfd/ent/predicate" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // ID filters vertices based on their ID field. diff --git a/ent/match_create.go b/ent/match_create.go index 59feea6..501f240 100644 --- a/ent/match_create.go +++ b/ent/match_create.go @@ -4,15 +4,15 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/player" "errors" "fmt" "time" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/player" ) // MatchCreate is the builder for creating a Match entity. diff --git a/ent/match_delete.go b/ent/match_delete.go index d5c66d6..e95440b 100644 --- a/ent/match_delete.go +++ b/ent/match_delete.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/predicate" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // MatchDelete is the builder for deleting a Match entity. diff --git a/ent/match_query.go b/ent/match_query.go index ce2ec35..53c6566 100644 --- a/ent/match_query.go +++ b/ent/match_query.go @@ -4,10 +4,6 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/player" - "csgowtfd/ent/predicate" "database/sql/driver" "errors" "fmt" @@ -16,6 +12,10 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // MatchQuery is the builder for querying Match entities. diff --git a/ent/match_update.go b/ent/match_update.go index 7c3bc36..ccbd8d9 100644 --- a/ent/match_update.go +++ b/ent/match_update.go @@ -4,10 +4,6 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/player" - "csgowtfd/ent/predicate" "errors" "fmt" "time" @@ -15,6 +11,10 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // MatchUpdate is the builder for updating Match entities. diff --git a/ent/matchplayer.go b/ent/matchplayer.go index 22ce97a..da12910 100644 --- a/ent/matchplayer.go +++ b/ent/matchplayer.go @@ -3,13 +3,13 @@ package ent import ( - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/player" "fmt" "strings" "entgo.io/ent/dialect/sql" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/player" ) // MatchPlayer is the model entity for the MatchPlayer schema. diff --git a/ent/matchplayer/where.go b/ent/matchplayer/where.go index 5f58e9e..5b87178 100644 --- a/ent/matchplayer/where.go +++ b/ent/matchplayer/where.go @@ -3,10 +3,9 @@ package matchplayer import ( - "csgowtfd/ent/predicate" - "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // ID filters vertices based on their ID field. diff --git a/ent/matchplayer_create.go b/ent/matchplayer_create.go index 435d8f2..4ef1450 100644 --- a/ent/matchplayer_create.go +++ b/ent/matchplayer_create.go @@ -4,18 +4,18 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" - "csgowtfd/ent/player" - "csgowtfd/ent/roundstats" - "csgowtfd/ent/spray" - "csgowtfd/ent/weapon" "errors" "fmt" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" ) // MatchPlayerCreate is the builder for creating a MatchPlayer entity. diff --git a/ent/matchplayer_delete.go b/ent/matchplayer_delete.go index 1f0199d..018657d 100644 --- a/ent/matchplayer_delete.go +++ b/ent/matchplayer_delete.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/predicate" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // MatchPlayerDelete is the builder for deleting a MatchPlayer entity. diff --git a/ent/matchplayer_query.go b/ent/matchplayer_query.go index db9bc5a..8debff2 100644 --- a/ent/matchplayer_query.go +++ b/ent/matchplayer_query.go @@ -4,14 +4,6 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" - "csgowtfd/ent/player" - "csgowtfd/ent/predicate" - "csgowtfd/ent/roundstats" - "csgowtfd/ent/spray" - "csgowtfd/ent/weapon" "database/sql/driver" "errors" "fmt" @@ -20,6 +12,14 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" ) // MatchPlayerQuery is the builder for querying MatchPlayer entities. diff --git a/ent/matchplayer_update.go b/ent/matchplayer_update.go index d3ae436..30d5873 100644 --- a/ent/matchplayer_update.go +++ b/ent/matchplayer_update.go @@ -4,20 +4,20 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" - "csgowtfd/ent/player" - "csgowtfd/ent/predicate" - "csgowtfd/ent/roundstats" - "csgowtfd/ent/spray" - "csgowtfd/ent/weapon" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" ) // MatchPlayerUpdate is the builder for updating MatchPlayer entities. diff --git a/ent/messages.go b/ent/messages.go index c488dbe..7a2e1fa 100644 --- a/ent/messages.go +++ b/ent/messages.go @@ -3,12 +3,12 @@ package ent import ( - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" "fmt" "strings" "entgo.io/ent/dialect/sql" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" ) // Messages is the model entity for the Messages schema. diff --git a/ent/messages/where.go b/ent/messages/where.go index fa8fdd7..243663b 100644 --- a/ent/messages/where.go +++ b/ent/messages/where.go @@ -3,10 +3,9 @@ package messages import ( - "csgowtfd/ent/predicate" - "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // ID filters vertices based on their ID field. diff --git a/ent/messages_create.go b/ent/messages_create.go index db9703e..cb0d345 100644 --- a/ent/messages_create.go +++ b/ent/messages_create.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" "errors" "fmt" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" ) // MessagesCreate is the builder for creating a Messages entity. diff --git a/ent/messages_delete.go b/ent/messages_delete.go index 25254b8..8596b7a 100644 --- a/ent/messages_delete.go +++ b/ent/messages_delete.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/messages" - "csgowtfd/ent/predicate" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // MessagesDelete is the builder for deleting a Messages entity. diff --git a/ent/messages_query.go b/ent/messages_query.go index c003a68..5d9f4e6 100644 --- a/ent/messages_query.go +++ b/ent/messages_query.go @@ -4,9 +4,6 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" - "csgowtfd/ent/predicate" "errors" "fmt" "math" @@ -14,6 +11,9 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // MessagesQuery is the builder for querying Messages entities. diff --git a/ent/messages_update.go b/ent/messages_update.go index b32108c..815d2be 100644 --- a/ent/messages_update.go +++ b/ent/messages_update.go @@ -4,15 +4,15 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" - "csgowtfd/ent/predicate" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // MessagesUpdate is the builder for updating Messages entities. diff --git a/ent/mutation.go b/ent/mutation.go index 2556b90..6e0f935 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -4,19 +4,20 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" - "csgowtfd/ent/player" - "csgowtfd/ent/predicate" - "csgowtfd/ent/roundstats" - "csgowtfd/ent/spray" - "csgowtfd/ent/weapon" "errors" "fmt" "sync" "time" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" + "entgo.io/ent" ) diff --git a/ent/player.go b/ent/player.go index 7d226b6..4171a46 100644 --- a/ent/player.go +++ b/ent/player.go @@ -3,12 +3,12 @@ package ent import ( - "csgowtfd/ent/player" "fmt" "strings" "time" "entgo.io/ent/dialect/sql" + "git.harting.dev/csgowtf/csgowtfd/ent/player" ) // Player is the model entity for the Player schema. diff --git a/ent/player/where.go b/ent/player/where.go index 6c784e6..328afd1 100644 --- a/ent/player/where.go +++ b/ent/player/where.go @@ -3,11 +3,11 @@ package player import ( - "csgowtfd/ent/predicate" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // ID filters vertices based on their ID field. diff --git a/ent/player_create.go b/ent/player_create.go index 9190e79..a0338a9 100644 --- a/ent/player_create.go +++ b/ent/player_create.go @@ -4,15 +4,15 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/player" "errors" "fmt" "time" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/player" ) // PlayerCreate is the builder for creating a Player entity. diff --git a/ent/player_delete.go b/ent/player_delete.go index a6a9a8c..fd25156 100644 --- a/ent/player_delete.go +++ b/ent/player_delete.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/player" - "csgowtfd/ent/predicate" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // PlayerDelete is the builder for deleting a Player entity. diff --git a/ent/player_query.go b/ent/player_query.go index 1176663..cbe058e 100644 --- a/ent/player_query.go +++ b/ent/player_query.go @@ -4,10 +4,6 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/player" - "csgowtfd/ent/predicate" "database/sql/driver" "errors" "fmt" @@ -16,6 +12,10 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // PlayerQuery is the builder for querying Player entities. diff --git a/ent/player_update.go b/ent/player_update.go index bc90d50..dc28bae 100644 --- a/ent/player_update.go +++ b/ent/player_update.go @@ -4,10 +4,6 @@ package ent import ( "context" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/player" - "csgowtfd/ent/predicate" "errors" "fmt" "time" @@ -15,6 +11,10 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // PlayerUpdate is the builder for updating Player entities. diff --git a/ent/roundstats.go b/ent/roundstats.go index 79f5f2b..fe61eec 100644 --- a/ent/roundstats.go +++ b/ent/roundstats.go @@ -3,12 +3,12 @@ package ent import ( - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/roundstats" "fmt" "strings" "entgo.io/ent/dialect/sql" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" ) // RoundStats is the model entity for the RoundStats schema. diff --git a/ent/roundstats/where.go b/ent/roundstats/where.go index eb652d3..0ca17f4 100644 --- a/ent/roundstats/where.go +++ b/ent/roundstats/where.go @@ -3,10 +3,9 @@ package roundstats import ( - "csgowtfd/ent/predicate" - "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // ID filters vertices based on their ID field. diff --git a/ent/roundstats_create.go b/ent/roundstats_create.go index 788e1e2..1603294 100644 --- a/ent/roundstats_create.go +++ b/ent/roundstats_create.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/roundstats" "errors" "fmt" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" ) // RoundStatsCreate is the builder for creating a RoundStats entity. diff --git a/ent/roundstats_delete.go b/ent/roundstats_delete.go index 4921780..0b0db72 100644 --- a/ent/roundstats_delete.go +++ b/ent/roundstats_delete.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/predicate" - "csgowtfd/ent/roundstats" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" ) // RoundStatsDelete is the builder for deleting a RoundStats entity. diff --git a/ent/roundstats_query.go b/ent/roundstats_query.go index a7cb7cd..3e731f8 100644 --- a/ent/roundstats_query.go +++ b/ent/roundstats_query.go @@ -4,9 +4,6 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/predicate" - "csgowtfd/ent/roundstats" "errors" "fmt" "math" @@ -14,6 +11,9 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" ) // RoundStatsQuery is the builder for querying RoundStats entities. diff --git a/ent/roundstats_update.go b/ent/roundstats_update.go index 89d3363..f4a21a6 100644 --- a/ent/roundstats_update.go +++ b/ent/roundstats_update.go @@ -4,15 +4,15 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/predicate" - "csgowtfd/ent/roundstats" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" ) // RoundStatsUpdate is the builder for updating RoundStats entities. diff --git a/ent/runtime.go b/ent/runtime.go index 0ad7602..6881139 100644 --- a/ent/runtime.go +++ b/ent/runtime.go @@ -3,10 +3,11 @@ package ent import ( - "csgowtfd/ent/match" - "csgowtfd/ent/player" - "csgowtfd/ent/schema" "time" + + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/schema" ) // The init function reads all schema descriptors with runtime code diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go index 4417d09..0b50306 100644 --- a/ent/runtime/runtime.go +++ b/ent/runtime/runtime.go @@ -2,7 +2,7 @@ package runtime -// The schema-stitching logic is generated in csgowtfd/ent/runtime.go +// The schema-stitching logic is generated in git.harting.dev/csgowtf/csgowtfd/ent/runtime.go const ( Version = "v0.10.0" // Version of ent codegen. diff --git a/ent/spray.go b/ent/spray.go index b5833e8..bd93c3c 100644 --- a/ent/spray.go +++ b/ent/spray.go @@ -3,12 +3,12 @@ package ent import ( - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/spray" "fmt" "strings" "entgo.io/ent/dialect/sql" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" ) // Spray is the model entity for the Spray schema. diff --git a/ent/spray/where.go b/ent/spray/where.go index a16d905..1066896 100644 --- a/ent/spray/where.go +++ b/ent/spray/where.go @@ -3,10 +3,9 @@ package spray import ( - "csgowtfd/ent/predicate" - "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // ID filters vertices based on their ID field. diff --git a/ent/spray_create.go b/ent/spray_create.go index 0d471cb..2124dc3 100644 --- a/ent/spray_create.go +++ b/ent/spray_create.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/spray" "errors" "fmt" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" ) // SprayCreate is the builder for creating a Spray entity. diff --git a/ent/spray_delete.go b/ent/spray_delete.go index d71ec28..d52bb4b 100644 --- a/ent/spray_delete.go +++ b/ent/spray_delete.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/predicate" - "csgowtfd/ent/spray" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" ) // SprayDelete is the builder for deleting a Spray entity. diff --git a/ent/spray_query.go b/ent/spray_query.go index dc57b7a..b7dcbca 100644 --- a/ent/spray_query.go +++ b/ent/spray_query.go @@ -4,9 +4,6 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/predicate" - "csgowtfd/ent/spray" "errors" "fmt" "math" @@ -14,6 +11,9 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" ) // SprayQuery is the builder for querying Spray entities. diff --git a/ent/spray_update.go b/ent/spray_update.go index d2e03cb..0bdd913 100644 --- a/ent/spray_update.go +++ b/ent/spray_update.go @@ -4,15 +4,15 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/predicate" - "csgowtfd/ent/spray" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" ) // SprayUpdate is the builder for updating Spray entities. diff --git a/ent/weapon.go b/ent/weapon.go index e50c5fd..7641a18 100644 --- a/ent/weapon.go +++ b/ent/weapon.go @@ -3,12 +3,12 @@ package ent import ( - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/weapon" "fmt" "strings" "entgo.io/ent/dialect/sql" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" ) // Weapon is the model entity for the Weapon schema. diff --git a/ent/weapon/where.go b/ent/weapon/where.go index 5be7106..a679911 100644 --- a/ent/weapon/where.go +++ b/ent/weapon/where.go @@ -3,10 +3,9 @@ package weapon import ( - "csgowtfd/ent/predicate" - "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" ) // ID filters vertices based on their ID field. diff --git a/ent/weapon_create.go b/ent/weapon_create.go index 2867bcb..967dfc6 100644 --- a/ent/weapon_create.go +++ b/ent/weapon_create.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/weapon" "errors" "fmt" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" ) // WeaponCreate is the builder for creating a Weapon entity. diff --git a/ent/weapon_delete.go b/ent/weapon_delete.go index 6a36375..a9d0c39 100644 --- a/ent/weapon_delete.go +++ b/ent/weapon_delete.go @@ -4,13 +4,13 @@ package ent import ( "context" - "csgowtfd/ent/predicate" - "csgowtfd/ent/weapon" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" ) // WeaponDelete is the builder for deleting a Weapon entity. diff --git a/ent/weapon_query.go b/ent/weapon_query.go index 7718d93..a9e09eb 100644 --- a/ent/weapon_query.go +++ b/ent/weapon_query.go @@ -4,9 +4,6 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/predicate" - "csgowtfd/ent/weapon" "errors" "fmt" "math" @@ -14,6 +11,9 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" ) // WeaponQuery is the builder for querying Weapon entities. diff --git a/ent/weapon_update.go b/ent/weapon_update.go index 1617ba3..2621741 100644 --- a/ent/weapon_update.go +++ b/ent/weapon_update.go @@ -4,15 +4,15 @@ package ent import ( "context" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/predicate" - "csgowtfd/ent/weapon" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/predicate" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" ) // WeaponUpdate is the builder for updating Weapon entities. diff --git a/go.mod b/go.mod index 9999c42..39ee85f 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module csgowtfd +module git.harting.dev/csgowtf/csgowtfd go 1.17 diff --git a/go.sum b/go.sum index f6620b8..7a3fa5f 100644 --- a/go.sum +++ b/go.sum @@ -488,6 +488,7 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= @@ -526,6 +527,7 @@ github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+ github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -619,10 +621,12 @@ github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY52 github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/cobra v1.3.0 h1:R7cSvGu+Vv+qX0gW5R/85dx2kmmJT5z5NM8ifdYjdn0= github.com/spf13/cobra v1.3.0/go.mod h1:BrRVncBjOJa/eUcVVm9CE+oC6as8k+VYr4NY7WCi9V4= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.10.0/go.mod h1:SoyBPwAtKDzypXNDFKN5kzH7ppppbGZtls1UpIy5AsM= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= @@ -1022,6 +1026,7 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= +golang.org/x/tools v0.1.9-0.20211216111533-8d383106f7e7 h1:M1gcVrIb2lSn2FIL19DG0+/b8nNVKJ7W7b4WcAGZAYM= golang.org/x/tools v0.1.9-0.20211216111533-8d383106f7e7/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go index 80edd7d..882232f 100644 --- a/main.go +++ b/main.go @@ -3,19 +3,20 @@ package main import ( "bytes" "context" - "csgowtfd/csgo" - "csgowtfd/ent" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/messages" - "csgowtfd/ent/migrate" - "csgowtfd/ent/player" - "csgowtfd/utils" "encoding/gob" + "encoding/json" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "flag" "fmt" + "git.harting.dev/csgowtf/csgowtfd/csgo" + "git.harting.dev/csgowtf/csgowtfd/ent" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/messages" + "git.harting.dev/csgowtf/csgowtfd/ent/migrate" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/utils" "github.com/go-redis/cache/v8" "github.com/go-redis/redis/v8" "github.com/gorilla/handlers" @@ -25,9 +26,12 @@ import ( log "github.com/sirupsen/logrus" "github.com/wercker/journalhook" "go.uber.org/ratelimit" + "golang.org/x/text/language" "gopkg.in/yaml.v3" + "io" "net" "net/http" + "net/url" "os" "os/signal" "strconv" @@ -653,12 +657,29 @@ func getMatchChat(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() id := mux.Vars(r)["id"] + trans := r.FormValue("translate") if id == "" { w.WriteHeader(http.StatusBadRequest) return } + tag, _, err := language.ParseAcceptLanguage(r.Header.Get("Accept-Language")) + if err != nil { + log.Warningf("[GMC] Unable to parse Accept-Language %s: %v", r.Header.Get("Accept-Language"), err) + w.WriteHeader(http.StatusBadRequest) + return + } + + var translate bool + if trans != "" { + translate, err = strconv.ParseBool(trans) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } + } + matchId, err := strconv.ParseUint(id, 10, 64) if err != nil { log.Infof("[GMC] Error parsing matchID %s: %v", id, err) @@ -681,6 +702,39 @@ func getMatchChat(w http.ResponseWriter, r *http.Request) { resp[steamid] = make([]*utils.ChatResponse, 0) } + if translate { + lang, _ := tag[0].Base() + v := url.Values{} + v.Set("auth_key", conf.Csgowtfd.DeepL.APIKey) + v.Set("text", stat.Message) + v.Set("target_lang", lang.String()) + dlResp, err := http.PostForm("https://"+conf.Csgowtfd.DeepL.BaseURL+"/v2/translate", v) + if err != nil || dlResp.StatusCode != http.StatusOK { + log.Warningf("[GMC] Unable to translate with DeepL: %v (HTTP %d)", err, dlResp.StatusCode) + goto sendNormalResp + } else { + respBytes, err := io.ReadAll(dlResp.Body) + if err != nil { + log.Warningf("[GMC] Unable to translate with DeepL: %v (HTTP %d)", err, dlResp.StatusCode) + goto sendNormalResp + } + dlRespJSON := new(utils.DeepLResponse) + err = json.Unmarshal(respBytes, &dlRespJSON) + if err != nil { + log.Warningf("[GMC] Unable to unmarshal JSON from DeepL: %v", err) + goto sendNormalResp + } + resp[steamid] = append(resp[steamid], &utils.ChatResponse{ + Message: dlRespJSON.Translations[0].Text, + AllChat: stat.AllChat, + Tick: stat.Tick, + TranslatedFrom: dlRespJSON.Translations[0].DetectedSourceLanguage, + TranslatedTo: lang.String(), + }) + } + continue + } + sendNormalResp: resp[steamid] = append(resp[steamid], &utils.ChatResponse{ Message: stat.Message, AllChat: stat.AllChat, @@ -1126,6 +1180,7 @@ func main() { router.HandleFunc(`/match/{id:\d{19}}/chat`, func(writer http.ResponseWriter, request *http.Request) {}).Methods(http.MethodOptions) router.HandleFunc(`/match/{id:\d{19}}/chat`, getMatchChat).Methods(http.MethodGet) + router.HandleFunc(`/match/{id:\d{19}}/chat`, getMatchChat).Queries("translate", "{translate}").Methods(http.MethodGet) router.HandleFunc(`/matches`, func(writer http.ResponseWriter, request *http.Request) {}).Methods(http.MethodOptions) router.HandleFunc(`/matches`, getMatches).Methods(http.MethodGet) diff --git a/utils/utils.go b/utils/utils.go index 5502eeb..295a1a9 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -2,17 +2,17 @@ package utils import ( "context" - "csgowtfd/ent" - "csgowtfd/ent/match" - "csgowtfd/ent/matchplayer" - "csgowtfd/ent/player" - "csgowtfd/ent/roundstats" - "csgowtfd/ent/spray" - "csgowtfd/ent/weapon" "encoding/json" "entgo.io/ent/dialect/sql" "errors" "fmt" + "git.harting.dev/csgowtf/csgowtfd/ent" + "git.harting.dev/csgowtf/csgowtfd/ent/match" + "git.harting.dev/csgowtf/csgowtfd/ent/matchplayer" + "git.harting.dev/csgowtf/csgowtfd/ent/player" + "git.harting.dev/csgowtf/csgowtfd/ent/roundstats" + "git.harting.dev/csgowtf/csgowtfd/ent/spray" + "git.harting.dev/csgowtf/csgowtfd/ent/weapon" "github.com/an0nfunc/go-steamapi" log "github.com/sirupsen/logrus" "go.uber.org/ratelimit" @@ -69,6 +69,10 @@ type Conf struct { Write int Idle int } + DeepL struct { + BaseURL string `yaml:"base_url"` + APIKey string `yaml:"api_key"` + } `yaml:"deepl"` } } @@ -87,6 +91,13 @@ type ShareCodeResponse struct { } `json:"result"` } +type DeepLResponse struct { + Translations []struct { + DetectedSourceLanguage string `json:"detected_source_language"` + Text string `json:"text"` + } `json:"translations"` +} + type MatchStats struct { Win int `json:"win,omitempty"` Tie int `json:"tie,omitempty"` @@ -161,10 +172,13 @@ type MateResponse struct { } type ChatResponse struct { - Player *PlayerResponse `json:"player,omitempty"` - Message string `json:"message"` - AllChat bool `json:"all_chat"` - Tick int `json:"tick"` + Player *PlayerResponse `json:"player,omitempty"` + Message string `json:"message"` + AllChat bool `json:"all_chat"` + Tick int `json:"tick"` + Translated bool `json:"translated,omitempty"` + TranslatedFrom string `json:"translated_from,omitempty"` + TranslatedTo string `json:"translated_to,omitempty"` } type WeaponDmg struct {