From 4374119f4c5426e52160bfc43759eca18d868637 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Fri, 12 Aug 2022 16:59:58 +0200 Subject: [PATCH] fix comments --- cmd/bot/channel.go | 14 +++++++------- cmd/bot/command.go | 12 ++++++------ cmd/bot/commands.go | 2 -- cmd/bot/user.go | 12 ++++++------ 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/cmd/bot/channel.go b/cmd/bot/channel.go index c9052d2..5ab17c9 100644 --- a/cmd/bot/channel.go +++ b/cmd/bot/channel.go @@ -9,9 +9,9 @@ import ( "github.com/lyx0/nourybot/pkg/common" ) -// AddChannel takes in a channel name, then queries `GetIdByLogin` for the +// AddChannel takes in a channel name, then calls 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. +// If there is no error thrown the TwitchClient joins the channel afterwards. func (app *Application) AddChannel(login string, message twitch.PrivateMessage) { userId, err := decapi.GetIdByLogin(login) if err != nil { @@ -20,7 +20,7 @@ func (app *Application) AddChannel(login string, message twitch.PrivateMessage) } // Initialize a new channel struct holding the values that will be - // passed into the `app.Models.Channels.Insert()` method. + // passed into the app.Models.Channels.Insert() method. channel := &data.Channel{ Login: login, TwitchID: userId, @@ -67,17 +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. +// InitialJoin is called on startup and queries the database for a list of +// channels which the TwitchClient then joins. func (app *Application) InitialJoin() { - // GetJoinable returns a `[]string` containing the channel names. + // GetJoinable returns a slice of channel names. channel, err := app.Models.Channels.GetJoinable() if err != nil { app.Logger.Error(err) return } - // Iterate over the `[]string` and join each. + // Iterate over the slice of channels and join each. for _, v := range channel { app.TwitchClient.Join(v) app.Logger.Infow("Joining channel:", diff --git a/cmd/bot/command.go b/cmd/bot/command.go index c702497..c8758bf 100644 --- a/cmd/bot/command.go +++ b/cmd/bot/command.go @@ -33,7 +33,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { msgLen := len(strings.SplitN(message.Message, " ", -2)) // target is the channelname the message originated from and - // where we are responding. + // where the TwitchClient should send the response target := message.Channel // Userlevel is the level set for a user in the database. @@ -45,7 +45,6 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { // If the level returned is 0 then the user was not found in the database. userLevel := app.GetUserLevel(message.User.Name) - // Left in for debugging purposes. app.Logger.Infow("Command received", // "message", message, // Pretty taxing "message.Message", message.Message, @@ -60,8 +59,8 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { // Hardcoded commands have a priority over database commands. // Switch over the commandName and see if there is a hardcoded case for it. // If there was no switch case satisfied, query the database if there is - // a `data.CommandModel.Name` equal to the `commandName` - // If there is return the `data.CommandModel.Text` entry. + // a data.CommandModel.Name equal to the `commandName` + // If there is return the data.CommandModel.Text entry. // Otherwise we ignore the message. switch commandName { case "": @@ -149,6 +148,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { return } + // ()pinG case "ping": commands.Ping(target, app.TwitchClient) return @@ -232,6 +232,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { return } + // ()echo case "echo": if userLevel < 250 { // Limit to myself for now. return @@ -244,7 +245,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { } //################### - // 1000- Admin only + // 1000 - Admin only //################### // ##### @@ -367,7 +368,6 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) { } // ################## - // Database Command // Check if the commandName exists as the "name" of a command in the database. // if it doesnt then ignore it. // ################## diff --git a/cmd/bot/commands.go b/cmd/bot/commands.go index 3d97337..18b8133 100644 --- a/cmd/bot/commands.go +++ b/cmd/bot/commands.go @@ -33,7 +33,6 @@ func (app *Application) AddCommand(name string, message twitch.PrivateMessage) { common.Send(message.Channel, reply, app.TwitchClient) return } else { - reply := fmt.Sprintf("Successfully added command: %s", name) common.Send(message.Channel, reply, app.TwitchClient) return @@ -73,7 +72,6 @@ func (app *Application) GetCommand(name, username string) (string, error) { // Userlevel was not enough so return an empty string and error. return "", ErrUserInsufficientLevel - } // EditCommandLevel takes in a name and level string and updates the entry with name diff --git a/cmd/bot/user.go b/cmd/bot/user.go index 4cc58ba..522eb99 100644 --- a/cmd/bot/user.go +++ b/cmd/bot/user.go @@ -10,8 +10,8 @@ import ( "github.com/lyx0/nourybot/pkg/common" ) -// AddUser takes in a login and level string. It calls GetIdByLogin to get the twitch id -// of the login name and then adds the login name, twitch id and supplied level to the database. +// AddUser calls GetIdByLogin to get the twitch id of the login name and then adds +// the login name, twitch id and supplied level to the database. func (app *Application) AddUser(login, lvl string, message twitch.PrivateMessage) { userId, err := decapi.GetIdByLogin(login) if err != nil { @@ -65,8 +65,8 @@ func (app *Application) DebugUser(login string, message twitch.PrivateMessage) { } } -// DeleteUser takes in a login string, queries the database for such a name and if an -// entry for the name exists deletes the entry. +// DeleteUser takes in a login string, queries the database for an entry with +// that login name and tries to delete that entry in the database. func (app *Application) DeleteUser(login string, message twitch.PrivateMessage) { err := app.Models.Users.Delete(login) if err != nil { @@ -79,8 +79,8 @@ func (app *Application) DeleteUser(login string, message twitch.PrivateMessage) common.Send(message.Channel, reply, app.TwitchClient) } -// EditUserLevel takes in a login name and level string, then updates the database record -// for the login name with the new level if such an entry exists. +// EditUserLevel tries to update the database record for the supplied +// login name with the new level. func (app *Application) EditUserLevel(login, lvl string, message twitch.PrivateMessage) { // Convert the level string to an integer. This is an easy check to see if // the level supplied was a number only.