ticket naming scheme
This commit is contained in:
parent
6fe3867434
commit
323a378315
@ -56,6 +56,10 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
archiveChannel := table.GetArchiveChannel(guildId)
|
archiveChannel := table.GetArchiveChannel(guildId)
|
||||||
categoryId := table.GetChannelCategory(guildId)
|
categoryId := table.GetChannelCategory(guildId)
|
||||||
|
|
||||||
|
namingSchemeChan := make(chan table.NamingScheme)
|
||||||
|
go table.GetTicketNamingScheme(guildId, namingSchemeChan)
|
||||||
|
namingScheme := <-namingSchemeChan
|
||||||
|
|
||||||
// /users/@me/guilds doesn't return channels, so we have to get them for the specific guild
|
// /users/@me/guilds doesn't return channels, so we have to get them for the specific guild
|
||||||
channelsChan := make(chan []table.Channel)
|
channelsChan := make(chan []table.Channel)
|
||||||
go table.GetCachedChannelsByGuild(guildId, channelsChan)
|
go table.GetCachedChannelsByGuild(guildId, channelsChan)
|
||||||
@ -104,6 +108,7 @@ func SettingsHandler(ctx *gin.Context) {
|
|||||||
"panelcontent": panelSettings.Content,
|
"panelcontent": panelSettings.Content,
|
||||||
"panelcolour": strconv.FormatInt(int64(panelSettings.Colour), 16),
|
"panelcolour": strconv.FormatInt(int64(panelSettings.Colour), 16),
|
||||||
"usersCanClose": usersCanClose,
|
"usersCanClose": usersCanClose,
|
||||||
|
"namingScheme": string(namingScheme),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ctx.Redirect(302, "/login")
|
ctx.Redirect(302, "/login")
|
||||||
|
@ -125,31 +125,24 @@ func UpdateSettingsHandler(ctx *gin.Context) {
|
|||||||
table.UpdateArchiveChannel(guildId, parsed)
|
table.UpdateArchiveChannel(guildId, parsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get panel title
|
|
||||||
panelTitle := ctx.PostForm("paneltitle")
|
|
||||||
if panelTitle != "" && len(panelTitle) <= 255 {
|
|
||||||
table.UpdatePanelTitle(guildId, panelTitle)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get panel content
|
|
||||||
panelContent := ctx.PostForm("panelcontent")
|
|
||||||
if panelContent != "" || len(panelContent) <= 2048 {
|
|
||||||
table.UpdatePanelContent(guildId, panelContent)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get panel colour
|
|
||||||
panelColourHex := ctx.PostForm("panelcolour")
|
|
||||||
if panelColourHex != "" {
|
|
||||||
panelColour, err := strconv.ParseUint(panelColourHex, 16, 32)
|
|
||||||
if err == nil {
|
|
||||||
table.UpdatePanelColour(guildId, int(panelColour))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Users can close
|
// Users can close
|
||||||
usersCanClose := ctx.PostForm("userscanclose") == "on"
|
usersCanClose := ctx.PostForm("userscanclose") == "on"
|
||||||
table.SetUserCanClose(guildId, usersCanClose)
|
table.SetUserCanClose(guildId, usersCanClose)
|
||||||
|
|
||||||
|
// Get naming scheme
|
||||||
|
namingScheme := table.NamingScheme(ctx.PostForm("namingscheme"))
|
||||||
|
isValidScheme := false
|
||||||
|
for _, validNamingScheme := range table.Schemes {
|
||||||
|
if validNamingScheme == namingScheme {
|
||||||
|
isValidScheme = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if isValidScheme {
|
||||||
|
go table.SetTicketNamingScheme(guildId, namingScheme)
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Redirect(302, fmt.Sprintf("/manage/%d/settings?validPrefix=%t&validWelcomeMessage=%t&validTicketLimit=%t", guildId, prefixValid, welcomeMessageValid, ticketLimitValid))
|
ctx.Redirect(302, fmt.Sprintf("/manage/%d/settings?validPrefix=%t&validWelcomeMessage=%t&validTicketLimit=%t", guildId, prefixValid, welcomeMessageValid, ticketLimitValid))
|
||||||
} else {
|
} else {
|
||||||
ctx.Redirect(302, "/login")
|
ctx.Redirect(302, "/login")
|
||||||
|
37
database/table/namingscheme.go
Normal file
37
database/table/namingscheme.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package table
|
||||||
|
|
||||||
|
import "github.com/TicketsBot/GoPanel/database"
|
||||||
|
|
||||||
|
type TicketNamingScheme struct {
|
||||||
|
Guild int64 `gorm:"column:GUILDID;unique;primary_key"`
|
||||||
|
NamingScheme string `gorm:"column:NAMINGSCHEME;type:VARCHAR(16)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type NamingScheme string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Id NamingScheme = "id"
|
||||||
|
Username NamingScheme = "username"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Schemes = []NamingScheme{Id, Username}
|
||||||
|
|
||||||
|
func (TicketNamingScheme) TableName() string {
|
||||||
|
return "TicketNamingScheme"
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTicketNamingScheme(guild int64, ch chan NamingScheme) {
|
||||||
|
var node TicketNamingScheme
|
||||||
|
database.Database.Where(TicketNamingScheme{Guild: guild}).First(&node)
|
||||||
|
namingScheme := node.NamingScheme
|
||||||
|
|
||||||
|
if namingScheme == "" {
|
||||||
|
ch <- Id
|
||||||
|
} else {
|
||||||
|
ch <- NamingScheme(namingScheme)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetTicketNamingScheme(guild int64, scheme NamingScheme) {
|
||||||
|
database.Database.Where(&TicketNamingScheme{Guild: guild}).Assign(&TicketNamingScheme{NamingScheme: string(scheme)}).FirstOrCreate(&TicketNamingScheme{})
|
||||||
|
}
|
@ -78,31 +78,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<label>Ticket Naming Scheme</label>
|
||||||
<h4>Default Panel Settings</h4>
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="namingscheme" id="naming-by-id" value="id" {{if eq .namingScheme "id"}}checked{{end}}>
|
||||||
|
<label class="form-check-label" for="naming-by-id">
|
||||||
|
Ticket ID
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
<div class="row">
|
<input class="form-check-input" type="radio" name="namingscheme" id="naming-by-username" value="username" {{if eq .namingScheme "username"}}checked{{end}}>
|
||||||
|
<label class="form-check-label" for="naming-by-username">
|
||||||
<div class="col-md-3 pr-1">
|
Username
|
||||||
<label>Panel Title</label>
|
</label>
|
||||||
<input name="paneltitle" type="text" class="form-control" placeholder="Open A Ticket" value="{{.paneltitle}}">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-6 pr-1">
|
|
||||||
<label>Panel Content</label>
|
|
||||||
<input name="panelcontent" type="text" class="form-control" placeholder="React with :envelope_with_arrow: to open a ticket" value="{{.panelcontent}}">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-3 pr-1">
|
|
||||||
<label>Panel Colour (Hex)</label>
|
|
||||||
<div class="input-group mb-3">
|
|
||||||
<div class="input-group-prepend">
|
|
||||||
<div class="input-group-text">#</div>
|
|
||||||
</div>
|
|
||||||
<input name="panelcolour" type="text" class="form-control" placeholder="23A31A" value="{{.panelcolour}}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input name="csrf" type="hidden" value="{{.csrf}}">
|
<input name="csrf" type="hidden" value="{{.csrf}}">
|
||||||
@ -157,7 +144,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="toast-body">
|
<div class="toast-body">
|
||||||
The ticketLimit you specified was invalid
|
The ticket limit you specified was invalid
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user