diff --git a/cmd/nourybot/command.go b/cmd/nourybot/command.go index d86708f..ad08be1 100644 --- a/cmd/nourybot/command.go +++ b/cmd/nourybot/command.go @@ -62,11 +62,6 @@ func (app *application) GetCommand(target, commandName string, userLevel int) (s return "", err } - app.Log.Infow("levels", - "commandName", commandName, - "userLevel", userLevel, - "command.Level", command.Level, - ) if command.Level == 0 { return command.Text, nil } else if userLevel >= command.Level { diff --git a/cmd/nourybot/commands.go b/cmd/nourybot/commands.go index 98cbdfe..89b38b1 100644 --- a/cmd/nourybot/commands.go +++ b/cmd/nourybot/commands.go @@ -14,7 +14,9 @@ func (app *application) handleCommand(message twitch.PrivateMessage) { var reply string // Increments the counter how many commands have been used, called in the ping command. - common.CommandUsed() + go common.CommandUsed() + + go app.InitUser(message.User.Name, message.User.ID) // commandName is the actual name of the command without the prefix. // e.g. `()ping` would be `ping`. diff --git a/cmd/nourybot/user.go b/cmd/nourybot/user.go index 3334c70..ecfd832 100644 --- a/cmd/nourybot/user.go +++ b/cmd/nourybot/user.go @@ -10,9 +10,9 @@ import ( // 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) InitUser(login, twitchId string, message twitch.PrivateMessage) { +func (app *application) InitUser(login, twitchId string) { _, err := app.Models.Users.Check(twitchId) - app.Log.Error(err) + //app.Log.Error(err) if err != nil { app.Models.Users.Insert(login, twitchId) diff --git a/internal/data/user.go b/internal/data/user.go index 6436f2f..bc90e46 100644 --- a/internal/data/user.go +++ b/internal/data/user.go @@ -23,14 +23,14 @@ type UserModel struct { // Insert inserts a user model into the database. func (u UserModel) Insert(login, twitchId string) error { query := ` - INSERT INTO users(login, twitchid) - VALUES ($1, $2) + INSERT INTO users(login, twitchid, level) + VALUES ($1, $2, $3) ON CONFLICT (login) DO NOTHING RETURNING id, added_at; ` - args := []interface{}{login, twitchId} + args := []interface{}{login, twitchId, "0"} // Execute the query returning the number of affected rows. result, err := u.DB.Exec(query, args...)