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/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/cmd/bot" "github.com/lyx0/nourybot/cmd/bot"
"github.com/lyx0/nourybot/pkg/config" "github.com/lyx0/nourybot/pkg/config"
"github.com/lyx0/nourybot/pkg/db"
"github.com/lyx0/nourybot/pkg/handlers" "github.com/lyx0/nourybot/pkg/handlers"
) )
@ -16,6 +17,9 @@ func main() {
conf := config.LoadConfig() conf := config.LoadConfig()
// db.InsertInitialData()
db.ListChannels()
nb = &bot.Bot{ nb = &bot.Bot{
TwitchClient: twitch.NewClient(conf.Username, conf.Oauth), TwitchClient: twitch.NewClient(conf.Username, conf.Oauth),
Uptime: time.Now(), Uptime: time.Now(),

View file

@ -24,7 +24,7 @@ func Connect() *mongo.Client {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer client.Disconnect(ctx) // defer client.Disconnect(ctx)
databases, err := client.ListDatabaseNames(ctx, bson.M{}) databases, err := client.ListDatabaseNames(ctx, bson.M{})
if err != nil { if err != nil {
@ -55,8 +55,8 @@ func InsertInitialData() {
Insert channel Insert channel
*/ */
chnl := []interface{}{ chnl := []interface{}{
bson.D{{"name", "nouryqt"}, {"connect", true}}, bson.D{{Key: "name", Value: "nouryqt"}, {Key: "connect", Value: true}},
bson.D{{"name", "nourybot"}, {"connect", true}}, bson.D{{Key: "name", Value: "nourybot"}, {Key: "connect", Value: true}},
} }
res, insertErr := collection.InsertMany(ctx, chnl) res, insertErr := collection.InsertMany(ctx, chnl)
@ -72,7 +72,9 @@ func ListChannels() {
collection := client.Database("nourybot").Collection("channels") collection := client.Database("nourybot").Collection("channels")
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) 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 { if currErr != nil {
panic(currErr) panic(currErr)
@ -84,6 +86,10 @@ func ListChannels() {
panic(err) panic(err)
} }
for _, ch := range channels {
fmt.Printf("%v", ch.Name)
}
} }
/* /*