connect works

This commit is contained in:
lyx0 2021-10-27 19:27:35 +02:00
parent 5f178e925e
commit 95e8fe0ade
2 changed files with 14 additions and 4 deletions

View file

@ -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(),

View file

@ -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)
}
}
/*