add comments

This commit is contained in:
lyx0 2022-08-11 23:34:05 +02:00
parent b832ec63b6
commit fbe3f6dc1e
2 changed files with 23 additions and 10 deletions

View file

@ -9,6 +9,9 @@ import (
"github.com/lyx0/nourybot/pkg/common"
)
// AddChannel takes in a channel name, then queries `GetIdByLogin` for the
// channels ID and inserts both the name and id value into the database.
// If there was no error thrown the `app.TwitchClient` joins the channel afterwards.
func (app *Application) AddChannel(login string, message twitch.PrivateMessage) {
userId, err := decapi.GetIdByLogin(login)
if err != nil {
@ -16,6 +19,8 @@ func (app *Application) AddChannel(login string, message twitch.PrivateMessage)
return
}
// Initialize a new channel struct holding the values that will be
// passed into the `app.Models.Channels.Insert()` method.
channel := &data.Channel{
Login: login,
TwitchID: userId,
@ -34,6 +39,8 @@ func (app *Application) AddChannel(login string, message twitch.PrivateMessage)
}
}
// GetAllChannels() queries the database and lists all channels.
// Only used for debug/information purposes.
func (app *Application) GetAllChannels() {
channel, err := app.Models.Channels.GetAll()
if err != nil {
@ -44,6 +51,8 @@ func (app *Application) GetAllChannels() {
"channel", channel)
}
// DeleteChannel queries the database for a channel name and if it exists
// deletes the channel and makes the bot depart said channel.
func (app *Application) DeleteChannel(login string, message twitch.PrivateMessage) {
err := app.Models.Channels.Delete(login)
if err != nil {
@ -58,13 +67,17 @@ func (app *Application) DeleteChannel(login string, message twitch.PrivateMessag
common.Send(message.Channel, reply, app.TwitchClient)
}
// InitialJoin is called on startup and gets all the channels from the database
// so that the `app.TwitchClient` then joins each.
func (app *Application) InitialJoin() {
// GetJoinable returns a `[]string` containing the channel names.
channel, err := app.Models.Channels.GetJoinable()
if err != nil {
app.Logger.Error(err)
return
}
// Iterate over the `[]string` and join each.
for _, v := range channel {
app.TwitchClient.Join(v)
app.Logger.Infow("Joining channel:",