Increase panel limit
This commit is contained in:
parent
ddc785af04
commit
66ab75eb69
@ -2,16 +2,17 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/TicketsBot/GoPanel/database"
|
||||
"github.com/TicketsBot/GoPanel/rpc/cache"
|
||||
"github.com/TicketsBot/GoPanel/utils"
|
||||
"github.com/TicketsBot/common/permission"
|
||||
syncutils "github.com/TicketsBot/common/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rxdn/gdl/objects/guild"
|
||||
"github.com/rxdn/gdl/rest/request"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"sort"
|
||||
"sync"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type wrappedGuild struct {
|
||||
@ -32,15 +33,17 @@ func GetGuilds(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wg := syncutils.NewChannelWaitGroup()
|
||||
wg.Add(len(guilds))
|
||||
|
||||
group, _ := errgroup.WithContext(context.Background())
|
||||
|
||||
adminGuilds := make([]wrappedGuild, 0)
|
||||
var lock sync.Mutex
|
||||
|
||||
ch := make(chan wrappedGuild)
|
||||
for _, g := range guilds {
|
||||
g := g
|
||||
|
||||
group.Go(func() error {
|
||||
defer wg.Done()
|
||||
|
||||
// verify bot is in guild
|
||||
_, ok := cache.Instance.GetGuild(g.GuildId, false)
|
||||
if !ok {
|
||||
@ -66,19 +69,52 @@ func GetGuilds(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
if permLevel >= permission.Support {
|
||||
lock.Lock()
|
||||
adminGuilds = append(adminGuilds, wrappedGuild{
|
||||
wrapped := wrappedGuild{
|
||||
Id: g.GuildId,
|
||||
Name: g.Name,
|
||||
Icon: g.Icon,
|
||||
})
|
||||
lock.Unlock()
|
||||
}
|
||||
|
||||
ch <- wrapped
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
adminGuilds := make([]wrappedGuild, 0)
|
||||
group.Go(func() error {
|
||||
adminGuilds := make([]wrappedGuild, 0)
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case <-wg.Wait():
|
||||
break loop
|
||||
case guild := <-ch:
|
||||
// Sort by name
|
||||
var index int
|
||||
for i, el := range adminGuilds {
|
||||
fmt.Printf("%s %s %v\n", guild.Name, el.Name, guild.Name < el.Name)
|
||||
if strings.ToLower(guild.Name) < strings.ToLower(el.Name) {
|
||||
index = i
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if index >= len(adminGuilds) {
|
||||
adminGuilds = append(adminGuilds, guild)
|
||||
} else {
|
||||
adminGuilds = append(adminGuilds, wrappedGuild{}) // create extra capacity with zero value
|
||||
copy(adminGuilds[index+1:], adminGuilds[index:])
|
||||
adminGuilds[index] = guild
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// not possible anyway but eh
|
||||
if err := group.Wait(); err != nil {
|
||||
ctx.JSON(500, gin.H{
|
||||
@ -88,11 +124,6 @@ func GetGuilds(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// sort guilds
|
||||
sort.Slice(adminGuilds, func(i, j int) bool {
|
||||
return adminGuilds[i].Name < adminGuilds[j].Name
|
||||
})
|
||||
|
||||
ctx.JSON(200, adminGuilds)
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const freePanelLimit = 3
|
||||
|
||||
func CreatePanel(ctx *gin.Context) {
|
||||
guildId := ctx.Keys["guildid"].(uint64)
|
||||
|
||||
@ -55,7 +57,7 @@ func CreatePanel(ctx *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
if len(panels) > 0 {
|
||||
if len(panels) >= freePanelLimit {
|
||||
ctx.AbortWithStatusJSON(402, gin.H{
|
||||
"success": false,
|
||||
"error": "You have exceeded your panel quota. Purchase premium to unlock more panels.",
|
||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.14
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/TicketsBot/archiverclient v0.0.0-20200704164621-09d42dd941e0
|
||||
github.com/TicketsBot/common v0.0.0-20201222195753-3dd751ebabf8
|
||||
github.com/TicketsBot/common v0.0.0-20210118171457-d5362b26aa6f
|
||||
github.com/TicketsBot/database v0.0.0-20201224193659-c89391f44b57
|
||||
github.com/TicketsBot/worker v0.0.0-20201224203453-0c8f9a415306
|
||||
github.com/apex/log v1.1.2
|
||||
|
@ -361,7 +361,7 @@
|
||||
if (res.data.premium) {
|
||||
el.appendChild(document.createTextNode('∞'));
|
||||
} else {
|
||||
el.appendChild(document.createTextNode('1'));
|
||||
el.appendChild(document.createTextNode('3'));
|
||||
document.getElementById('premium-ad').style.display = 'block';
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user