This commit is contained in:
rxdn 2022-07-23 22:25:01 +01:00
parent 03257635ca
commit 35658b2aaf
4 changed files with 34 additions and 25 deletions

View File

@ -17,6 +17,18 @@ func AddBlacklistHandler(ctx *gin.Context) {
return return
} }
// Max of 250 blacklisted users
count, err := database.Client.Blacklist.GetBlacklistedCount(guildId)
if err != nil {
ctx.JSON(500, utils.ErrorJson(err))
return
}
if count >= 250 {
ctx.JSON(400, utils.ErrorStr("Blacklist limit (250) reached: consider using a role instead"))
return
}
permLevel, err := utils.GetPermissionLevel(guildId, id) permLevel, err := utils.GetPermissionLevel(guildId, id)
if err != nil { if err != nil {
ctx.JSON(500, utils.ErrorJson(err)) ctx.JSON(500, utils.ErrorJson(err))

View File

@ -2,6 +2,7 @@ package api
import ( import (
"github.com/TicketsBot/GoPanel/database" "github.com/TicketsBot/GoPanel/database"
"github.com/TicketsBot/GoPanel/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -12,41 +13,39 @@ type tag struct {
func CreateTag(ctx *gin.Context) { func CreateTag(ctx *gin.Context) {
guildId := ctx.Keys["guildid"].(uint64) guildId := ctx.Keys["guildid"].(uint64)
var data tag
// Max of 200 tags
count, err := database.Client.Tag.GetTagCount(guildId)
if err != nil {
ctx.JSON(500, utils.ErrorJson(err))
return
}
if count >= 200 {
ctx.JSON(400, utils.ErrorStr("Tag limit (200) reached"))
return
}
var data tag
if err := ctx.BindJSON(&data); err != nil { if err := ctx.BindJSON(&data); err != nil {
ctx.AbortWithStatusJSON(400, gin.H{ ctx.JSON(400, utils.ErrorJson(err))
"success": false,
"error": err.Error(),
})
return return
} }
if !data.verifyIdLength() { if !data.verifyIdLength() {
ctx.AbortWithStatusJSON(400, gin.H{ ctx.JSON(400, utils.ErrorStr("Tag ID must be 1 - 16 characters in length"))
"success": false,
"error": "Tag ID must be 1 - 16 characters in length",
})
return return
} }
if !data.verifyContentLength() { if !data.verifyContentLength() {
ctx.AbortWithStatusJSON(400, gin.H{ ctx.JSON(400, utils.ErrorStr("Tag content must be 1 - 2000 characters in length"))
"success": false,
"error": "Tag content must be 1 - 2000 characters in length",
})
return return
} }
if err := database.Client.Tag.Set(guildId, data.Id, data.Content); err != nil { if err := database.Client.Tag.Set(guildId, data.Id, data.Content); err != nil {
ctx.AbortWithStatusJSON(500, gin.H{ ctx.JSON(500, utils.ErrorJson(err))
"success": false,
"error": err.Error(),
})
} else { } else {
ctx.JSON(200, gin.H{ ctx.JSON(200, utils.SuccessResponse)
"success": true,
})
} }
} }

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/BurntSushi/toml v0.3.1 github.com/BurntSushi/toml v0.3.1
github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc
github.com/TicketsBot/common v0.0.0-20220703211704-f792aa9f0c42 github.com/TicketsBot/common v0.0.0-20220703211704-f792aa9f0c42
github.com/TicketsBot/database v0.0.0-20220723203414-97262005b792 github.com/TicketsBot/database v0.0.0-20220723212053-ab122ba82749
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c
github.com/TicketsBot/worker v0.0.0-20220710121124-cd5ec72739f9 github.com/TicketsBot/worker v0.0.0-20220710121124-cd5ec72739f9
github.com/apex/log v1.1.2 github.com/apex/log v1.1.2

6
go.sum
View File

@ -5,10 +5,8 @@ github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc h1:n15W8
github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc/go.mod h1:2KcfHS0JnSsgcxZBs3NyWMXNQzEo67mBSGOyzHPWOCc= github.com/TicketsBot/archiverclient v0.0.0-20220326163414-558fd52746dc/go.mod h1:2KcfHS0JnSsgcxZBs3NyWMXNQzEo67mBSGOyzHPWOCc=
github.com/TicketsBot/common v0.0.0-20220703211704-f792aa9f0c42 h1:3/qnbrEfL8gqSbjJ4o7WKkdoPngmhjAGEXFwteEjpqs= github.com/TicketsBot/common v0.0.0-20220703211704-f792aa9f0c42 h1:3/qnbrEfL8gqSbjJ4o7WKkdoPngmhjAGEXFwteEjpqs=
github.com/TicketsBot/common v0.0.0-20220703211704-f792aa9f0c42/go.mod h1:WxHh6bY7KhIqdayeOp5f0Zj2NNi/7QqCQfMEqHnpdAM= github.com/TicketsBot/common v0.0.0-20220703211704-f792aa9f0c42/go.mod h1:WxHh6bY7KhIqdayeOp5f0Zj2NNi/7QqCQfMEqHnpdAM=
github.com/TicketsBot/database v0.0.0-20220721214509-131e86b1a06c h1:eyAFQuKihRkfkSNg1xeIm9nHQZ1z2Qg46kS7LcLZNxk= github.com/TicketsBot/database v0.0.0-20220723212053-ab122ba82749 h1:U/TnoBH3AyeV8uuQK/g69NfdNzGYGnjMD5KryJ+93Ok=
github.com/TicketsBot/database v0.0.0-20220721214509-131e86b1a06c/go.mod h1:F57cywrZsnper1cy56Bx0c/HEsxQBLHz3Pl98WXblWw= github.com/TicketsBot/database v0.0.0-20220723212053-ab122ba82749/go.mod h1:F57cywrZsnper1cy56Bx0c/HEsxQBLHz3Pl98WXblWw=
github.com/TicketsBot/database v0.0.0-20220723203414-97262005b792 h1:hBkD95dzF1F9CG6+E0xJKCWxt6NIhZjxjvqIFz6h8Kg=
github.com/TicketsBot/database v0.0.0-20220723203414-97262005b792/go.mod h1:F57cywrZsnper1cy56Bx0c/HEsxQBLHz3Pl98WXblWw=
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c h1:OqGjFH6mbE6gd+NqI2ARJdtH3UUvhiAkD0r0fhGJK2s= github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c h1:OqGjFH6mbE6gd+NqI2ARJdtH3UUvhiAkD0r0fhGJK2s=
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c/go.mod h1:jgi2OXQKsd5nUnTIRkwvPmeuD/i7OhN68LKMssuQY1c= github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c/go.mod h1:jgi2OXQKsd5nUnTIRkwvPmeuD/i7OhN68LKMssuQY1c=
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM= github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM=