69 lines
1.2 KiB
Go
69 lines
1.2 KiB
Go
package endpoints
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.zomo.dev/zomo/discord-retokenizer/storage"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type SimpleDiscordUser struct {
|
|
Username string `json:"username"`
|
|
Discriminator string `json:"discriminator"`
|
|
Avatar string `json:"avatar"`
|
|
Banner string `json:"banner"`
|
|
Accent_color int `json:"accent_color"`
|
|
Verified bool `json:"verified"`
|
|
}
|
|
|
|
type BotData struct {
|
|
Token string
|
|
ID string
|
|
Loaded SimpleDiscordUser
|
|
}
|
|
|
|
// one array of just bot ids
|
|
// `bot:(id):token`
|
|
// `bot:(id):data`
|
|
// SimpleDiscordUser
|
|
|
|
func bots(c *gin.Context) {
|
|
bots := storage.GetBots()
|
|
c.JSON(200, bots)
|
|
}
|
|
|
|
func bot(c *gin.Context) {
|
|
id := c.Param("id")
|
|
bot := storage.GetBot(id)
|
|
c.JSON(200, bot)
|
|
}
|
|
|
|
type addBotBody struct {
|
|
Token string `json:"token" binding:"required"`
|
|
}
|
|
|
|
func addBot(c *gin.Context) {
|
|
var tokenBody addBotBody
|
|
if err := c.BindJSON(&tokenBody); err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
didSet := storage.AddBot(tokenBody.Token)
|
|
if didSet {
|
|
c.JSON(200, gin.H{
|
|
"success": true,
|
|
})
|
|
} else {
|
|
c.JSON(400, gin.H{
|
|
"success": false,
|
|
})
|
|
}
|
|
}
|
|
|
|
func removeBot(c *gin.Context) {
|
|
id := c.Param("id")
|
|
storage.RemoveBot(id)
|
|
c.JSON(200, gin.H{
|
|
"success": true,
|
|
})
|
|
} |