add comments

This commit is contained in:
lyx0 2022-08-12 00:08:39 +02:00
parent fbe3f6dc1e
commit 29b6b3c952
4 changed files with 27 additions and 6 deletions

5
cmd/bot/.env .example Normal file
View file

@ -0,0 +1,5 @@
TWITCH_USERNAME=nourybot
TWITCH_OAUTH=oauth:mycooloauthtoken42069
TWITCH_COMMAND_PREFIX=()
DB_DSN=postgres://username:password@localhost/nourybot?sslmode=disable

View file

@ -45,11 +45,12 @@ 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,
// "message", message, // Pretty taxing
"message.Message", message.Message,
"message.Channel", target,
"user level", userLevel,
"userLevel", userLevel,
"commandName", commandName,
"cmdParams", cmdParams,
"msgLen", msgLen,

View file

@ -8,6 +8,10 @@ import (
"github.com/lyx0/nourybot/pkg/common"
)
// AddCommand takes in a name parameter and a twitch.PrivateMessage. It slices the
// twitch.PrivateMessage after the name parameter and adds everything after to a text
// value. Then it calls the app.Models.Commands.Insert method with both name, and text
// values adding them to the database.
func (app *Application) AddCommand(name string, message twitch.PrivateMessage) {
// prefixLength is the length of `()addcommand` plus +2 (for the space and zero based)
prefixLength := 14
@ -36,6 +40,12 @@ func (app *Application) AddCommand(name string, message twitch.PrivateMessage) {
}
}
// GetCommand queries the database for a name. If an entry exists it checks
// if the Command.Level is 0, if it is the command.Text value is returned.
//
// If the Command.Level is not 0 it queries the database for the level of the
// user who sent the message. If the users level is equal or higher
// the command.Text field is returned.
func (app *Application) GetCommand(name, username string) (string, error) {
// Fetch the command from the database if it exists.
command, err := app.Models.Commands.Get(name)
@ -66,6 +76,8 @@ func (app *Application) GetCommand(name, username string) (string, error) {
}
// EditCommandLevel takes in a name and level string and updates the entry with name
// to the supplied level value.
func (app *Application) EditCommandLevel(name, lvl string, message twitch.PrivateMessage) {
level, err := strconv.Atoi(lvl)
if err != nil {
@ -87,6 +99,7 @@ func (app *Application) EditCommandLevel(name, lvl string, message twitch.Privat
}
}
// DeleteCommand takes in a name value and deletes the command from the database if it exists.
func (app *Application) DeleteCommand(name string, message twitch.PrivateMessage) {
err := app.Models.Commands.Delete(name)
if err != nil {

View file

@ -31,10 +31,10 @@ func main() {
// Twitch
cfg.twitchUsername = os.Getenv("TWITCH_USERNAME")
cfg.twitchOauth = os.Getenv("TWITCH_OAUTH")
cfg.commandPrefix = os.Getenv("TWITCH_COMMAND_PREFIX")
tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth)
// Basic configuration
cfg.commandPrefix = "()"
// Will be used someday Copesen
cfg.environment = "Development"
// Database
@ -43,6 +43,7 @@ func main() {
cfg.db.maxIdleConns = 25
cfg.db.maxIdleTime = "15m"
// Establish database connection
db, err := openDB(cfg)
if err != nil {
sugar.Fatal(err)
@ -113,9 +114,10 @@ func main() {
// Start time
common.StartTime()
common.Send("nourylul", "xd", app.TwitchClient)
// app.GetAllChannels()
// Join the channels in the database.
app.InitialJoin()
common.Send("nourylul", "xd", app.TwitchClient)
})
// Actually connect to chat.