2021-10-28 16:20:27 +02:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-10-28 17:44:19 +02:00
|
|
|
"fmt"
|
2021-10-28 16:20:27 +02:00
|
|
|
"time"
|
|
|
|
|
2021-10-28 17:44:19 +02:00
|
|
|
"github.com/lyx0/nourybot/cmd/bot"
|
2021-10-28 16:20:27 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2021-10-28 17:44:19 +02:00
|
|
|
func PartChannel(target, channelName string, nb *bot.Bot) {
|
2021-10-28 16:20:27 +02:00
|
|
|
// Interact with data
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get my collection instance
|
|
|
|
*/
|
2021-10-28 17:44:19 +02:00
|
|
|
collection := nb.MongoClient.Database("nourybot").Collection("channels")
|
2021-10-28 16:20:27 +02:00
|
|
|
|
|
|
|
// Channel
|
|
|
|
chnl := Channel{channelName, true}
|
|
|
|
|
|
|
|
res, insertErr := collection.DeleteOne(ctx, chnl)
|
2021-10-28 17:44:19 +02:00
|
|
|
if insertErr != nil || res.DeletedCount != 1 {
|
|
|
|
nb.Send(target, fmt.Sprintf("Error trying to part %s", channelName))
|
2021-10-28 16:20:27 +02:00
|
|
|
log.Error(insertErr)
|
2021-10-28 17:44:19 +02:00
|
|
|
return
|
2021-10-28 16:20:27 +02:00
|
|
|
}
|
2021-10-28 17:44:19 +02:00
|
|
|
nb.Send(target, fmt.Sprintf("Parted %s", channelName))
|
|
|
|
|
|
|
|
log.Info(res.DeletedCount)
|
2021-10-28 16:20:27 +02:00
|
|
|
|
|
|
|
}
|