1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-11 09:32:50 +00:00

use permissions from database - updated bot-scripts

This commit is contained in:
2018-10-20 13:42:37 -05:00
parent 3f650e7c65
commit b004d4f29a
15 changed files with 126 additions and 57 deletions

View File

@@ -3,6 +3,7 @@ package model
import (
"time"
"github.com/jinzhu/copier"
"github.com/jinzhu/gorm"
)
@@ -20,9 +21,15 @@ type User struct {
Verified bool `json:"verified"`
MFAEnabled bool `json:"mfa_enabled"`
Bot bool `json:"bot"`
Permissions *int `gorm:"default:1;not null" json:"permissions"`
}
// UserSave -
func UserSave(conn *gorm.DB, u *User) error {
return conn.Save(u).Error
var userCopy User
copier.Copy(&userCopy, u)
// insert or update user
// need to make copy of assign object because it must mess
// with the actual object in FirstOrCreate method
return conn.Where(&User{ID: u.ID}).Assign(userCopy).FirstOrCreate(u).Error
}