fix repeated config calls

This commit is contained in:
lyx0 2021-10-28 17:48:18 +02:00
parent 844d1ba98e
commit a707c1a53f
4 changed files with 6 additions and 8 deletions

View file

@ -21,7 +21,7 @@ func main() {
nb = &bot.Bot{
TwitchClient: twitch.NewClient(conf.Username, conf.Oauth),
MongoClient: db.Connect(),
MongoClient: db.Connect(conf),
Uptime: time.Now(),
}

View file

@ -16,10 +16,9 @@ type Channel struct {
Connect bool `bson:"connect,omitempty"`
}
func Connect() *mongo.Client {
conf := config.LoadConfig()
func Connect(cfg *config.Config) *mongo.Client {
client, err := mongo.NewClient(options.Client().ApplyURI(conf.MongoURI))
client, err := mongo.NewClient(options.Client().ApplyURI(cfg.MongoURI))
if err != nil {
log.Fatal(err)
}

View file

@ -10,13 +10,12 @@ import (
)
func InitialJoin(nb *bot.Bot) {
client := Connect()
collection := client.Database("nourybot").Collection("channels")
collection := nb.MongoClient.Database("nourybot").Collection("channels")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
defer client.Disconnect(ctx)
defer nb.MongoClient.Disconnect(ctx)
cur, currErr := collection.Find(ctx, bson.D{})

View file

@ -31,6 +31,6 @@ func PartChannel(target, channelName string, nb *bot.Bot) {
}
nb.Send(target, fmt.Sprintf("Parted %s", channelName))
log.Info(res.DeletedCount)
// log.Info(res)
}