ping everyone disable

This commit is contained in:
Dot-Rar 2019-05-26 17:34:08 +01:00
parent 00f6ed46cc
commit 89a8438fb8
6 changed files with 65 additions and 6 deletions

View File

@ -93,6 +93,14 @@ func SettingsHandler(ctx *gin.Context) {
table.UpdateTicketLimit(guildId, limit) table.UpdateTicketLimit(guildId, limit)
} }
// Ping everyone
pingEveryone := table.GetPingEveryone(guildId)
pingEveryoneStr := ctx.Query("pingeveryone")
if csrfCorrect {
pingEveryone = pingEveryoneStr == "on"
table.UpdatePingEveryone(guildId, pingEveryone)
}
// /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
if len(guild.Channels) == 0 { if len(guild.Channels) == 0 {
var channels []objects.Channel var channels []objects.Channel
@ -215,6 +223,7 @@ func SettingsHandler(ctx *gin.Context) {
"invalidWelcomeMessage": len(ctx.Query("welcomeMessage")) > 1000, "invalidWelcomeMessage": len(ctx.Query("welcomeMessage")) > 1000,
"invalidTicketLimit": invalidTicketLimit, "invalidTicketLimit": invalidTicketLimit,
"csrf": store.Get("csrf").(string), "csrf": store.Get("csrf").(string),
"pingEveryone": pingEveryone,
})) }))
} else { } else {
ctx.Redirect(302, "/login") ctx.Redirect(302, "/login")

View File

@ -1,7 +1,6 @@
package table package table
import ( import (
"fmt"
"github.com/TicketsBot/GoPanel/database" "github.com/TicketsBot/GoPanel/database"
) )
@ -15,7 +14,6 @@ func (ArchiveChannel) TableName() string {
} }
func UpdateArchiveChannel(guildId int64, channelId int64) { func UpdateArchiveChannel(guildId int64, channelId int64) {
fmt.Println(channelId)
var channel ArchiveChannel var channel ArchiveChannel
database.Database.Where(ArchiveChannel{Guild: guildId}).Assign(ArchiveChannel{Channel: channelId}).FirstOrCreate(&channel) database.Database.Where(ArchiveChannel{Guild: guildId}).Assign(ArchiveChannel{Channel: channelId}).FirstOrCreate(&channel)
} }

View File

@ -0,0 +1,37 @@
package table
import (
"github.com/TicketsBot/GoPanel/database"
)
type PingEveryone struct {
GuildId int64 `gorm:"column:GUILDID"`
PingEveryone bool `gorm:"column:PINGEVERYONE;type:TINYINT"`
}
func (PingEveryone) TableName() string {
return "pingeveryone"
}
// tldr I hate gorm
func UpdatePingEveryone(guildId int64, pingEveryone bool) {
var settings []PingEveryone
database.Database.Where(&PingEveryone{GuildId: guildId}).Find(&settings)
updated := PingEveryone{guildId, pingEveryone}
if len(settings) == 0 {
database.Database.Create(&updated)
} else {
database.Database.Table("pingeveryone").Where("GUILDID = ?", guildId).Update("PINGEVERYONE", pingEveryone)
}
//database.Database.Where(&PingEveryone{GuildId: guildId}).Assign(&updated).FirstOrCreate(&PingEveryone{})
}
func GetPingEveryone(guildId int64) bool {
pingEveryone := PingEveryone{PingEveryone: true}
database.Database.Where(&PingEveryone{GuildId: guildId}).First(&pingEveryone)
return pingEveryone.PingEveryone
}

View File

@ -8,6 +8,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Management panel for the Discord Tickets bot"> <meta name="description" content="Management panel for the Discord Tickets bot">
<link rel="shortcut icon" href="/assets/img/favicon.ico" type="image/x-icon">
<link rel="icon" href="/assets/img/favicon.ico" type="image/x-icon">
<!-- Custom CSS --> <!-- Custom CSS -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
<style> <style>

View File

@ -8,6 +8,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Management panel for the Discord Tickets bot"> <meta name="description" content="Management panel for the Discord Tickets bot">
<link rel="shortcut icon" href="/assets/img/favicon.ico" type="image/x-icon">
<link rel="icon" href="/assets/img/favicon.ico" type="image/x-icon">
<!-- Custom CSS --> <!-- Custom CSS -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
<style> <style>

View File

@ -12,18 +12,26 @@
<div class="card-body"> <div class="card-body">
<form> <form>
<div class="row"> <div class="row">
<div class="col-md-6 pr-1"> <div class="col-md-5 pr-1">
<div class="form-group"> <div class="form-group">
<label>Prefix (Max len. 8)</label> <label>Prefix (Max len. 8)</label>
<input name="prefix" type="text" class="form-control" placeholder="t!" value="{{prefix}}"> <input name="prefix" type="text" class="form-control" placeholder="t!" value="{{prefix}}">
</div> </div>
</div> </div>
<div class="col-md-6 px-1"> <div class="col-md-5 px-1">
<div class="form-group"> <div class="form-group">
<label>Ticket Limit (1-10)</label> <label>Ticket Limit (1-10)</label>
<input name="ticketlimit" type="text" class="form-control" placeholder="5" value="{{ticketLimit}}"> <input name="ticketlimit" type="text" class="form-control" placeholder="5" value="{{ticketLimit}}">
</div> </div>
</div> </div>
<div class="col-md-2 px-1">
<div class="form-group">
<label>Ping @everyone on ticket open</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="pingeveryone" value="on" {{#pingEveryone}}checked{{/pingEveryone}} style="width:30px;height:30px;">
</div>
</div>
</div>
</div> </div>
<div class="row"> <div class="row">
@ -42,7 +50,7 @@
</div> </div>
<select class="form-control" name="archivechannel"> <select class="form-control" name="archivechannel">
{{#channels}} {{#channels}}
<option {{#active}}selected{{/active}} value="{{channelname}}">{{channelname}}</option> <option {{#active}}selected{{/active}} value="{{channelid}}">{{channelname}}</option>
{{/channels}} {{/channels}}
</select> </select>
</div> </div>
@ -120,6 +128,7 @@
</div> </div>
<script> <script>
$('.toast').toast('show') $('.toast').toast('show');
$('#pingeveryone').prop('indeterminate', {{pingEveryone}});
</script> </script>
</div> </div>