From a3b6667022e77f7265dd24058a34842aed8a7632 Mon Sep 17 00:00:00 2001 From: Santiago Ramirez Date: Tue, 19 Dec 2023 14:26:18 +0000 Subject: [PATCH] feat: config file --- go.mod | 29 ++++++++++++++++++--- kreacher/clients.go | 3 +++ kreacher/config.go | 62 ++++++++++++++++++++++++++++++--------------- 3 files changed, 70 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 7d82829..9862fe7 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,32 @@ module github.com/SantiiRepair/kreacher-bot go 1.21.5 require ( + github.com/gotd/td v0.91.0 + github.com/joho/godotenv v1.5.1 + github.com/redis/go-redis/v9 v9.3.1 + gopkg.in/telebot.v3 v3.2.1 +) + +require ( + github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/joho/godotenv v1.5.1 // indirect - github.com/redis/go-redis/v9 v9.3.1 // indirect - gopkg.in/telebot.v3 v3.2.1 // indirect + github.com/go-faster/errors v0.7.0 // indirect + github.com/go-faster/jx v1.1.0 // indirect + github.com/go-faster/xor v1.0.0 // indirect + github.com/gotd/ige v0.2.2 // indirect + github.com/gotd/neo v0.1.5 // indirect + github.com/klauspost/compress v1.17.4 // indirect + github.com/segmentio/asm v1.2.0 // indirect + go.opentelemetry.io/otel v1.21.0 // indirect + go.opentelemetry.io/otel/trace v1.21.0 // indirect + go.uber.org/atomic v1.11.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.26.0 // indirect + golang.org/x/crypto v0.16.0 // indirect + golang.org/x/net v0.19.0 // indirect + golang.org/x/sync v0.5.0 // indirect + golang.org/x/sys v0.15.0 // indirect + nhooyr.io/websocket v1.8.10 // indirect + rsc.io/qr v0.2.0 // indirect ) diff --git a/kreacher/clients.go b/kreacher/clients.go index 5a8366b..ba4b3c4 100755 --- a/kreacher/clients.go +++ b/kreacher/clients.go @@ -3,6 +3,7 @@ package kreacher import ( "time" + td "github.com/gotd/td/telegram" "github.com/redis/go-redis/v9" tele "gopkg.in/telebot.v3" ) @@ -18,3 +19,5 @@ var kbot, _ = tele.NewBot(tele.Settings{ Token: NewConfig().BotToken, Poller: &tele.LongPoller{Timeout: 10 * time.Second}, }) + +var ubot = td.NewClient(NewConfig().APIID, NewConfig().APIHash, td.Options{}) diff --git a/kreacher/config.go b/kreacher/config.go index c801442..8c9f5a6 100755 --- a/kreacher/config.go +++ b/kreacher/config.go @@ -3,12 +3,13 @@ package kreacher import ( "fmt" "os" + "strconv" "github.com/joho/godotenv" ) type Config struct { - APIID string + APIID int APIHash string BotToken string BotUsername string @@ -22,10 +23,10 @@ type Config struct { PostgresUser string PostgresPassword string PostgresHost string - PostgresPort string + PostgresPort int RedisHost string RedisPassword string - RedisPort string + RedisPort int } func NewConfig() *Config { @@ -34,24 +35,43 @@ func NewConfig() *Config { fmt.Println("No .env file found") } + apiID, _ := strconv.Atoi(os.Getenv("API_ID")) + apiHash := os.Getenv("API_HASH") + botToken := os.Getenv("BOT_TOKEN") + botUsername := os.Getenv("BOT_USERNAME") + channel := os.Getenv("CHANNEL") + esMoviesChannel := os.Getenv("ES_MOVIES_CHANNEL") + esSeriesChannel := os.Getenv("ES_SERIES_CHANNEL") + managementMode := os.Getenv("MANAGEMENT_MODE") + maintainer := os.Getenv("MAINTAINER") + sessionString := os.Getenv("SESSION_STRING") + postgresDB := os.Getenv("POSTGRES_DB") + postgresUser := os.Getenv("POSTGRES_USER") + postgressPassword := os.Getenv("POSTGRES_PASSWORD") + postgresHost := os.Getenv("POSTGRES_HOST") + postgresPort, _ := strconv.Atoi(os.Getenv("POSTGRES_PORT")) + redisHost := os.Getenv("REDIS_HOST") + redisPassword := os.Getenv("REDIS_PASSWORD") + redisPort, _ := strconv.Atoi(os.Getenv("REDIS_PORT")) + return &Config{ - APIID: os.Getenv("API_ID"), - APIHash: os.Getenv("API_HASH"), - BotToken: os.Getenv("BOT_TOKEN"), - BotUsername: os.Getenv("BOT_USERNAME"), - Channel: os.Getenv("CHANNEL"), - ESMoviesChannel: os.Getenv("ES_MOVIES_CHANNEL"), - ESSeriesChannel: os.Getenv("ES_SERIES_CHANNEL"), - ManagementMode: os.Getenv("MANAGEMENT_MODE"), - Maintainer: os.Getenv("MANTAINER"), - SessionString: os.Getenv("SESSION_STRING"), - PostgresDB: os.Getenv("POSTGRES_DB"), - PostgresUser: os.Getenv("POSTGRES_USER"), - PostgresPassword: os.Getenv("POSTGRES_PASSWORD"), - PostgresHost: os.Getenv("POSTGRES_HOST"), - PostgresPort: os.Getenv("POSTGRES_PORT"), - RedisHost: os.Getenv("REDIS_HOST"), - RedisPassword: os.Getenv("REDIS_PASSWORD"), - RedisPort: os.Getenv("REDIS_PORT"), + APIID: apiID, + APIHash: apiHash, + BotToken: botToken, + BotUsername: botUsername, + Channel: channel, + ESMoviesChannel: esMoviesChannel, + ESSeriesChannel: esSeriesChannel, + ManagementMode: managementMode, + Maintainer: maintainer, + SessionString: sessionString, + PostgresDB: postgresDB, + PostgresUser: postgresUser, + PostgresPassword: postgressPassword, + PostgresHost: postgresHost, + PostgresPort: postgresPort, + RedisHost: redisHost, + RedisPassword: redisPassword, + RedisPort: redisPort, } }