This commit is contained in:
2022-12-09 23:26:38 -06:00
parent 8df6231b71
commit d8a6c8acd1
15 changed files with 643 additions and 56 deletions

69
endpoints/bots.go Normal file
View File

@@ -0,0 +1,69 @@
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,
})
}