From 4171d11dae585a1aa62b26840ad67e4acc4cf230 Mon Sep 17 00:00:00 2001 From: lyx0 Date: Thu, 28 Oct 2021 16:20:27 +0200 Subject: [PATCH] part works --- pkg/db/partchannel.go | 32 ++++++++++++++++++++++++++++++++ pkg/handlers/command.go | 5 +++++ 2 files changed, 37 insertions(+) create mode 100644 pkg/db/partchannel.go diff --git a/pkg/db/partchannel.go b/pkg/db/partchannel.go new file mode 100644 index 0000000..f177182 --- /dev/null +++ b/pkg/db/partchannel.go @@ -0,0 +1,32 @@ +package db + +import ( + "context" + "time" + + log "github.com/sirupsen/logrus" +) + +func PartChannel(channelName string) { + // Interact with data + + client := Connect() + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + /* + Get my collection instance + */ + collection := client.Database("nourybot").Collection("channels") + + // Channel + chnl := Channel{channelName, true} + + res, insertErr := collection.DeleteOne(ctx, chnl) + if insertErr != nil { + log.Error(insertErr) + } + log.Info(res) + +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index b2cf77f..ae199ba 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -144,6 +144,11 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) { case "join": db.AddChannel(cmdParams[1]) nb.Send(message.Channel, "Joined") + return + + case "part": + db.PartChannel(cmdParams[1]) + nb.Send(message.Channel, "Parted") case "firstline": if msgLen == 1 {