mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add channel list command
This commit is contained in:
parent
51c09c2bf8
commit
7531a67b18
3 changed files with 62 additions and 0 deletions
11
pkg/commands/channellist.go
Normal file
11
pkg/commands/channellist.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/db"
|
||||
)
|
||||
|
||||
func ChannelList(target string, nb *bot.Bot) {
|
||||
db.ListChannel(nb)
|
||||
nb.Send(target, "Whispered you the list of channel.")
|
||||
}
|
43
pkg/db/listchannel.go
Normal file
43
pkg/db/listchannel.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
// InitialJoin is called everytime the Bot starts and joins the
|
||||
// initial list of twitch channels it should be in.
|
||||
func ListChannel(nb *bot.Bot) {
|
||||
collection := nb.MongoClient.Database("nourybot").Collection("channels")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// defer nb.MongoClient.Disconnect(ctx)
|
||||
|
||||
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 {
|
||||
nb.TwitchClient.Join(ch.Name)
|
||||
// nb.TwitchClient.Say(ch.Name, "xd")
|
||||
channelList += ch.Name + " "
|
||||
}
|
||||
nb.TwitchClient.Whisper("nouryqt", channelList)
|
||||
// It worked
|
||||
// nb.Send("nourybot", fmt.Sprintf("Badabing Badaboom Pepepains Joined %v channel", channelCount))
|
||||
// nb.Send("nouryqt", fmt.Sprintf("Badabing Badaboom Pepepains Joined %v channel", channelCount))
|
||||
}
|
|
@ -75,6 +75,14 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) {
|
|||
commands.Bttv(target, cmdParams[1], nb)
|
||||
return
|
||||
|
||||
case "channellist":
|
||||
if message.User.ID != "31437432" {
|
||||
nb.Send(target, "You are not allowed to do this")
|
||||
return
|
||||
}
|
||||
commands.ChannelList(target, nb)
|
||||
return
|
||||
|
||||
// case "bttvemotes":
|
||||
// commands.BttvEmotes(target, nb)
|
||||
// return
|
||||
|
|
Loading…
Reference in a new issue