diff --git a/cmd/main.go b/cmd/main.go index 6cb8981..4fe4359 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -7,6 +7,7 @@ import ( "github.com/gempir/go-twitch-irc/v2" "github.com/lyx0/nourybot/cmd/bot" "github.com/lyx0/nourybot/pkg/config" + "github.com/lyx0/nourybot/pkg/db" "github.com/lyx0/nourybot/pkg/handlers" ) @@ -16,6 +17,9 @@ func main() { conf := config.LoadConfig() + // db.InsertInitialData() + db.ListChannels() + nb = &bot.Bot{ TwitchClient: twitch.NewClient(conf.Username, conf.Oauth), Uptime: time.Now(), diff --git a/pkg/db/connect.go b/pkg/db/connect.go index 278ea8c..f55e953 100644 --- a/pkg/db/connect.go +++ b/pkg/db/connect.go @@ -24,7 +24,7 @@ func Connect() *mongo.Client { if err != nil { log.Fatal(err) } - defer client.Disconnect(ctx) + // defer client.Disconnect(ctx) databases, err := client.ListDatabaseNames(ctx, bson.M{}) if err != nil { @@ -55,8 +55,8 @@ func InsertInitialData() { Insert channel */ chnl := []interface{}{ - bson.D{{"name", "nouryqt"}, {"connect", true}}, - bson.D{{"name", "nourybot"}, {"connect", true}}, + bson.D{{Key: "name", Value: "nouryqt"}, {Key: "connect", Value: true}}, + bson.D{{Key: "name", Value: "nourybot"}, {Key: "connect", Value: true}}, } res, insertErr := collection.InsertMany(ctx, chnl) @@ -72,7 +72,9 @@ func ListChannels() { collection := client.Database("nourybot").Collection("channels") ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) - cur, currErr := collection.Find(ctx, bson.D{}) + defer client.Disconnect(ctx) + + cur, currErr := collection.Find(ctx, bson.D{{Key: "connect", Value: true}}) if currErr != nil { panic(currErr) @@ -84,6 +86,10 @@ func ListChannels() { panic(err) } + for _, ch := range channels { + fmt.Printf("%v", ch.Name) + } + } /*