2021-11-01 19:34:32 +01:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/lyx0/nourybot/cmd/bot"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
)
|
|
|
|
|
2021-11-01 19:41:15 +01:00
|
|
|
// Listchannel reads the list of channel from the database and
|
|
|
|
// whispers them to my own account.
|
2021-11-01 19:34:32 +01:00
|
|
|
func ListChannel(nb *bot.Bot) {
|
|
|
|
collection := nb.MongoClient.Database("nourybot").Collection("channels")
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
cur, currErr := collection.Find(ctx, bson.D{})
|
|
|
|
|
|
|
|
if currErr != nil {
|
|
|
|
panic(currErr)
|
|
|
|
}
|
|
|
|
defer cur.Close(ctx)
|
|
|
|
|
|
|
|
var channels []Channel
|
|
|
|
if err := cur.All(ctx, &channels); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
channelList := ""
|
|
|
|
for _, ch := range channels {
|
|
|
|
channelList += ch.Name + " "
|
|
|
|
}
|
2021-11-01 19:35:30 +01:00
|
|
|
|
2021-11-01 19:34:32 +01:00
|
|
|
nb.TwitchClient.Whisper("nouryqt", channelList)
|
|
|
|
}
|