Skip to content

Commit

Permalink
feat: config file
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Dec 19, 2023
1 parent 7400db1 commit a3b6667
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 24 deletions.
29 changes: 26 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
3 changes: 3 additions & 0 deletions kreacher/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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{})
62 changes: 41 additions & 21 deletions kreacher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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,
}
}

0 comments on commit a3b6667

Please sign in to comment.