mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
initialize user to database when he uses a command
This commit is contained in:
parent
4d8aab7fd4
commit
abc3b45656
4 changed files with 8 additions and 11 deletions
|
@ -62,11 +62,6 @@ func (app *application) GetCommand(target, commandName string, userLevel int) (s
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Log.Infow("levels",
|
|
||||||
"commandName", commandName,
|
|
||||||
"userLevel", userLevel,
|
|
||||||
"command.Level", command.Level,
|
|
||||||
)
|
|
||||||
if command.Level == 0 {
|
if command.Level == 0 {
|
||||||
return command.Text, nil
|
return command.Text, nil
|
||||||
} else if userLevel >= command.Level {
|
} else if userLevel >= command.Level {
|
||||||
|
|
|
@ -14,7 +14,9 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
||||||
var reply string
|
var reply string
|
||||||
|
|
||||||
// Increments the counter how many commands have been used, called in the ping command.
|
// 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.
|
// commandName is the actual name of the command without the prefix.
|
||||||
// e.g. `()ping` would be `ping`.
|
// e.g. `()ping` would be `ping`.
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
|
|
||||||
// AddUser calls GetIdByLogin to get the twitch id of the login name and then adds
|
// 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.
|
// 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)
|
_, err := app.Models.Users.Check(twitchId)
|
||||||
app.Log.Error(err)
|
//app.Log.Error(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Models.Users.Insert(login, twitchId)
|
app.Models.Users.Insert(login, twitchId)
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,14 @@ type UserModel struct {
|
||||||
// Insert inserts a user model into the database.
|
// Insert inserts a user model into the database.
|
||||||
func (u UserModel) Insert(login, twitchId string) error {
|
func (u UserModel) Insert(login, twitchId string) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO users(login, twitchid)
|
INSERT INTO users(login, twitchid, level)
|
||||||
VALUES ($1, $2)
|
VALUES ($1, $2, $3)
|
||||||
ON CONFLICT (login)
|
ON CONFLICT (login)
|
||||||
DO NOTHING
|
DO NOTHING
|
||||||
RETURNING id, added_at;
|
RETURNING id, added_at;
|
||||||
`
|
`
|
||||||
|
|
||||||
args := []interface{}{login, twitchId}
|
args := []interface{}{login, twitchId, "0"}
|
||||||
|
|
||||||
// Execute the query returning the number of affected rows.
|
// Execute the query returning the number of affected rows.
|
||||||
result, err := u.DB.Exec(query, args...)
|
result, err := u.DB.Exec(query, args...)
|
||||||
|
|
Loading…
Reference in a new issue