Customisation options
This commit is contained in:
parent
aed0f28f13
commit
1e2ae09d71
@ -19,6 +19,7 @@ import (
|
||||
"github.com/rxdn/gdl/rest"
|
||||
"github.com/rxdn/gdl/rest/request"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -37,6 +38,8 @@ type panelBody struct {
|
||||
Mentions []string `json:"mentions"`
|
||||
WithDefaultTeam bool `json:"default_team"`
|
||||
Teams []database.SupportTeam `json:"teams"`
|
||||
ImageUrl *string `json:"image_url,omitempty"`
|
||||
ThumbnailUrl *string `json:"thumbnail_url,omitempty"`
|
||||
}
|
||||
|
||||
func CreatePanel(ctx *gin.Context) {
|
||||
@ -91,7 +94,7 @@ func CreatePanel(ctx *gin.Context) {
|
||||
customId := utils.RandString(80)
|
||||
|
||||
emoji, _ := data.getEmoji() // already validated
|
||||
msgId, err := data.sendEmbed(&botContext, data.Title, customId, emoji, premiumTier > premium.None)
|
||||
msgId, err := data.sendEmbed(&botContext, data.Title, customId, emoji, data.ImageUrl, data.ThumbnailUrl, premiumTier > premium.None)
|
||||
if err != nil {
|
||||
var unwrapped request.RestError
|
||||
if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 {
|
||||
@ -123,6 +126,8 @@ func CreatePanel(ctx *gin.Context) {
|
||||
WelcomeMessage: data.WelcomeMessage,
|
||||
WithDefaultTeam: data.WithDefaultTeam,
|
||||
CustomId: customId,
|
||||
ImageUrl: data.ImageUrl,
|
||||
ThumbnailUrl: data.ThumbnailUrl,
|
||||
}
|
||||
|
||||
panelId, err := dbclient.Client.Panel.Create(panel)
|
||||
@ -202,6 +207,8 @@ func insertTeams(guildId uint64, panelId int, teams []database.SupportTeam) (int
|
||||
return 500, group.Wait()
|
||||
}
|
||||
|
||||
var urlRegex = regexp.MustCompile(`^https?://([-a-zA-Z0-9@:%._+~#=]{1,256})\.[a-zA-Z0-9()]{1,63}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$`)
|
||||
|
||||
func (p *panelBody) doValidations(ctx *gin.Context, guildId uint64) bool {
|
||||
if !p.verifyTitle() {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
@ -254,6 +261,14 @@ func (p *panelBody) doValidations(ctx *gin.Context, guildId uint64) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if !p.verifyImageUrl() || !p.verifyThumbnailUrl() {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "Image URL must be between 1 - 255 characters and a valid URL",
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@ -312,12 +327,36 @@ func (p *panelBody) verifyWelcomeMessage() bool {
|
||||
return p.WelcomeMessage == nil || (len(*p.WelcomeMessage) > 0 && len(*p.WelcomeMessage) < 1025)
|
||||
}
|
||||
|
||||
func (p *panelBody) sendEmbed(ctx *botcontext.BotContext, title, customId, emote string, isPremium bool) (uint64, error) {
|
||||
func (p *panelBody) verifyImageUrl() bool {
|
||||
if p.ImageUrl != nil && len(*p.ImageUrl) == 0 {
|
||||
p.ImageUrl = nil
|
||||
}
|
||||
|
||||
return p.ImageUrl == nil || (len(*p.ImageUrl) <= 255 && urlRegex.MatchString(*p.ImageUrl))
|
||||
}
|
||||
|
||||
func (p *panelBody) verifyThumbnailUrl() bool {
|
||||
if p.ThumbnailUrl != nil && len(*p.ThumbnailUrl) == 0 {
|
||||
p.ThumbnailUrl = nil
|
||||
}
|
||||
|
||||
return p.ThumbnailUrl == nil || (len(*p.ThumbnailUrl) <= 255 && urlRegex.MatchString(*p.ThumbnailUrl))
|
||||
}
|
||||
|
||||
func (p *panelBody) sendEmbed(ctx *botcontext.BotContext, title, customId, emote string, imageUrl, thumbnailUrl *string, isPremium bool) (uint64, error) {
|
||||
e := embed.NewEmbed().
|
||||
SetTitle(p.Title).
|
||||
SetDescription(p.Content).
|
||||
SetColor(int(p.Colour))
|
||||
|
||||
if imageUrl != nil {
|
||||
e.SetImage(*imageUrl)
|
||||
}
|
||||
|
||||
if thumbnailUrl != nil {
|
||||
e.SetThumbnail(*thumbnailUrl)
|
||||
}
|
||||
|
||||
if !isPremium {
|
||||
// TODO: Don't harcode
|
||||
e.SetFooter("Powered by ticketsbot.net", "https://cdn.discordapp.com/avatars/508391840525975553/ac2647ffd4025009e2aa852f719a8027.png?size=256")
|
||||
|
@ -11,16 +11,8 @@ import (
|
||||
|
||||
func ListPanels(ctx *gin.Context) {
|
||||
type panelResponse struct {
|
||||
PanelId int `json:"panel_id"`
|
||||
ChannelId uint64 `json:"channel_id,string"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Colour uint32 `json:"colour"`
|
||||
CategoryId uint64 `json:"category_id,string"`
|
||||
Emote string `json:"emote"`
|
||||
WelcomeMessage *string `json:"welcome_message"`
|
||||
database.Panel
|
||||
Mentions []string `json:"mentions"`
|
||||
WithDefaultTeam bool `json:"default_team"`
|
||||
Teams []database.SupportTeam `json:"teams"`
|
||||
}
|
||||
|
||||
@ -74,16 +66,8 @@ func ListPanels(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
wrapped[i] = panelResponse{
|
||||
PanelId: p.PanelId,
|
||||
ChannelId: p.ChannelId,
|
||||
Title: p.Title,
|
||||
Content: p.Content,
|
||||
Colour: uint32(p.Colour),
|
||||
CategoryId: p.TargetCategory,
|
||||
Emote: p.ReactionEmote,
|
||||
WelcomeMessage: p.WelcomeMessage,
|
||||
Panel: p,
|
||||
Mentions: mentions,
|
||||
WithDefaultTeam: p.WithDefaultTeam,
|
||||
Teams: teams,
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,9 @@ func UpdatePanel(ctx *gin.Context) {
|
||||
existing.ChannelId != data.ChannelId ||
|
||||
existing.Content != data.Content ||
|
||||
existing.Title != data.Title ||
|
||||
existing.ReactionEmote != data.Emote
|
||||
existing.ReactionEmote != data.Emote ||
|
||||
existing.ImageUrl != data.ImageUrl ||
|
||||
existing.ThumbnailUrl != data.ThumbnailUrl
|
||||
|
||||
emoji, _ := data.getEmoji() // already validated
|
||||
newMessageId := existing.MessageId
|
||||
@ -113,7 +115,7 @@ func UpdatePanel(ctx *gin.Context) {
|
||||
// delete old message, ignoring error
|
||||
_ = rest.DeleteMessage(botContext.Token, botContext.RateLimiter, existing.ChannelId, existing.MessageId)
|
||||
|
||||
newMessageId, err = data.sendEmbed(&botContext, existing.Title, existing.CustomId, existing.ReactionEmote, premiumTier > premium.None)
|
||||
newMessageId, err = data.sendEmbed(&botContext, data.Title, existing.CustomId, data.Emote, data.ImageUrl, data.ThumbnailUrl, premiumTier > premium.None)
|
||||
if err != nil {
|
||||
var unwrapped request.RestError
|
||||
if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 {
|
||||
|
@ -43,6 +43,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<Input col2={true} label="Large Image URL" bind:value={data.image_url} />
|
||||
<Input col2={true} label="Small Image URL" bind:value={data.thumbnail_url} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@ -237,7 +241,7 @@
|
||||
|
||||
.advanced-settings-show {
|
||||
visibility: visible;
|
||||
min-height: 250px;
|
||||
min-height: 297px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
export const API_URL = env.API_URL || "http://172.26.50.75:3000"
|
||||
export const API_URL = env.API_URL || "http://172.24.138.236:3000"
|
||||
export const PLACEHOLDER_DOCS_URL = "https://docs.ticketsbot.net/setup/placeholders.html"
|
||||
|
||||
export const OAUTH = {
|
||||
|
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb
|
||||
github.com/TicketsBot/common v0.0.0-20210604175952-03cfa14c16e1
|
||||
github.com/TicketsBot/database v0.0.0-20210625163257-35eea2daa97c
|
||||
github.com/TicketsBot/database v0.0.0-20210630165045-4745a3db99e1
|
||||
github.com/TicketsBot/worker v0.0.0-20210528135955-34744f610804
|
||||
github.com/apex/log v1.1.2
|
||||
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
|
||||
|
Loading…
x
Reference in New Issue
Block a user