This commit is contained in:
rxdn 2021-05-27 13:43:25 +01:00
parent c83858bebf
commit 8993b31a0b
13 changed files with 178 additions and 163 deletions

View File

@ -60,7 +60,7 @@ func MultiPanelCreate(ctx *gin.Context) {
messageId, err := data.sendEmbed(&botContext, premiumTier > premium.None) messageId, err := data.sendEmbed(&botContext, premiumTier > premium.None)
if err != nil { if err != nil {
var unwrapped request.RestError var unwrapped request.RestError
if errors.As(err, &unwrapped); unwrapped.ErrorCode == 403 { if errors.As(err, &unwrapped); unwrapped.StatusCode == 403 {
ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to send messages in the provided channel"))) ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to send messages in the provided channel")))
} else { } else {
ctx.JSON(500, utils.ErrorJson(err)) ctx.JSON(500, utils.ErrorJson(err))
@ -71,7 +71,7 @@ func MultiPanelCreate(ctx *gin.Context) {
if err := data.addReactions(&botContext, data.ChannelId, messageId, panels); err != nil { if err := data.addReactions(&botContext, data.ChannelId, messageId, panels); err != nil {
var unwrapped request.RestError var unwrapped request.RestError
if errors.As(err, &unwrapped); unwrapped.ErrorCode == 403{ if errors.As(err, &unwrapped); unwrapped.StatusCode == 403{
ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to add reactions in the provided channel"))) ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to add reactions in the provided channel")))
} else { } else {
ctx.JSON(500, utils.ErrorJson(err)) ctx.JSON(500, utils.ErrorJson(err))

View File

@ -80,7 +80,7 @@ func MultiPanelUpdate(ctx *gin.Context) {
messageId, err := data.sendEmbed(&botContext, premiumTier > premium.None) messageId, err := data.sendEmbed(&botContext, premiumTier > premium.None)
if err != nil { if err != nil {
var unwrapped request.RestError var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 { if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 {
ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to send messages in the provided channel"))) ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to send messages in the provided channel")))
} else { } else {
ctx.JSON(500, utils.ErrorJson(err)) ctx.JSON(500, utils.ErrorJson(err))
@ -92,7 +92,7 @@ func MultiPanelUpdate(ctx *gin.Context) {
// add reactions to new message // add reactions to new message
if err := data.addReactions(&botContext, data.ChannelId, messageId, panels); err != nil { if err := data.addReactions(&botContext, data.ChannelId, messageId, panels); err != nil {
var unwrapped request.RestError var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 { if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 {
ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to add reactions in the provided channel"))) ctx.JSON(500, utils.ErrorJson(errors.New("I do not have permission to add reactions in the provided channel")))
} else { } else {
ctx.JSON(500, utils.ErrorJson(err)) ctx.JSON(500, utils.ErrorJson(err))

View File

@ -14,7 +14,8 @@ import (
"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/channel/embed" "github.com/rxdn/gdl/objects/channel/embed"
"github.com/rxdn/gdl/objects/channel/message" "github.com/rxdn/gdl/objects/guild/emoji"
"github.com/rxdn/gdl/objects/interaction/component"
"github.com/rxdn/gdl/rest" "github.com/rxdn/gdl/rest"
"github.com/rxdn/gdl/rest/request" "github.com/rxdn/gdl/rest/request"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
@ -38,7 +39,6 @@ type panelBody struct {
} }
func CreatePanel(ctx *gin.Context) { func CreatePanel(ctx *gin.Context) {
guildId := ctx.Keys["guildid"].(uint64) guildId := ctx.Keys["guildid"].(uint64)
botContext, err := botcontext.ContextForGuild(guildId) botContext, err := botcontext.ContextForGuild(guildId)
@ -87,10 +87,13 @@ func CreatePanel(ctx *gin.Context) {
return return
} }
msgId, err := data.sendEmbed(&botContext, premiumTier > premium.None) customId := utils.RandString(80)
emoji, _ := data.getEmoji() // already validated
msgId, err := data.sendEmbed(&botContext, data.Title, customId, emoji, premiumTier > premium.None)
if err != nil { if err != nil {
var unwrapped request.RestError var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 { if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 {
ctx.AbortWithStatusJSON(500, gin.H{ ctx.AbortWithStatusJSON(500, gin.H{
"success": false, "success": false,
"error": "I do not have permission to send messages in the specified channel", "error": "I do not have permission to send messages in the specified channel",
@ -106,26 +109,6 @@ func CreatePanel(ctx *gin.Context) {
return return
} }
// Add reaction
emoji, _ := data.getEmoji() // already validated
if err = rest.CreateReaction(botContext.Token, botContext.RateLimiter, data.ChannelId, msgId, emoji); err != nil {
var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 {
ctx.AbortWithStatusJSON(500, gin.H{
"success": false,
"error": "I do not have permission to add reactions in the specified channel",
})
} else {
// TODO: Most appropriate error?
ctx.AbortWithStatusJSON(500, gin.H{
"success": false,
"error": err.Error(),
})
}
return
}
// Store in DB // Store in DB
panel := database.Panel{ panel := database.Panel{
MessageId: msgId, MessageId: msgId,
@ -138,9 +121,11 @@ func CreatePanel(ctx *gin.Context) {
ReactionEmote: emoji, ReactionEmote: emoji,
WelcomeMessage: data.WelcomeMessage, WelcomeMessage: data.WelcomeMessage,
WithDefaultTeam: utils.ContainsString(data.Teams, "default"), WithDefaultTeam: utils.ContainsString(data.Teams, "default"),
CustomId: customId,
} }
if err = dbclient.Client.Panel.Create(panel); err != nil { panelId, err := dbclient.Client.Panel.Create(panel)
if err != nil {
ctx.AbortWithStatusJSON(500, gin.H{ ctx.AbortWithStatusJSON(500, gin.H{
"success": false, "success": false,
"error": err.Error(), "error": err.Error(),
@ -189,7 +174,7 @@ func CreatePanel(ctx *gin.Context) {
ctx.JSON(200, gin.H{ ctx.JSON(200, gin.H{
"success": true, "success": true,
"message_id": strconv.FormatUint(msgId, 10), "panel_id": strconv.Itoa(panelId),
}) })
} }
@ -323,7 +308,7 @@ func (p *panelBody) verifyWelcomeMessage() bool {
return p.WelcomeMessage == nil || (len(*p.WelcomeMessage) > 0 && len(*p.WelcomeMessage) < 1025) return p.WelcomeMessage == nil || (len(*p.WelcomeMessage) > 0 && len(*p.WelcomeMessage) < 1025)
} }
func (p *panelBody) sendEmbed(ctx *botcontext.BotContext, isPremium bool) (messageId uint64, err error) { func (p *panelBody) sendEmbed(ctx *botcontext.BotContext, title, customId, emote string, isPremium bool) (uint64, error) {
e := embed.NewEmbed(). e := embed.NewEmbed().
SetTitle(p.Title). SetTitle(p.Title).
SetDescription(p.Content). SetDescription(p.Content).
@ -334,12 +319,36 @@ func (p *panelBody) sendEmbed(ctx *botcontext.BotContext, isPremium bool) (messa
e.SetFooter("Powered by ticketsbot.net", "https://cdn.discordapp.com/avatars/508391840525975553/ac2647ffd4025009e2aa852f719a8027.png?size=256") e.SetFooter("Powered by ticketsbot.net", "https://cdn.discordapp.com/avatars/508391840525975553/ac2647ffd4025009e2aa852f719a8027.png?size=256")
} }
var msg message.Message data := rest.CreateMessageData{
msg, err = rest.CreateMessage(ctx.Token, ctx.RateLimiter, p.ChannelId, rest.CreateMessageData{Embed: e}) Embed: e,
if err != nil { Components: []component.Component{
return {
Type: component.ComponentActionRow,
ComponentData: component.ActionRow{
Components: []component.Component{
{
Type: component.ComponentButton,
ComponentData: component.Button{
Label: title,
CustomId: customId,
Style: component.ButtonStylePrimary,
Emoji: emoji.Emoji{
Name: emote,
},
Url: nil,
Disabled: false,
},
},
},
},
},
},
} }
messageId = msg.Id msg, err := rest.CreateMessage(ctx.Token, ctx.RateLimiter, p.ChannelId, data)
return if err != nil {
return 0, err
}
return msg.Id, nil
} }

View File

@ -20,7 +20,7 @@ func DeletePanel(ctx *gin.Context) {
return return
} }
messageId, err := strconv.ParseUint(ctx.Param("message"), 10, 64) panelId, err := strconv.Atoi(ctx.Param("id"))
if err != nil { if err != nil {
ctx.AbortWithStatusJSON(400, gin.H{ ctx.AbortWithStatusJSON(400, gin.H{
"success": false, "success": false,
@ -29,7 +29,7 @@ func DeletePanel(ctx *gin.Context) {
return return
} }
panel, err := database.Client.Panel.Get(messageId) panel, err := database.Client.Panel.GetById(panelId)
if err != nil { if err != nil {
ctx.JSON(500, gin.H{ ctx.JSON(500, gin.H{
"success": false, "success": false,
@ -47,7 +47,7 @@ func DeletePanel(ctx *gin.Context) {
return return
} }
if err := database.Client.Panel.Delete(messageId); err != nil { if err := database.Client.Panel.Delete(panelId); err != nil {
ctx.JSON(500, gin.H{ ctx.JSON(500, gin.H{
"success": false, "success": false,
"error": err.Error(), "error": err.Error(),

View File

@ -11,8 +11,8 @@ import (
func ListPanels(ctx *gin.Context) { func ListPanels(ctx *gin.Context) {
type panelResponse struct { type panelResponse struct {
PanelId int `json:"panel_id"`
ChannelId uint64 `json:"channel_id,string"` ChannelId uint64 `json:"channel_id,string"`
MessageId uint64 `json:"message_id,string"`
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`
Colour uint32 `json:"colour"` Colour uint32 `json:"colour"`
@ -74,7 +74,7 @@ func ListPanels(ctx *gin.Context) {
} }
wrapped[i] = panelResponse{ wrapped[i] = panelResponse{
MessageId: p.MessageId, PanelId: p.PanelId,
ChannelId: p.ChannelId, ChannelId: p.ChannelId,
Title: p.Title, Title: p.Title,
Content: p.Content, Content: p.Content,

View File

@ -33,16 +33,14 @@ func UpdatePanel(ctx *gin.Context) {
return return
} }
messageId, err := strconv.ParseUint(ctx.Param("message"), 10, 64) panelId, err := strconv.Atoi(ctx.Param("id"))
if err != nil { if err != nil {
ctx.AbortWithStatusJSON(400, utils.ErrorJson(err)) ctx.AbortWithStatusJSON(400, utils.ErrorJson(err))
return return
} }
data.MessageId = messageId
// get existing // get existing
existing, err := dbclient.Client.Panel.Get(data.MessageId) existing, err := dbclient.Client.Panel.GetById(panelId)
if err != nil { if err != nil {
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
return return
@ -121,7 +119,7 @@ func UpdatePanel(ctx *gin.Context) {
existing.ReactionEmote != data.Emote existing.ReactionEmote != data.Emote
emoji, _ := data.getEmoji() // already validated emoji, _ := data.getEmoji() // already validated
newMessageId := messageId newMessageId := existing.MessageId
if shouldUpdateMessage { if shouldUpdateMessage {
// delete old message // delete old message
@ -134,10 +132,10 @@ func UpdatePanel(ctx *gin.Context) {
} }
premiumTier := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter) premiumTier := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
newMessageId, err = data.sendEmbed(&botContext, premiumTier > premium.None) newMessageId, err = data.sendEmbed(&botContext, existing.Title, existing.CustomId, existing.ReactionEmote, premiumTier > premium.None)
if err != nil { if err != nil {
var unwrapped request.RestError var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 { if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 {
ctx.AbortWithStatusJSON(500, gin.H{ ctx.AbortWithStatusJSON(500, gin.H{
"success": false, "success": false,
"error": "I do not have permission to send messages in the specified channel", "error": "I do not have permission to send messages in the specified channel",
@ -153,7 +151,7 @@ func UpdatePanel(ctx *gin.Context) {
// Add reaction // Add reaction
if err = rest.CreateReaction(botContext.Token, botContext.RateLimiter, data.ChannelId, newMessageId, emoji); err != nil { if err = rest.CreateReaction(botContext.Token, botContext.RateLimiter, data.ChannelId, newMessageId, emoji); err != nil {
var unwrapped request.RestError var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 { if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 {
ctx.AbortWithStatusJSON(500, gin.H{ ctx.AbortWithStatusJSON(500, gin.H{
"success": false, "success": false,
"error": "I do not have permission to add reactions in the specified channel", "error": "I do not have permission to add reactions in the specified channel",
@ -169,6 +167,7 @@ func UpdatePanel(ctx *gin.Context) {
// Store in DB // Store in DB
panel := database.Panel{ panel := database.Panel{
PanelId: panelId,
MessageId: newMessageId, MessageId: newMessageId,
ChannelId: data.ChannelId, ChannelId: data.ChannelId,
GuildId: guildId, GuildId: guildId,
@ -181,7 +180,7 @@ func UpdatePanel(ctx *gin.Context) {
WithDefaultTeam: utils.ContainsString(data.Teams, "default"), WithDefaultTeam: utils.ContainsString(data.Teams, "default"),
} }
if err = dbclient.Client.Panel.Update(messageId, panel); err != nil { if err = dbclient.Client.Panel.Update(panel); err != nil {
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
return return
} }
@ -239,6 +238,5 @@ func UpdatePanel(ctx *gin.Context) {
ctx.JSON(200, gin.H{ ctx.JSON(200, gin.H{
"success": true, "success": true,
"message_id": strconv.FormatUint(newMessageId, 10),
}) })
} }

View File

@ -116,7 +116,7 @@ func SendMessage(ctx *gin.Context) {
if err != nil { if err != nil {
// We can delete the webhook in this case // We can delete the webhook in this case
var unwrapped request.RestError var unwrapped request.RestError
if errors.As(err, &unwrapped); unwrapped.ErrorCode == 403 || unwrapped.ErrorCode == 404 { if errors.As(err, &unwrapped); unwrapped.StatusCode == 403 || unwrapped.StatusCode == 404 {
go database.Client.Webhooks.Delete(guildId, ticketId) go database.Client.Webhooks.Delete(guildId, ticketId)
} }
} else { } else {

View File

@ -5,13 +5,20 @@ import (
"github.com/TicketsBot/GoPanel/botcontext" "github.com/TicketsBot/GoPanel/botcontext"
"github.com/TicketsBot/GoPanel/database" "github.com/TicketsBot/GoPanel/database"
"github.com/TicketsBot/GoPanel/messagequeue" "github.com/TicketsBot/GoPanel/messagequeue"
command "github.com/TicketsBot/worker/bot/command/impl" "github.com/TicketsBot/worker/bot/command/impl/admin"
"github.com/TicketsBot/worker/bot/command/manager"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/rxdn/gdl/rest" "github.com/rxdn/gdl/rest"
"time" "time"
) )
func WhitelabelCreateInteractions(ctx *gin.Context) { // TODO: Refactor
func GetWhitelabelCreateInteractions() func(*gin.Context) {
cm := new(manager.CommandManager)
cm.RegisterCommands()
return func(ctx *gin.Context) {
userId := ctx.Keys["userid"].(uint64) userId := ctx.Keys["userid"].(uint64)
// Get bot // Get bot
@ -75,14 +82,14 @@ func WhitelabelCreateInteractions(ctx *gin.Context) {
} }
var interactions []rest.CreateCommandData var interactions []rest.CreateCommandData
for _, cmd := range command.Commands { for _, cmd := range cm.GetCommands() {
properties := cmd.Properties() properties := cmd.Properties()
if properties.MessageOnly || properties.AdminOnly || properties.HelperOnly || properties.MainBotOnly { if properties.MessageOnly || properties.AdminOnly || properties.HelperOnly || properties.MainBotOnly {
continue continue
} }
option := command.BuildOption(cmd) option := admin.BuildOption(cmd)
data := rest.CreateCommandData{ data := rest.CreateCommandData{
Name: option.Name, Name: option.Name,
@ -104,3 +111,4 @@ func WhitelabelCreateInteractions(ctx *gin.Context) {
}) })
} }
} }
}

View File

@ -67,7 +67,7 @@ func CallbackHandler(ctx *gin.Context) {
return return
} }
store.Set("csrf", utils.RandStringRunes(32)) store.Set("csrf", utils.RandString(32))
store.Set("userid", currentUser.Id) store.Set("userid", currentUser.Id)
store.Set("name", currentUser.Username) store.Set("name", currentUser.Username)

View File

@ -101,8 +101,8 @@ func StartServer() {
guildAuthApiAdmin.GET("/panels", api_panels.ListPanels) guildAuthApiAdmin.GET("/panels", api_panels.ListPanels)
guildAuthApiAdmin.PUT("/panels", api_panels.CreatePanel) guildAuthApiAdmin.PUT("/panels", api_panels.CreatePanel)
guildAuthApiAdmin.PUT("/panels/:message", api_panels.UpdatePanel) guildAuthApiAdmin.PUT("/panels/:id", api_panels.UpdatePanel)
guildAuthApiAdmin.DELETE("/panels/:message", api_panels.DeletePanel) guildAuthApiAdmin.DELETE("/panels/:id", api_panels.DeletePanel)
guildAuthApiAdmin.GET("/multipanels", api_panels.MultiPanelList) guildAuthApiAdmin.GET("/multipanels", api_panels.MultiPanelList)
guildAuthApiAdmin.POST("/multipanels", api_panels.MultiPanelCreate) guildAuthApiAdmin.POST("/multipanels", api_panels.MultiPanelCreate)
@ -149,7 +149,7 @@ func StartServer() {
whitelabelApiGroup.GET("/guilds", api_whitelabel.WhitelabelGetGuilds) whitelabelApiGroup.GET("/guilds", api_whitelabel.WhitelabelGetGuilds)
whitelabelApiGroup.GET("/public-key", api_whitelabel.WhitelabelGetPublicKey) whitelabelApiGroup.GET("/public-key", api_whitelabel.WhitelabelGetPublicKey)
whitelabelApiGroup.POST("/public-key", api_whitelabel.WhitelabelPostPublicKey) whitelabelApiGroup.POST("/public-key", api_whitelabel.WhitelabelPostPublicKey)
whitelabelApiGroup.POST("/create-interactions", api_whitelabel.WhitelabelCreateInteractions) whitelabelApiGroup.POST("/create-interactions", api_whitelabel.GetWhitelabelCreateInteractions())
whitelabelApiGroup.POST("/", createLimiter(10, time.Minute), api_whitelabel.WhitelabelPost) whitelabelApiGroup.POST("/", createLimiter(10, time.Minute), api_whitelabel.WhitelabelPost)
whitelabelApiGroup.POST("/status", createLimiter(1, time.Second*5), api_whitelabel.WhitelabelStatusPost) whitelabelApiGroup.POST("/status", createLimiter(1, time.Second*5), api_whitelabel.WhitelabelStatusPost)

10
go.mod
View File

@ -5,23 +5,23 @@ go 1.14
require ( require (
github.com/BurntSushi/toml v0.3.1 github.com/BurntSushi/toml v0.3.1
github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb
github.com/TicketsBot/common v0.0.0-20210314144843-3ac00a091e42 github.com/TicketsBot/common v0.0.0-20210508230445-142f7765b87f
github.com/TicketsBot/database v0.0.0-20210314143312-464ac4588cf2 github.com/TicketsBot/database v0.0.0-20210526225555-040a69389e53
github.com/TicketsBot/worker v0.0.0-20210314143458-b27c23beab4b github.com/TicketsBot/worker v0.0.0-20210526230503-cf3fa42fed99
github.com/apex/log v1.1.2 github.com/apex/log v1.1.2
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-contrib/multitemplate v0.0.0-20200226145339-3e397ee01bc6 github.com/gin-contrib/multitemplate v0.0.0-20200226145339-3e397ee01bc6
github.com/gin-contrib/static v0.0.0-20191128031702-f81c604d8ac2 github.com/gin-contrib/static v0.0.0-20191128031702-f81c604d8ac2
github.com/gin-gonic/contrib v0.0.0-20191209060500-d6e26eeaa607 github.com/gin-gonic/contrib v0.0.0-20191209060500-d6e26eeaa607
github.com/gin-gonic/gin v1.6.2 github.com/gin-gonic/gin v1.7.1
github.com/go-redis/redis v6.15.9+incompatible github.com/go-redis/redis v6.15.9+incompatible
github.com/gorilla/sessions v1.2.0 // indirect github.com/gorilla/sessions v1.2.0 // indirect
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/jackc/pgx/v4 v4.7.1 github.com/jackc/pgx/v4 v4.7.1
github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/rxdn/gdl v0.0.0-20210301221508-d84ed0db0f5c github.com/rxdn/gdl v0.0.0-20210527124215-63f4791eb845
github.com/sirupsen/logrus v1.5.0 github.com/sirupsen/logrus v1.5.0
github.com/ulule/limiter/v3 v3.5.0 github.com/ulule/limiter/v3 v3.5.0
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a

View File

@ -255,13 +255,13 @@
} }
} }
async function deletePanel(messageId) { async function deletePanel(panelId) {
const res = await axios.delete('/api/{{.guildId}}/panels/' + messageId); const res = await axios.delete('/api/{{.guildId}}/panels/' + panelId);
if (res.status === 200 && res.data.success) { if (res.status === 200 && res.data.success) {
notifySuccess('Panel deleted successfully'); notifySuccess('Panel deleted successfully');
const el = document.getElementById(messageId); const el = document.getElementById(panelId);
el.parentNode.removeChild(el); el.parentNode.removeChild(el);
} else { } else {
notifyError(res.data.error); notifyError(res.data.error);
@ -301,7 +301,7 @@
const res = await axios.put('/api/{{.guildId}}/panels', data); const res = await axios.put('/api/{{.guildId}}/panels', data);
if (res.status === 200 && res.data.success) { if (res.status === 200 && res.data.success) {
data.message_id = res.data.message_id; data.panel_id = res.data.panel_id;
appendPanel(data, await getChannels()); appendPanel(data, await getChannels());
notifySuccess('Panel created successfully') notifySuccess('Panel created successfully')
} else { } else {
@ -381,7 +381,7 @@
const container = document.getElementById('panel-container'); const container = document.getElementById('panel-container');
const tr = document.createElement('tr'); const tr = document.createElement('tr');
tr.id = panel.message_id; // TODO: When we call this after creating a panel, we don't know the message ID yet tr.id = panel.panel_id;
appendTd(tr, `#${getChannelName(channels, panel.channel_id)}`); appendTd(tr, `#${getChannelName(channels, panel.channel_id)}`);
appendTd(tr, panel.title); appendTd(tr, panel.title);
@ -393,7 +393,7 @@
editButton.type = 'button'; editButton.type = 'button';
editButton.classList.add('btn', 'btn-primary', 'btn-fill', 'mx-auto'); editButton.classList.add('btn', 'btn-primary', 'btn-fill', 'mx-auto');
editButton.appendChild(document.createTextNode('Edit')); editButton.appendChild(document.createTextNode('Edit'));
editButton.onclick = () => { openEditModal(panel.message_id) }; editButton.onclick = () => { openEditModal(panel.panel_id) };
editTd.appendChild(editButton); editTd.appendChild(editButton);
tr.appendChild(editTd); tr.appendChild(editTd);
@ -403,7 +403,7 @@
deleteButton.type = 'submit'; deleteButton.type = 'submit';
deleteButton.classList.add('btn', 'btn-primary', 'btn-fill', 'mx-auto'); deleteButton.classList.add('btn', 'btn-primary', 'btn-fill', 'mx-auto');
deleteButton.appendChild(document.createTextNode('Delete')); deleteButton.appendChild(document.createTextNode('Delete'));
deleteButton.onclick = () => {deletePanel(panel.message_id)}; deleteButton.onclick = () => {deletePanel(panel.panel_id)};
deleteTd.appendChild(deleteButton); deleteTd.appendChild(deleteButton);
tr.appendChild(deleteTd); tr.appendChild(deleteTd);
@ -475,7 +475,7 @@
for (const panel of panels) { for (const panel of panels) {
const option = document.createElement('option'); const option = document.createElement('option');
option.value = panel.message_id; option.value = panel.panel_id;
option.appendChild(document.createTextNode(panel.title)); option.appendChild(document.createTextNode(panel.title));
select.appendChild(option); select.appendChild(option);
} }

View File

@ -8,7 +8,7 @@ import (
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func RandStringRunes(length int) string { func RandString(length int) string {
b := make([]rune, length) b := make([]rune, length)
for i := range b { for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))] b[i] = letterRunes[rand.Intn(len(letterRunes))]