This commit is contained in:
rxdn 2020-09-25 19:02:37 +01:00
parent 38ff3a7da5
commit 46cd4a9e06
8 changed files with 26 additions and 15 deletions

View File

@ -42,7 +42,7 @@ func GetGuilds(ctx *gin.Context) {
fakeGuild := guild.Guild{
Id: g.GuildId,
Owner: g.Owner,
Permissions: int(g.UserPermissions),
Permissions: uint64(g.UserPermissions),
}
if g.Owner {

View File

@ -59,7 +59,8 @@ func MultiPanelCreate(ctx *gin.Context) {
messageId, err := data.sendEmbed(&botContext, premiumTier > premium.None)
if err != nil {
if err == request.ErrForbidden {
var unwrapped request.RestError
if errors.As(err, &unwrapped); unwrapped.ErrorCode == 403 {
ctx.JSON(500, utils.ErrorToResponse(errors.New("I do not have permission to send messages in the provided channel")))
} else {
ctx.JSON(500, utils.ErrorToResponse(err))
@ -69,7 +70,8 @@ func MultiPanelCreate(ctx *gin.Context) {
}
if err := data.addReactions(&botContext, data.ChannelId, messageId, panels); err != nil {
if err == request.ErrForbidden {
var unwrapped request.RestError
if errors.As(err, &unwrapped); unwrapped.ErrorCode == 403{
ctx.JSON(500, utils.ErrorToResponse(errors.New("I do not have permission to add reactions in the provided channel")))
} else {
ctx.JSON(500, utils.ErrorToResponse(err))

View File

@ -38,7 +38,8 @@ func MultiPanelDelete(ctx *gin.Context) {
return
}
if err := rest.DeleteMessage(botContext.Token, botContext.RateLimiter, panel.ChannelId, panel.MessageId); err != nil && !request.IsClientError(err) {
var unwrapped request.RestError
if err := rest.DeleteMessage(botContext.Token, botContext.RateLimiter, panel.ChannelId, panel.MessageId); err != nil && !(errors.As(err, &unwrapped) && unwrapped.IsClientError()) {
ctx.JSON(500, utils.ErrorToResponse(err))
return
}

View File

@ -67,7 +67,8 @@ func MultiPanelUpdate(ctx *gin.Context) {
}
// delete old message
if err := rest.DeleteMessage(botContext.Token, botContext.RateLimiter, multiPanel.ChannelId, multiPanel.MessageId); err != nil && !request.IsClientError(err) {
var unwrapped request.RestError
if err := rest.DeleteMessage(botContext.Token, botContext.RateLimiter, multiPanel.ChannelId, multiPanel.MessageId); err != nil && !(errors.As(err, &unwrapped) && unwrapped.IsClientError()) {
ctx.JSON(500, utils.ErrorToResponse(err))
return
}
@ -78,7 +79,8 @@ func MultiPanelUpdate(ctx *gin.Context) {
// send new message
messageId, err := data.sendEmbed(&botContext, premiumTier > premium.None)
if err != nil {
if err == request.ErrForbidden {
var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 {
ctx.JSON(500, utils.ErrorToResponse(errors.New("I do not have permission to send messages in the provided channel")))
} else {
ctx.JSON(500, utils.ErrorToResponse(err))
@ -89,7 +91,8 @@ func MultiPanelUpdate(ctx *gin.Context) {
// add reactions to new message
if err := data.addReactions(&botContext, data.ChannelId, messageId, panels); err != nil {
if err == request.ErrForbidden {
var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 {
ctx.JSON(500, utils.ErrorToResponse(errors.New("I do not have permission to add reactions in the provided channel")))
} else {
ctx.JSON(500, utils.ErrorToResponse(err))

View File

@ -71,7 +71,8 @@ func CreatePanel(ctx *gin.Context) {
msgId, err := data.sendEmbed(&botContext, premiumTier > premium.None)
if err != nil {
if err == request.ErrForbidden {
var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 {
ctx.AbortWithStatusJSON(500, gin.H{
"success": false,
"error": "I do not have permission to send messages in the specified channel",
@ -90,7 +91,8 @@ func CreatePanel(ctx *gin.Context) {
// Add reaction
emoji, _ := data.getEmoji() // already validated
if err = rest.CreateReaction(botContext.Token, botContext.RateLimiter, data.ChannelId, msgId, emoji); err != nil {
if err == request.ErrForbidden {
var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 {
ctx.AbortWithStatusJSON(500, gin.H{
"success": false,
"error": "I do not have permission to add reactions in the specified channel",

View File

@ -137,7 +137,8 @@ func UpdatePanel(ctx *gin.Context) {
premiumTier := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
newMessageId, err = data.sendEmbed(&botContext, premiumTier > premium.None)
if err != nil {
if err == request.ErrForbidden {
var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 {
ctx.AbortWithStatusJSON(500, gin.H{
"success": false,
"error": "I do not have permission to send messages in the specified channel",
@ -152,7 +153,8 @@ func UpdatePanel(ctx *gin.Context) {
// Add reaction
if err = rest.CreateReaction(botContext.Token, botContext.RateLimiter, data.ChannelId, newMessageId, emoji); err != nil {
if err == request.ErrForbidden {
var unwrapped request.RestError
if errors.As(err, &unwrapped) && unwrapped.ErrorCode == 403 {
ctx.AbortWithStatusJSON(500, gin.H{
"success": false,
"error": "I do not have permission to add reactions in the specified channel",

View File

@ -1,6 +1,7 @@
package api
import (
"errors"
"fmt"
"github.com/TicketsBot/GoPanel/botcontext"
"github.com/TicketsBot/GoPanel/database"
@ -105,9 +106,9 @@ func SendMessage(ctx *gin.Context) {
})
if err != nil {
fmt.Println(err.Error())
// We can delete the webhook in this case
if err == request.ErrNotFound || err == request.ErrForbidden {
var unwrapped request.RestError
if errors.As(err, &unwrapped); unwrapped.ErrorCode == 403 || unwrapped.ErrorCode == 404 {
go database.Client.Webhooks.Delete(guildId, ticketId)
}
} else {

4
go.mod
View File

@ -5,7 +5,7 @@ go 1.14
require (
github.com/BurntSushi/toml v0.3.1
github.com/TicketsBot/archiverclient v0.0.0-20200704164621-09d42dd941e0
github.com/TicketsBot/common v0.0.0-20200702195837-7afe5e77d1df
github.com/TicketsBot/common v0.0.0-20200925115036-a1bbe85f45bb
github.com/TicketsBot/database v0.0.0-20200723134637-72f4cd31eef6
github.com/TicketsBot/logarchiver v0.0.0-20200425163447-199b93429026 // indirect
github.com/apex/log v1.1.2
@ -23,7 +23,7 @@ require (
github.com/klauspost/compress v1.10.10 // indirect
github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c
github.com/pkg/errors v0.9.1
github.com/rxdn/gdl v0.0.0-20200618155240-edb9ae72ef6e
github.com/rxdn/gdl v0.0.0-20200925123042-8f6710be7d00
github.com/sirupsen/logrus v1.5.0
github.com/ulule/limiter/v3 v3.5.0
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a