mirror of
https://github.com/mgerb/go-discord-bot
synced 2026-01-11 17:42:48 +00:00
feat: add user event log to admin page
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package model
|
||||
|
||||
var Migrations []interface{} = []interface{}{
|
||||
// Migrations - list of database migrations
|
||||
var Migrations = []interface{}{
|
||||
&Message{},
|
||||
&Attachment{},
|
||||
&User{},
|
||||
&VideoArchive{},
|
||||
&Sound{},
|
||||
&UserEventLog{},
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ type Sound struct {
|
||||
User User `json:"user"`
|
||||
}
|
||||
|
||||
func SoundCreate(conn *gorm.DB, sound *Sound) error {
|
||||
func SoundSave(conn *gorm.DB, sound *Sound) error {
|
||||
return conn.Create(sound).Error
|
||||
}
|
||||
|
||||
func SoundList(conn *gorm.DB) ([]Sound, error) {
|
||||
func SoundGet(conn *gorm.DB) ([]Sound, error) {
|
||||
sound := []Sound{}
|
||||
err := conn.Set("gorm:auto_preload", true).Find(&sound).Error
|
||||
return sound, err
|
||||
|
||||
51
server/webserver/model/user_event_log.go
Normal file
51
server/webserver/model/user_event_log.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
// UserEventLog - logger for user events
|
||||
type UserEventLog struct {
|
||||
ID uint `gorm:"primary_key; auto_increment; not null" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt *time.Time `json:"deleted_at"`
|
||||
Content string `json:"content"`
|
||||
User User `json:"user"`
|
||||
UserID string `json:"user_id"`
|
||||
}
|
||||
|
||||
// UserEventLogSave -
|
||||
func UserEventLogSave(conn *gorm.DB, m *UserEventLog) error {
|
||||
return conn.Save(m).Error
|
||||
}
|
||||
|
||||
// UserEventLogGet - returns all messages - must use paging
|
||||
func UserEventLogGet(conn *gorm.DB, page int) ([]*UserEventLog, error) {
|
||||
userEventLog := []*UserEventLog{}
|
||||
err := conn.Offset(page*100).Limit(100).Order("created_at desc", true).Preload("User").Find(&userEventLog).Error
|
||||
return userEventLog, err
|
||||
}
|
||||
|
||||
// LogSoundPlayedEvent - log event when user plays sound clip
|
||||
func LogSoundPlayedEvent(conn *gorm.DB, userID, soundName string, fromWebUI bool) error {
|
||||
|
||||
var content string
|
||||
|
||||
// from discord
|
||||
if !fromWebUI {
|
||||
content = "played sound clip: " + soundName
|
||||
} else {
|
||||
content = "played sound clip from web UI: " + soundName
|
||||
}
|
||||
|
||||
// log play event
|
||||
userEventLog := &UserEventLog{
|
||||
UserID: userID,
|
||||
Content: content,
|
||||
}
|
||||
|
||||
return UserEventLogSave(conn, userEventLog)
|
||||
}
|
||||
Reference in New Issue
Block a user