welcome message per panel
This commit is contained in:
parent
495a6c5ac2
commit
0288628629
@ -114,6 +114,7 @@ func CreatePanel(ctx *gin.Context) {
|
||||
Colour: int32(data.Colour),
|
||||
TargetCategory: data.CategoryId,
|
||||
ReactionEmote: emoji,
|
||||
WelcomeMessage: data.WelcomeMessage,
|
||||
}
|
||||
|
||||
if err = dbclient.Client.Panel.Create(panel); err != nil {
|
||||
@ -174,6 +175,14 @@ func (p *panel) doValidations(ctx *gin.Context, guildId uint64) bool {
|
||||
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
|
||||
}
|
||||
|
||||
@ -216,6 +225,10 @@ func (p *panel) verifyCategory(channels []channel.Channel) bool {
|
||||
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) {
|
||||
e := embed.NewEmbed().
|
||||
SetTitle(p.Title).
|
||||
|
@ -13,6 +13,7 @@ type panel struct {
|
||||
Colour uint32 `json:"colour"`
|
||||
CategoryId uint64 `json:"category_id,string"`
|
||||
Emote string `json:"emote"`
|
||||
WelcomeMessage *string `json:"welcome_message"`
|
||||
}
|
||||
|
||||
func ListPanels(ctx *gin.Context) {
|
||||
@ -38,6 +39,7 @@ func ListPanels(ctx *gin.Context) {
|
||||
Colour: uint32(p.Colour),
|
||||
CategoryId: p.TargetCategory,
|
||||
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/TicketsBot/archiverclient v0.0.0-20200425115930-0ca198cc8306
|
||||
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/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
|
@ -86,8 +86,29 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-2 pr-1 offset-md-5">
|
||||
<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="col-md-2 pr-1 offset-md-5">
|
||||
<div class="form-group text-center">
|
||||
<button type="submit" class="btn btn-primary btn-fill"><i class="fas fa-paper-plane"></i> Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -133,26 +154,21 @@
|
||||
}
|
||||
|
||||
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 = {
|
||||
title: document.getElementById('title').value,
|
||||
content: document.getElementById('content').value,
|
||||
emote: document.getElementById('reaction').value.replace(':', ''),
|
||||
title: title === '' ? 'Open a ticket!' : title,
|
||||
content: content === '' ? 'By reacting to this ticket, a message will be opened for you.' : content,
|
||||
emote: emote === '' ? 'envelope_with_arrow' : emote,
|
||||
colour: parseInt(`0x${document.getElementById('colour').value.slice(1)}`),
|
||||
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,
|
||||
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);
|
||||
if (res.status === 200 && res.data.success) {
|
||||
data.message_id = res.data.message_id;
|
||||
|
@ -35,7 +35,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2 px-1">
|
||||
<div class="col-md-3 px-1">
|
||||
<div class="form-group">
|
||||
<label>Ping @everyone on ticket open</label>
|
||||
<div class="form-check">
|
||||
|
@ -112,6 +112,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
@ -121,7 +122,8 @@
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Error</th>
|
||||
<th scope="col" span="2">Error</th>
|
||||
<th scope="col">Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="error_body">
|
||||
@ -223,8 +225,12 @@
|
||||
|
||||
// append errors
|
||||
for (error of res.data.errors) {
|
||||
const message = error.Message;
|
||||
const time = new Date(error.Time);
|
||||
|
||||
const tr = document.createElement('tr');
|
||||
appendTd(tr, error);
|
||||
appendTd(tr, message);
|
||||
appendTd(tr, time.toDateString());
|
||||
document.getElementById('error_body').appendChild(tr);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user