force modmail server
This commit is contained in:
parent
e6d5a05eea
commit
495a6c5ac2
@ -22,7 +22,7 @@ func WhitelabelGet(ctx *gin.Context) {
|
||||
if bot.BotId == 0 {
|
||||
ctx.JSON(404, gin.H{
|
||||
"success": false,
|
||||
"error": "No bot found",
|
||||
"error": "No bot found",
|
||||
})
|
||||
} else {
|
||||
// Get status
|
||||
@ -35,8 +35,8 @@ func WhitelabelGet(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Get errors
|
||||
errors, err := database.Client.WhitelabelErrors.GetRecent(bot.UserId, 10)
|
||||
// Get forced modmail guild
|
||||
forcedGuild, err := database.Client.ModmailForcedGuilds.Get(bot.BotId)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{
|
||||
"success": false,
|
||||
@ -46,10 +46,10 @@ func WhitelabelGet(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
ctx.JSON(200, gin.H{
|
||||
"success": true,
|
||||
"id": strconv.FormatUint(bot.BotId, 10),
|
||||
"status": status,
|
||||
"errors": errors,
|
||||
"success": true,
|
||||
"id": strconv.FormatUint(bot.BotId, 10),
|
||||
"status": status,
|
||||
"modmail_forced_guild": strconv.FormatUint(forcedGuild, 10),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
52
app/http/endpoints/api/whitelabelgetguilds.go
Normal file
52
app/http/endpoints/api/whitelabelgetguilds.go
Normal file
@ -0,0 +1,52 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/TicketsBot/GoPanel/database"
|
||||
"github.com/TicketsBot/GoPanel/rpc/cache"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func WhitelabelGetGuilds(ctx *gin.Context) {
|
||||
userId := ctx.Keys["userid"].(uint64)
|
||||
|
||||
bot, err := database.Client.Whitelabel.GetByUserId(userId)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// id -> name
|
||||
guilds := make(map[string]string, 0)
|
||||
if bot.BotId == 0 {
|
||||
ctx.JSON(404, gin.H{
|
||||
"success": false,
|
||||
"guilds": guilds,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ids, err := database.Client.WhitelabelGuilds.GetGuilds(bot.BotId)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
for _, id := range ids {
|
||||
// get guild name
|
||||
if guild, found := cache.Instance.GetGuild(id, false); found {
|
||||
guilds[strconv.FormatUint(id, 10)] = guild.Name
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSON(200, gin.H{
|
||||
"success": true,
|
||||
"guilds": guilds,
|
||||
})
|
||||
}
|
110
app/http/endpoints/api/whitelabelpostmodmail.go
Normal file
110
app/http/endpoints/api/whitelabelpostmodmail.go
Normal file
@ -0,0 +1,110 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/TicketsBot/GoPanel/database"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func WhitelabelModmailPost(ctx *gin.Context) {
|
||||
userId := ctx.Keys["userid"].(uint64)
|
||||
|
||||
// Get bot
|
||||
bot, err := database.Client.Whitelabel.GetByUserId(userId)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure bot exists
|
||||
if bot.BotId == 0 {
|
||||
ctx.JSON(404, gin.H{
|
||||
"success": false,
|
||||
"error": "No bot found",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Parse status
|
||||
var guildId uint64
|
||||
{
|
||||
var data map[string]string
|
||||
if err := ctx.BindJSON(&data); err != nil {
|
||||
ctx.JSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "No guild ID provided",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
guildIdStr, ok := data["guild"]
|
||||
if !ok {
|
||||
ctx.JSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "No guild ID provided",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
guildId, err = strconv.ParseUint(guildIdStr, 10, 64)
|
||||
if err != nil {
|
||||
ctx.JSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "Invalid guild ID provided",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if guildId == 0 {
|
||||
if err := database.Client.ModmailForcedGuilds.Delete(bot.BotId); err != nil {
|
||||
ctx.JSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// verify that the bot is in the specified guild
|
||||
guilds, err := database.Client.WhitelabelGuilds.GetGuilds(bot.BotId)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var found bool
|
||||
for _, botGuild := range guilds {
|
||||
if botGuild == guildId {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
ctx.JSON(400, gin.H{
|
||||
"success": false,
|
||||
"error": "The bot isn't in the guild your provided",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if err := database.Client.ModmailForcedGuilds.Set(bot.BotId, guildId); err != nil {
|
||||
ctx.JSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, gin.H{
|
||||
"success": true,
|
||||
"bot": bot,
|
||||
})
|
||||
}
|
@ -119,6 +119,8 @@ func StartServer() {
|
||||
|
||||
whitelabelGroup.GET("/", api.WhitelabelGet)
|
||||
whitelabelApiGroup.GET("/errors", api.WhitelabelGetErrors)
|
||||
whitelabelApiGroup.GET("/guilds", api.WhitelabelGetGuilds)
|
||||
whitelabelApiGroup.POST("/modmail", api.WhitelabelModmailPost)
|
||||
|
||||
whitelabelApiGroup.Group("/").Use(createLimiter(10, time.Minute)).POST("/", api.WhitelabelPost)
|
||||
whitelabelApiGroup.Group("/").Use(createLimiter(1, time.Second * 5)).POST("/status", api.WhitelabelStatusPost)
|
||||
|
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-20200612180221-a26ff96874ea
|
||||
github.com/TicketsBot/database v0.0.0-20200613162408-5b3847cebd07
|
||||
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
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="content">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Bot Token</h4>
|
||||
@ -20,13 +20,13 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 ">
|
||||
<div class="col-md-12">
|
||||
<p class="white">Note: You will not be able to view the token after submitting it</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-1">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-fill" type="submit">
|
||||
<i class="fas fa-paper-plane"></i>
|
||||
@ -34,7 +34,7 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="col-md-4">
|
||||
<button class="btn btn-primary btn-fill" id="invite" type="button">
|
||||
<i class="fas fa-plus"></i>
|
||||
Generate Invite Link
|
||||
@ -45,6 +45,39 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Modmail</h4>
|
||||
</div>
|
||||
<div class="card-body" id="card">
|
||||
<form onsubmit="updateForcedModmail(); return false;">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label>Server</label>
|
||||
<select class="form-control" id="forced_modmail">
|
||||
<option value="0">Allow user to select</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-fill" type="submit">
|
||||
<i class="fas fa-paper-plane"></i>
|
||||
Submit
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@ -66,7 +99,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary btn-fill" type="submit">
|
||||
<i class="fas fa-paper-plane"></i>
|
||||
@ -137,6 +170,21 @@
|
||||
showToast('Success', `Started tickets whitelabel on ${res.data.bot.username}#${res.data.bot.discriminator}`);
|
||||
}
|
||||
|
||||
async function updateForcedModmail() {
|
||||
const select = document.getElementById('forced_modmail');
|
||||
const data = {
|
||||
guild: select.options[select.selectedIndex].value
|
||||
};
|
||||
|
||||
const res = await axios.post('/user/whitelabel/modmail', data);
|
||||
if (res.status !== 200 || !res.data.success) {
|
||||
showToast('Error', res.data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
showToast('Success', 'Updated modmail settings successfully')
|
||||
}
|
||||
|
||||
async function updateStatus() {
|
||||
const data = {
|
||||
status: document.getElementById('status').value
|
||||
@ -154,7 +202,9 @@
|
||||
async function loadStatus() {
|
||||
const res = await axios.get('/user/whitelabel');
|
||||
if (res.status !== 200 || !res.data.success) {
|
||||
showToast('Error', res.data.error);
|
||||
if (res.status !== 404) {
|
||||
showToast('Error', res.data.error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -180,5 +230,41 @@
|
||||
}
|
||||
|
||||
loadErrors();
|
||||
|
||||
async function loadGuilds() {
|
||||
// get selected guild
|
||||
const settingsRes = await axios.get('/user/whitelabel');
|
||||
if (settingsRes.status !== 200 || !settingsRes.data.success) {
|
||||
showToast('Error', settingsRes.data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
const guildId = settingsRes.data.modmail_forced_guild;
|
||||
|
||||
// get guild list
|
||||
const guildsRes = await axios.get('/user/whitelabel/guilds');
|
||||
if (guildsRes.status !== 200 || !guildsRes.data.success) {
|
||||
if (guildsRes.status !== 404) {
|
||||
showToast('Error', guildsRes.data.error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// append guilds to dropdown
|
||||
const select = document.getElementById('forced_modmail');
|
||||
for (let [id, name] of Object.entries(guildsRes.data.guilds)) {
|
||||
const option = document.createElement('option');
|
||||
option.value = id;
|
||||
option.text = name;
|
||||
|
||||
if (id === guildId) {
|
||||
option.selected = true;
|
||||
}
|
||||
|
||||
select.add(option);
|
||||
}
|
||||
}
|
||||
|
||||
loadGuilds();
|
||||
</script>
|
||||
{{end}}
|
Loading…
x
Reference in New Issue
Block a user