1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-11 17:42:48 +00:00

statistics tab for discord chat

This commit is contained in:
2018-04-10 21:51:45 -05:00
parent 27a42f1b99
commit 5fa0f1ac2e
22 changed files with 281 additions and 34 deletions

View File

@@ -4,20 +4,18 @@ import (
"strconv"
"github.com/gin-gonic/gin"
"github.com/mgerb/go-discord-bot/server/db"
"github.com/mgerb/go-discord-bot/server/logger"
)
// GetLogs - get all logs
func GetLogs(c *gin.Context) {
// GetMessages - get all messages
func GetMessages(c *gin.Context) {
page, err := strconv.Atoi(c.Query("page"))
if err != nil {
page = 0
}
messages := []logger.Message{}
err = db.Conn.Offset(page*100).Limit(100).Order("timestamp desc", true).Preload("User").Find(&messages).Error
messages, err := logger.GetMessages(page)
if err != nil {
c.JSON(500, err)
@@ -26,3 +24,15 @@ func GetLogs(c *gin.Context) {
c.JSON(200, messages)
}
// GetLinkedMessages -
func GetLinkedMessages(c *gin.Context) {
posts, err := logger.GetLinkedMessages()
if err != nil {
c.JSON(500, err.Error())
return
}
c.JSON(200, posts)
}

View File

@@ -23,8 +23,9 @@ func getRouter() *gin.Engine {
api.GET("/ytdownloader", handlers.Downloader)
api.GET("/soundlist", handlers.SoundList)
api.GET("/cliplist", handlers.ClipList)
api.GET("/logs", handlers.GetLogs)
api.POST("/oauth", handlers.Oauth)
api.GET("/logger/messages", handlers.GetMessages)
api.GET("/logger/linkedmessages", handlers.GetLinkedMessages)
authorizedAPI := router.Group("/api")
authorizedAPI.Use(middleware.AuthorizedJWT())