mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
fix repeated config calls
This commit is contained in:
parent
844d1ba98e
commit
a707c1a53f
|
@ -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(),
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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{})
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue