welcome message per panel
This commit is contained in:
parent
495a6c5ac2
commit
0288628629
@ -25,7 +25,7 @@ func CreatePanel(ctx *gin.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.AbortWithStatusJSON(500, gin.H{
|
ctx.AbortWithStatusJSON(500, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -114,6 +114,7 @@ func CreatePanel(ctx *gin.Context) {
|
|||||||
Colour: int32(data.Colour),
|
Colour: int32(data.Colour),
|
||||||
TargetCategory: data.CategoryId,
|
TargetCategory: data.CategoryId,
|
||||||
ReactionEmote: emoji,
|
ReactionEmote: emoji,
|
||||||
|
WelcomeMessage: data.WelcomeMessage,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = dbclient.Client.Panel.Create(panel); err != nil {
|
if err = dbclient.Client.Panel.Create(panel); err != nil {
|
||||||
@ -125,7 +126,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),
|
"message_id": strconv.FormatUint(msgId, 10),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -174,6 +175,14 @@ func (p *panel) doValidations(ctx *gin.Context, guildId uint64) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !p.verifyWelcomeMessage() {
|
||||||
|
ctx.AbortWithStatusJSON(400, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"error": "Welcome message must be null or between 1 - 1024 characters",
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +225,10 @@ func (p *panel) verifyCategory(channels []channel.Channel) bool {
|
|||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *panel) verifyWelcomeMessage() bool {
|
||||||
|
return p.WelcomeMessage == nil || (len(*p.WelcomeMessage) > 0 && len(*p.WelcomeMessage) < 1025)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *panel) sendEmbed(ctx *botcontext.BotContext, isPremium bool) (messageId uint64, err error) {
|
func (p *panel) sendEmbed(ctx *botcontext.BotContext, isPremium bool) (messageId uint64, err error) {
|
||||||
e := embed.NewEmbed().
|
e := embed.NewEmbed().
|
||||||
SetTitle(p.Title).
|
SetTitle(p.Title).
|
||||||
|
@ -6,13 +6,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type panel struct {
|
type panel struct {
|
||||||
ChannelId uint64 `json:"channel_id,string"`
|
ChannelId uint64 `json:"channel_id,string"`
|
||||||
MessageId uint64 `json:"message_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"`
|
||||||
CategoryId uint64 `json:"category_id,string"`
|
CategoryId uint64 `json:"category_id,string"`
|
||||||
Emote string `json:"emote"`
|
Emote string `json:"emote"`
|
||||||
|
WelcomeMessage *string `json:"welcome_message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListPanels(ctx *gin.Context) {
|
func ListPanels(ctx *gin.Context) {
|
||||||
@ -22,7 +23,7 @@ func ListPanels(ctx *gin.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.AbortWithStatusJSON(500, gin.H{
|
ctx.AbortWithStatusJSON(500, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -31,13 +32,14 @@ func ListPanels(ctx *gin.Context) {
|
|||||||
|
|
||||||
for i, p := range panels {
|
for i, p := range panels {
|
||||||
wrapped[i] = panel{
|
wrapped[i] = panel{
|
||||||
ChannelId: p.ChannelId,
|
ChannelId: p.ChannelId,
|
||||||
MessageId: p.MessageId,
|
MessageId: p.MessageId,
|
||||||
Title: p.Title,
|
Title: p.Title,
|
||||||
Content: p.Content,
|
Content: p.Content,
|
||||||
Colour: uint32(p.Colour),
|
Colour: uint32(p.Colour),
|
||||||
CategoryId: p.TargetCategory,
|
CategoryId: p.TargetCategory,
|
||||||
Emote: p.ReactionEmote,
|
Emote: p.ReactionEmote,
|
||||||
|
WelcomeMessage: p.WelcomeMessage,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@ -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-20200425115930-0ca198cc8306
|
github.com/TicketsBot/archiverclient v0.0.0-20200425115930-0ca198cc8306
|
||||||
github.com/TicketsBot/common v0.0.0-20200529141045-7426ad13f1a4
|
github.com/TicketsBot/common v0.0.0-20200529141045-7426ad13f1a4
|
||||||
github.com/TicketsBot/database v0.0.0-20200613162408-5b3847cebd07
|
github.com/TicketsBot/database v0.0.0-20200614182426-d117a0e3f769
|
||||||
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
|
||||||
|
@ -85,9 +85,30 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4 pr-1 offset-md-4">
|
||||||
|
<div class="text-center">
|
||||||
|
<button class="btn btn-primary btn-fill" type="button" data-toggle="collapse" data-target="#advanced" aria-expanded="false" aria-controls="advanced">
|
||||||
|
Expand advanced settings
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="collapse" id="advanced" style="width: 100%">
|
||||||
|
<div class="col-md-6 pr-1">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="black">Welcome Message</label>
|
||||||
|
<textarea type="text" class="form-control" placeholder="If not provided, your server's default welcome message will be used" id="welcome_message"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-2 pr-1 offset-md-5">
|
<div class="col-md-2 pr-1 offset-md-5">
|
||||||
<div class="form-group">
|
<div class="form-group text-center">
|
||||||
<button type="submit" class="btn btn-primary btn-fill"><i class="fas fa-paper-plane"></i> Submit</button>
|
<button type="submit" class="btn btn-primary btn-fill"><i class="fas fa-paper-plane"></i> Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -133,26 +154,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createPanel() {
|
async function createPanel() {
|
||||||
|
const title = document.getElementById('title').value;
|
||||||
|
const content = document.getElementById('content').value;
|
||||||
|
const emote = document.getElementById('reaction').value.replace(':', '');
|
||||||
|
const welcomeMessage = document.getElementById('welcome_message').value;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
title: document.getElementById('title').value,
|
title: title === '' ? 'Open a ticket!' : title,
|
||||||
content: document.getElementById('content').value,
|
content: content === '' ? 'By reacting to this ticket, a message will be opened for you.' : content,
|
||||||
emote: document.getElementById('reaction').value.replace(':', ''),
|
emote: emote === '' ? 'envelope_with_arrow' : emote,
|
||||||
colour: parseInt(`0x${document.getElementById('colour').value.slice(1)}`),
|
colour: parseInt(`0x${document.getElementById('colour').value.slice(1)}`),
|
||||||
channel_id: document.getElementById('channel-container').options[document.getElementById('channel-container').selectedIndex].value,
|
channel_id: document.getElementById('channel-container').options[document.getElementById('channel-container').selectedIndex].value,
|
||||||
category_id: document.getElementById('category-container').options[document.getElementById('category-container').selectedIndex].value,
|
category_id: document.getElementById('category-container').options[document.getElementById('category-container').selectedIndex].value,
|
||||||
|
welcome_message: welcomeMessage === '' ? null : welcomeMessage
|
||||||
};
|
};
|
||||||
|
|
||||||
// fill defaults
|
|
||||||
if (data.title === '') {
|
|
||||||
data.title = 'Open a ticket!';
|
|
||||||
}
|
|
||||||
if (data.content === '') {
|
|
||||||
data.content = 'By reacting to this ticket, a ticket will be opened for you.';
|
|
||||||
}
|
|
||||||
if (data.emote === '') {
|
|
||||||
data.emote = 'envelope_with_arrow';
|
|
||||||
}
|
|
||||||
|
|
||||||
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.message_id = res.data.message_id;
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-2 px-1">
|
<div class="col-md-3 px-1">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Ping @everyone on ticket open</label>
|
<label>Ping @everyone on ticket open</label>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
|
@ -112,6 +112,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
@ -121,7 +122,8 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Error</th>
|
<th scope="col" span="2">Error</th>
|
||||||
|
<th scope="col">Date</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="error_body">
|
<tbody id="error_body">
|
||||||
@ -223,8 +225,12 @@
|
|||||||
|
|
||||||
// append errors
|
// append errors
|
||||||
for (error of res.data.errors) {
|
for (error of res.data.errors) {
|
||||||
|
const message = error.Message;
|
||||||
|
const time = new Date(error.Time);
|
||||||
|
|
||||||
const tr = document.createElement('tr');
|
const tr = document.createElement('tr');
|
||||||
appendTd(tr, error);
|
appendTd(tr, message);
|
||||||
|
appendTd(tr, time.toDateString());
|
||||||
document.getElementById('error_body').appendChild(tr);
|
document.getElementById('error_body').appendChild(tr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user