mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
addchannel works
This commit is contained in:
parent
20f9470ce8
commit
cb0181c01f
5 changed files with 27 additions and 24 deletions
|
@ -11,9 +11,9 @@ type Bot struct {
|
|||
Uptime time.Time
|
||||
}
|
||||
|
||||
type Channel struct {
|
||||
Name string
|
||||
}
|
||||
// type Channel struct {
|
||||
// Name string
|
||||
// }
|
||||
|
||||
// Send checks the message against a banphrase api
|
||||
// and also splits the message into two if the message
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func AddChannel(channelName string) {
|
||||
|
@ -21,17 +20,8 @@ func AddChannel(channelName string) {
|
|||
*/
|
||||
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}},
|
||||
}
|
||||
// Channel
|
||||
chnl := Channel{channelName, true}
|
||||
|
||||
res, insertErr := collection.InsertOne(ctx, chnl)
|
||||
if insertErr != nil {
|
||||
|
|
|
@ -2,7 +2,6 @@ package db
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/lyx0/nourybot/pkg/config"
|
||||
|
@ -12,6 +11,11 @@ import (
|
|||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
Name string `bson:"name,omitempty"`
|
||||
Connect bool `bson:"connect,omitempty"`
|
||||
}
|
||||
|
||||
func Connect() *mongo.Client {
|
||||
conf := config.LoadConfig()
|
||||
|
||||
|
@ -29,20 +33,23 @@ func Connect() *mongo.Client {
|
|||
}
|
||||
// defer client.Disconnect(ctx)
|
||||
|
||||
err = client.Ping(context.TODO(), nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Info("Connected to MongoDB!")
|
||||
|
||||
databases, err := client.ListDatabaseNames(ctx, bson.M{})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(databases)
|
||||
_ = databases
|
||||
// log.Info(databases)
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
type channel struct {
|
||||
Name string `bson:"name,omitempty"`
|
||||
Connect bool `bson:"connect,omitempty"`
|
||||
}
|
||||
|
||||
/*
|
||||
List databases
|
||||
*/
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
|
@ -24,15 +25,15 @@ func InitialJoin(nb *bot.Bot) {
|
|||
}
|
||||
defer cur.Close(ctx)
|
||||
|
||||
var channels []channel
|
||||
var channels []Channel
|
||||
if err := cur.All(ctx, &channels); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, ch := range channels {
|
||||
nb.TwitchClient.Join(ch.Name)
|
||||
log.Infof("Joined: %s\n", ch.Name)
|
||||
nb.TwitchClient.Say(ch.Name, "xd")
|
||||
// fmt.Printf("%v\n", ch.Name)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/gempir/go-twitch-irc/v2"
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/commands"
|
||||
"github.com/lyx0/nourybot/pkg/db"
|
||||
"github.com/lyx0/nourybot/pkg/utils"
|
||||
)
|
||||
|
||||
|
@ -140,6 +141,10 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) {
|
|||
return
|
||||
}
|
||||
|
||||
case "join":
|
||||
db.AddChannel(cmdParams[1])
|
||||
nb.Send(message.Channel, "Joined")
|
||||
|
||||
case "firstline":
|
||||
if msgLen == 1 {
|
||||
nb.Send(target, "Usage: ()firstline [channel] [user]")
|
||||
|
|
Loading…
Reference in a new issue