2021-10-28 15:13:39 +02:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
)
|
|
|
|
|
|
|
|
func AddChannel(channelName string) {
|
|
|
|
// Interact with data
|
|
|
|
|
|
|
|
client := Connect()
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
Get my collection instance
|
|
|
|
*/
|
|
|
|
collection := client.Database("nourybot").Collection("channels")
|
|
|
|
|
|
|
|
/*
|
|
|
|
Insert channel
|
|
|
|
*/
|
|
|
|
// chnl := []interface{}{
|
|
|
|
// bson.D{{Key: "name", Value: "nouryqt"}, {Key: "connect", Value: true}},
|
|
|
|
// bson.D{{Key: "name", Value: "nourybot"}, {Key: "connect", Value: true}},
|
|
|
|
// }
|
|
|
|
|
|
|
|
chnl := []interface{}{
|
|
|
|
bson.D{{Key: "name", Value: channelName}, {Key: "connect", Value: true}},
|
|
|
|
}
|
|
|
|
|
|
|
|
res, insertErr := collection.InsertOne(ctx, chnl)
|
|
|
|
if insertErr != nil {
|
|
|
|
log.Error(insertErr)
|
|
|
|
}
|
|
|
|
log.Info(res)
|
|
|
|
|
|
|
|
}
|