2021-10-28 15:13:39 +02:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/lyx0/nourybot/cmd/bot"
|
2021-10-28 16:16:11 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2021-10-28 15:13:39 +02:00
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitialJoin(nb *bot.Bot) {
|
|
|
|
client := Connect()
|
|
|
|
|
|
|
|
collection := client.Database("nourybot").Collection("channels")
|
2021-10-28 15:22:19 +02:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2021-10-28 15:13:39 +02:00
|
|
|
defer client.Disconnect(ctx)
|
|
|
|
|
|
|
|
cur, currErr := collection.Find(ctx, bson.D{})
|
|
|
|
|
|
|
|
if currErr != nil {
|
|
|
|
panic(currErr)
|
|
|
|
}
|
|
|
|
defer cur.Close(ctx)
|
|
|
|
|
2021-10-28 16:16:11 +02:00
|
|
|
var channels []Channel
|
2021-10-28 15:13:39 +02:00
|
|
|
if err := cur.All(ctx, &channels); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ch := range channels {
|
|
|
|
nb.TwitchClient.Join(ch.Name)
|
|
|
|
nb.TwitchClient.Say(ch.Name, "xd")
|
2021-10-28 17:20:24 +02:00
|
|
|
log.Infof("Joined: %s\n", ch.Name)
|
2021-10-28 15:13:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|