mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
fix comments
This commit is contained in:
parent
74b4ac2962
commit
4374119f4c
4 changed files with 19 additions and 21 deletions
|
@ -9,9 +9,9 @@ import (
|
||||||
"github.com/lyx0/nourybot/pkg/common"
|
"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.
|
// 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) {
|
func (app *Application) AddChannel(login string, message twitch.PrivateMessage) {
|
||||||
userId, err := decapi.GetIdByLogin(login)
|
userId, err := decapi.GetIdByLogin(login)
|
||||||
if err != nil {
|
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
|
// 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{
|
channel := &data.Channel{
|
||||||
Login: login,
|
Login: login,
|
||||||
TwitchID: userId,
|
TwitchID: userId,
|
||||||
|
@ -67,17 +67,17 @@ func (app *Application) DeleteChannel(login string, message twitch.PrivateMessag
|
||||||
common.Send(message.Channel, reply, app.TwitchClient)
|
common.Send(message.Channel, reply, app.TwitchClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitialJoin is called on startup and gets all the channels from the database
|
// InitialJoin is called on startup and queries the database for a list of
|
||||||
// so that the `app.TwitchClient` then joins each.
|
// channels which the TwitchClient then joins.
|
||||||
func (app *Application) InitialJoin() {
|
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()
|
channel, err := app.Models.Channels.GetJoinable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Logger.Error(err)
|
app.Logger.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over the `[]string` and join each.
|
// Iterate over the slice of channels and join each.
|
||||||
for _, v := range channel {
|
for _, v := range channel {
|
||||||
app.TwitchClient.Join(v)
|
app.TwitchClient.Join(v)
|
||||||
app.Logger.Infow("Joining channel:",
|
app.Logger.Infow("Joining channel:",
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
msgLen := len(strings.SplitN(message.Message, " ", -2))
|
msgLen := len(strings.SplitN(message.Message, " ", -2))
|
||||||
|
|
||||||
// target is the channelname the message originated from and
|
// target is the channelname the message originated from and
|
||||||
// where we are responding.
|
// where the TwitchClient should send the response
|
||||||
target := message.Channel
|
target := message.Channel
|
||||||
|
|
||||||
// Userlevel is the level set for a user in the database.
|
// 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.
|
// If the level returned is 0 then the user was not found in the database.
|
||||||
userLevel := app.GetUserLevel(message.User.Name)
|
userLevel := app.GetUserLevel(message.User.Name)
|
||||||
|
|
||||||
// Left in for debugging purposes.
|
|
||||||
app.Logger.Infow("Command received",
|
app.Logger.Infow("Command received",
|
||||||
// "message", message, // Pretty taxing
|
// "message", message, // Pretty taxing
|
||||||
"message.Message", message.Message,
|
"message.Message", message.Message,
|
||||||
|
@ -60,8 +59,8 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
// Hardcoded commands have a priority over database commands.
|
// Hardcoded commands have a priority over database commands.
|
||||||
// Switch over the commandName and see if there is a hardcoded case for it.
|
// 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
|
// If there was no switch case satisfied, query the database if there is
|
||||||
// a `data.CommandModel.Name` equal to the `commandName`
|
// a data.CommandModel.Name equal to the `commandName`
|
||||||
// If there is return the `data.CommandModel.Text` entry.
|
// If there is return the data.CommandModel.Text entry.
|
||||||
// Otherwise we ignore the message.
|
// Otherwise we ignore the message.
|
||||||
switch commandName {
|
switch commandName {
|
||||||
case "":
|
case "":
|
||||||
|
@ -149,6 +148,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ()pinG
|
||||||
case "ping":
|
case "ping":
|
||||||
commands.Ping(target, app.TwitchClient)
|
commands.Ping(target, app.TwitchClient)
|
||||||
return
|
return
|
||||||
|
@ -232,6 +232,7 @@ func (app *Application) handleCommand(message twitch.PrivateMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ()echo <message>
|
||||||
case "echo":
|
case "echo":
|
||||||
if userLevel < 250 { // Limit to myself for now.
|
if userLevel < 250 { // Limit to myself for now.
|
||||||
return
|
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.
|
// Check if the commandName exists as the "name" of a command in the database.
|
||||||
// if it doesnt then ignore it.
|
// if it doesnt then ignore it.
|
||||||
// ##################
|
// ##################
|
||||||
|
|
|
@ -33,7 +33,6 @@ func (app *Application) AddCommand(name string, message twitch.PrivateMessage) {
|
||||||
common.Send(message.Channel, reply, app.TwitchClient)
|
common.Send(message.Channel, reply, app.TwitchClient)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
reply := fmt.Sprintf("Successfully added command: %s", name)
|
reply := fmt.Sprintf("Successfully added command: %s", name)
|
||||||
common.Send(message.Channel, reply, app.TwitchClient)
|
common.Send(message.Channel, reply, app.TwitchClient)
|
||||||
return
|
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.
|
// Userlevel was not enough so return an empty string and error.
|
||||||
return "", ErrUserInsufficientLevel
|
return "", ErrUserInsufficientLevel
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditCommandLevel takes in a name and level string and updates the entry with name
|
// EditCommandLevel takes in a name and level string and updates the entry with name
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/lyx0/nourybot/pkg/common"
|
"github.com/lyx0/nourybot/pkg/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddUser takes in a login and level string. It calls GetIdByLogin to get the twitch id
|
// AddUser calls GetIdByLogin to get the twitch id of the login name and then adds
|
||||||
// of the login name and then adds the login name, twitch id and supplied level to the database.
|
// the login name, twitch id and supplied level to the database.
|
||||||
func (app *Application) AddUser(login, lvl string, message twitch.PrivateMessage) {
|
func (app *Application) AddUser(login, lvl string, message twitch.PrivateMessage) {
|
||||||
userId, err := decapi.GetIdByLogin(login)
|
userId, err := decapi.GetIdByLogin(login)
|
||||||
if err != nil {
|
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
|
// DeleteUser takes in a login string, queries the database for an entry with
|
||||||
// entry for the name exists deletes the entry.
|
// that login name and tries to delete that entry in the database.
|
||||||
func (app *Application) DeleteUser(login string, message twitch.PrivateMessage) {
|
func (app *Application) DeleteUser(login string, message twitch.PrivateMessage) {
|
||||||
err := app.Models.Users.Delete(login)
|
err := app.Models.Users.Delete(login)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -79,8 +79,8 @@ func (app *Application) DeleteUser(login string, message twitch.PrivateMessage)
|
||||||
common.Send(message.Channel, reply, app.TwitchClient)
|
common.Send(message.Channel, reply, app.TwitchClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditUserLevel takes in a login name and level string, then updates the database record
|
// EditUserLevel tries to update the database record for the supplied
|
||||||
// for the login name with the new level if such an entry exists.
|
// login name with the new level.
|
||||||
func (app *Application) EditUserLevel(login, lvl string, message twitch.PrivateMessage) {
|
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
|
// Convert the level string to an integer. This is an easy check to see if
|
||||||
// the level supplied was a number only.
|
// the level supplied was a number only.
|
||||||
|
|
Loading…
Reference in a new issue