custom status

This commit is contained in:
Dot-Rar 2020-05-29 15:26:47 +01:00
parent 83193f934e
commit bdaae58c71
5 changed files with 173 additions and 5 deletions

View File

@ -25,9 +25,20 @@ func WhitelabelGet(ctx *gin.Context) {
"error": "No bot found",
})
} else {
// Get status
status, err := database.Client.WhitelabelStatuses.Get(bot.BotId)
if err != nil {
ctx.JSON(500, gin.H{
"success": false,
"error": err.Error(),
})
return
}
ctx.JSON(200, gin.H{
"success": true,
"id": strconv.FormatUint(bot.BotId, 10),
"status": status,
})
}
}

View File

@ -0,0 +1,99 @@
package api
import (
"github.com/TicketsBot/GoPanel/config"
"github.com/TicketsBot/GoPanel/database"
"github.com/TicketsBot/GoPanel/messagequeue"
"github.com/TicketsBot/GoPanel/rpc"
"github.com/TicketsBot/common/premium"
"github.com/TicketsBot/common/statusupdates"
"github.com/gin-gonic/gin"
)
func WhitelabelStatusPost(ctx *gin.Context) {
userId := ctx.Keys["userid"].(uint64)
premiumTier := rpc.PremiumClient.GetTierByUser(userId, false)
if premiumTier < premium.Whitelabel {
var isForced bool
for _, forced := range config.Conf.ForceWhitelabel {
if forced == userId {
isForced = true
break
}
}
if !isForced {
ctx.JSON(402, gin.H{
"success": false,
"error": "You must have the whitelabel premium tier",
})
return
}
}
// 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 status string
{
var data map[string]string
if err := ctx.BindJSON(&data); err != nil {
ctx.JSON(400, gin.H{
"success": false,
"error": "No status provided",
})
return
}
var ok bool
status, ok = data["status"]
if !ok {
ctx.JSON(400, gin.H{
"success": false,
"error": "No status provided",
})
return
}
if len(status) == 0 || len(status) > 255 {
ctx.JSON(400, gin.H{
"success": false,
"error": "Status must be between 1-255 characters in length",
})
return
}
}
if err := database.Client.WhitelabelStatuses.Set(bot.BotId, status); err != nil {
ctx.JSON(500, gin.H{
"success": false,
"error": err.Error(),
})
return
}
go statusupdates.Publish(messagequeue.Client.Client, bot.BotId)
ctx.JSON(200, gin.H{
"success": true,
"bot": bot,
})
}

View File

@ -112,6 +112,7 @@ func StartServer() {
userGroup.GET("/whitelabel", api.WhitelabelGet)
userGroup.POST("/whitelabel", api.WhitelabelPost)
userGroup.POST("/whitelabel/status", api.WhitelabelStatusPost)
}
if err := router.Run(config.Conf.Server.Host); err != nil {

4
go.mod
View File

@ -5,8 +5,8 @@ go 1.14
require (
github.com/BurntSushi/toml v0.3.1
github.com/TicketsBot/archiverclient v0.0.0-20200425115930-0ca198cc8306
github.com/TicketsBot/common v0.0.0-20200527174950-d8ebbcbf49c9
github.com/TicketsBot/database v0.0.0-20200527183847-2fbafde7649e
github.com/TicketsBot/common v0.0.0-20200529141045-7426ad13f1a4
github.com/TicketsBot/database v0.0.0-20200529142046-b47b53137846
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

View File

@ -5,7 +5,7 @@
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Whitelabel</h4>
<h4 class="card-title">Bot Token</h4>
</div>
<div class="card-body" id="card">
<form onsubmit="updateSettings(); return false;">
@ -46,6 +46,38 @@
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Custom Status</h4>
</div>
<div class="card-body" id="card">
<form onsubmit="updateStatus(); return false;">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Status</label>
<input name="status" type="text" class="form-control" placeholder="DM for help | t!help" id="status">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">
<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>
<div aria-live="polite" aria-atomic="true" style="position: relative">
@ -71,9 +103,8 @@
<script>
async function updateSettings() {
const token = document.getElementById('token').value;
const data = {
token: token
token: document.getElementById('token').value
};
const res = await axios.post('/user/whitelabel', data);
@ -84,6 +115,32 @@
showToast('Success', `Started tickets whitelabel on ${res.data.bot.username}#${res.data.bot.discriminator}`);
}
async function updateStatus() {
const data = {
status: document.getElementById('status').value
};
const res = await axios.post('/user/whitelabel/status', data);
if (res.status !== 200 || !res.data.success) {
showToast('Error', res.data.error);
return;
}
showToast('Success', 'Updated status successfully')
}
async function loadStatus() {
const res = await axios.get('/user/whitelabel');
if (res.status !== 200 || !res.data.success) {
showToast('Error', res.data.error);
return;
}
document.getElementById('status').value = res.data.status;
}
loadStatus();
</script>
</div>
{{end}}