add some comments

This commit is contained in:
lyx0 2021-10-28 21:49:54 +02:00
parent f02e88cd32
commit 432edf4e63
5 changed files with 9 additions and 3 deletions

View file

@ -17,8 +17,6 @@ func main() {
conf := config.LoadConfig() conf := config.LoadConfig()
// db.InsertInitialData()
nb = &bot.Bot{ nb = &bot.Bot{
TwitchClient: twitch.NewClient(conf.Username, conf.Oauth), TwitchClient: twitch.NewClient(conf.Username, conf.Oauth),
MongoClient: db.Connect(conf), MongoClient: db.Connect(conf),

View file

@ -9,6 +9,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// AddChannel adds a given channel name to the database.
func AddChannel(target, channelName string, nb *bot.Bot) { func AddChannel(target, channelName string, nb *bot.Bot) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()

View file

@ -11,6 +11,8 @@ import (
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
) )
// Connect connects the the MongoDB database through a supplied cfg
// and returns a *mongo.Client
func Connect(cfg *config.Config) *mongo.Client { func Connect(cfg *config.Config) *mongo.Client {
client, err := mongo.NewClient(options.Client().ApplyURI(cfg.MongoURI)) client, err := mongo.NewClient(options.Client().ApplyURI(cfg.MongoURI))
if err != nil { if err != nil {

View file

@ -9,6 +9,8 @@ import (
"go.mongodb.org/mongo-driver/bson" "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 InitialJoin(nb *bot.Bot) { func InitialJoin(nb *bot.Bot) {
collection := nb.MongoClient.Database("nourybot").Collection("channels") collection := nb.MongoClient.Database("nourybot").Collection("channels")
@ -31,7 +33,7 @@ func InitialJoin(nb *bot.Bot) {
for _, ch := range channels { for _, ch := range channels {
nb.TwitchClient.Join(ch.Name) nb.TwitchClient.Join(ch.Name)
nb.TwitchClient.Say(ch.Name, "xd") // nb.TwitchClient.Say(ch.Name, "xd")
log.Infof("Joined: %s\n", ch.Name) log.Infof("Joined: %s\n", ch.Name)
} }

View file

@ -9,6 +9,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// PartChannel takes in a target channel and querys the database for
// its name. If the channel is found it deletes the channel and returns a
// success message. If the channel couldn't be found it will return an error.
func PartChannel(target, channelName string, nb *bot.Bot) { func PartChannel(target, channelName string, nb *bot.Bot) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()