Fix invalid call
This commit is contained in:
parent
4a121f6b63
commit
e0ada652d4
@ -11,7 +11,7 @@ import (
|
|||||||
type Settings struct {
|
type Settings struct {
|
||||||
database.Settings
|
database.Settings
|
||||||
Prefix string `json:"prefix"`
|
Prefix string `json:"prefix"`
|
||||||
WelcomeMessaage string `json:"welcome_message"`
|
WelcomeMessage string `json:"welcome_message"`
|
||||||
TicketLimit uint8 `json:"ticket_limit"`
|
TicketLimit uint8 `json:"ticket_limit"`
|
||||||
Category uint64 `json:"category,string"`
|
Category uint64 `json:"category,string"`
|
||||||
ArchiveChannel *uint64 `json:"archive_channel,string"`
|
ArchiveChannel *uint64 `json:"archive_channel,string"`
|
||||||
@ -46,9 +46,9 @@ func GetSettingsHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// welcome message
|
// welcome message
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.WelcomeMessaage, err = dbclient.Client.WelcomeMessages.Get(guildId)
|
settings.WelcomeMessage, err = dbclient.Client.WelcomeMessages.Get(guildId)
|
||||||
if err == nil && settings.WelcomeMessaage == "" {
|
if err == nil && settings.WelcomeMessage == "" {
|
||||||
settings.WelcomeMessaage = "Thank you for contacting support.\nPlease describe your issue and await a response."
|
settings.WelcomeMessage = "Thank you for contacting support.\nPlease describe your issue and await a response."
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -2,16 +2,12 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TicketsBot/GoPanel/botcontext"
|
|
||||||
dbclient "github.com/TicketsBot/GoPanel/database"
|
dbclient "github.com/TicketsBot/GoPanel/database"
|
||||||
"github.com/TicketsBot/GoPanel/rpc/cache"
|
"github.com/TicketsBot/GoPanel/rpc/cache"
|
||||||
"github.com/TicketsBot/database"
|
"github.com/TicketsBot/database"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/rxdn/gdl/objects/channel"
|
"github.com/rxdn/gdl/objects/channel"
|
||||||
"github.com/rxdn/gdl/objects/interaction"
|
|
||||||
"github.com/rxdn/gdl/rest"
|
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,17 +55,7 @@ func (s *Settings) updateSettings(guildId uint64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
group, _ := errgroup.WithContext(context.Background())
|
|
||||||
|
|
||||||
group.Go(func() error {
|
|
||||||
return dbclient.Client.Settings.Set(guildId, s.Settings)
|
return dbclient.Client.Settings.Set(guildId, s.Settings)
|
||||||
})
|
|
||||||
|
|
||||||
group.Go(func() error {
|
|
||||||
return setOpenCommandPermissions(guildId, s.DisableOpenCommand)
|
|
||||||
})
|
|
||||||
|
|
||||||
return group.Wait()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var validAutoArchive = []int{60, 1440, 4320, 10080}
|
var validAutoArchive = []int{60, 1440, 4320, 10080}
|
||||||
@ -141,46 +127,6 @@ func (s *Settings) Validate(guildId uint64) error {
|
|||||||
return group.Wait()
|
return group.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setOpenCommandPermissions(guildId uint64, disabled bool) error {
|
|
||||||
ctx, err := botcontext.ContextForGuild(guildId)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
commands, err := rest.GetGlobalCommands(ctx.Token, ctx.RateLimiter, ctx.BotId)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var commandId uint64
|
|
||||||
for _, cmd := range commands {
|
|
||||||
if cmd.Name == "open" {
|
|
||||||
commandId = cmd.Id
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if commandId == 0 {
|
|
||||||
return errors.New("open command not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
data := rest.CommandWithPermissionsData{
|
|
||||||
Id: commandId,
|
|
||||||
ApplicationId: ctx.BotId,
|
|
||||||
GuildId: guildId,
|
|
||||||
Permissions: []interaction.ApplicationCommandPermissions{
|
|
||||||
{
|
|
||||||
Id: guildId,
|
|
||||||
Type: interaction.ApplicationCommandPermissionTypeRole,
|
|
||||||
Permission: !disabled,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = rest.EditCommandPermissions(ctx.Token, ctx.RateLimiter, ctx.BotId, guildId, commandId, data)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Settings) updatePrefix(guildId uint64) bool {
|
func (s *Settings) updatePrefix(guildId uint64) bool {
|
||||||
if s.Prefix == "" || len(s.Prefix) > 8 {
|
if s.Prefix == "" || len(s.Prefix) > 8 {
|
||||||
return false
|
return false
|
||||||
@ -191,11 +137,11 @@ func (s *Settings) updatePrefix(guildId uint64) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateWelcomeMessage(guildId uint64) bool {
|
func (s *Settings) updateWelcomeMessage(guildId uint64) bool {
|
||||||
if s.WelcomeMessaage == "" || len(s.WelcomeMessaage) > 4096 {
|
if s.WelcomeMessage == "" || len(s.WelcomeMessage) > 4096 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
go dbclient.Client.WelcomeMessages.Set(guildId, s.WelcomeMessaage)
|
go dbclient.Client.WelcomeMessages.Set(guildId, s.WelcomeMessage)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user