mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
return if parting a channnel was successful
This commit is contained in:
parent
bda8dde069
commit
844d1ba98e
3 changed files with 19 additions and 12 deletions
|
@ -2,13 +2,14 @@ package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/lyx0/nourybot/cmd/bot"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddChannel(channelName string, mongoClient *mongo.Client) {
|
func AddChannel(target, channelName string, nb *bot.Bot) {
|
||||||
// Interact with data
|
// Interact with data
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
@ -17,7 +18,7 @@ func AddChannel(channelName string, mongoClient *mongo.Client) {
|
||||||
/*
|
/*
|
||||||
Get my collection instance
|
Get my collection instance
|
||||||
*/
|
*/
|
||||||
collection := mongoClient.Database("nourybot").Collection("channels")
|
collection := nb.MongoClient.Database("nourybot").Collection("channels")
|
||||||
|
|
||||||
// Channel
|
// Channel
|
||||||
// {{"name": string}, {"connect": bool}}
|
// {{"name": string}, {"connect": bool}}
|
||||||
|
@ -25,8 +26,11 @@ func AddChannel(channelName string, mongoClient *mongo.Client) {
|
||||||
|
|
||||||
res, insertErr := collection.InsertOne(ctx, chnl)
|
res, insertErr := collection.InsertOne(ctx, chnl)
|
||||||
if insertErr != nil {
|
if insertErr != nil {
|
||||||
|
nb.Send(target, fmt.Sprintf("Error trying to join %s", channelName))
|
||||||
log.Error(insertErr)
|
log.Error(insertErr)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
nb.Send(target, fmt.Sprintf("Joined %s", channelName))
|
||||||
log.Info(res)
|
log.Info(res)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,14 @@ package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/lyx0/nourybot/cmd/bot"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func PartChannel(channelName string, mongoClient *mongo.Client) {
|
func PartChannel(target, channelName string, nb *bot.Bot) {
|
||||||
// Interact with data
|
// Interact with data
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
@ -17,15 +18,19 @@ func PartChannel(channelName string, mongoClient *mongo.Client) {
|
||||||
/*
|
/*
|
||||||
Get my collection instance
|
Get my collection instance
|
||||||
*/
|
*/
|
||||||
collection := mongoClient.Database("nourybot").Collection("channels")
|
collection := nb.MongoClient.Database("nourybot").Collection("channels")
|
||||||
|
|
||||||
// Channel
|
// Channel
|
||||||
chnl := Channel{channelName, true}
|
chnl := Channel{channelName, true}
|
||||||
|
|
||||||
res, insertErr := collection.DeleteOne(ctx, chnl)
|
res, insertErr := collection.DeleteOne(ctx, chnl)
|
||||||
if insertErr != nil {
|
if insertErr != nil || res.DeletedCount != 1 {
|
||||||
|
nb.Send(target, fmt.Sprintf("Error trying to part %s", channelName))
|
||||||
log.Error(insertErr)
|
log.Error(insertErr)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
log.Info(res)
|
nb.Send(target, fmt.Sprintf("Parted %s", channelName))
|
||||||
|
|
||||||
|
log.Info(res.DeletedCount)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,8 +146,7 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) {
|
||||||
nb.Send(target, "You are not allowed to do this")
|
nb.Send(target, "You are not allowed to do this")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
db.AddChannel(cmdParams[1], nb.MongoClient)
|
db.AddChannel(target, cmdParams[1], nb)
|
||||||
nb.Send(message.Channel, "Joined")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
case "part":
|
case "part":
|
||||||
|
@ -155,8 +154,7 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) {
|
||||||
nb.Send(target, "You are not allowed to do this")
|
nb.Send(target, "You are not allowed to do this")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
db.PartChannel(cmdParams[1], nb.MongoClient)
|
db.PartChannel(target, cmdParams[1], nb)
|
||||||
nb.Send(message.Channel, "Parted")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
case "firstline":
|
case "firstline":
|
||||||
|
|
Loading…
Reference in a new issue