Custom commands
This commit is contained in:
parent
c675d0f655
commit
618c26acbc
@ -14,7 +14,7 @@ func AddBotStaffHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Client.BotStaff.Add(userId); err != nil {
|
if err := database.Client.BotStaff.Add(ctx, userId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ type userData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ListBotStaffHandler(ctx *gin.Context) {
|
func ListBotStaffHandler(ctx *gin.Context) {
|
||||||
staff, err := database.Client.BotStaff.GetAll()
|
staff, err := database.Client.BotStaff.GetAll(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -38,7 +38,7 @@ func ListBotStaffHandler(ctx *gin.Context) {
|
|||||||
Id: userId,
|
Id: userId,
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := cache.Instance.GetUser(context.Background(), userId)
|
user, err := cache.Instance.GetUser(ctx, userId)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
data.Username = user.Username
|
data.Username = user.Username
|
||||||
data.Discriminator = user.Discriminator
|
data.Discriminator = user.Discriminator
|
||||||
|
@ -14,7 +14,7 @@ func RemoveBotStaffHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Client.BotStaff.Delete(userId); err != nil {
|
if err := database.Client.BotStaff.Delete(ctx, userId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func GetBlacklistHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
offset := pageLimit * (page - 1)
|
offset := pageLimit * (page - 1)
|
||||||
|
|
||||||
blacklistedUsers, err := database.Client.Blacklist.GetBlacklistedUsers(guildId, pageLimit, offset)
|
blacklistedUsers, err := database.Client.Blacklist.GetBlacklistedUsers(ctx, guildId, pageLimit, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -64,7 +64,7 @@ func GetBlacklistHandler(ctx *gin.Context) {
|
|||||||
users[i] = userData
|
users[i] = userData
|
||||||
}
|
}
|
||||||
|
|
||||||
blacklistedRoles, err := database.Client.RoleBlacklist.GetBlacklistedRoles(guildId)
|
blacklistedRoles, err := database.Client.RoleBlacklist.GetBlacklistedRoles(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -43,7 +43,7 @@ func AddBlacklistHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
if body.EntityType == entityTypeUser {
|
if body.EntityType == entityTypeUser {
|
||||||
// Max of 250 blacklisted users
|
// Max of 250 blacklisted users
|
||||||
count, err := database.Client.Blacklist.GetBlacklistedCount(guildId)
|
count, err := database.Client.Blacklist.GetBlacklistedCount(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -66,7 +66,7 @@ func AddBlacklistHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Client.Blacklist.Add(guildId, body.Snowflake); err != nil {
|
if err := database.Client.Blacklist.Add(ctx, guildId, body.Snowflake); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ func AddBlacklistHandler(ctx *gin.Context) {
|
|||||||
})
|
})
|
||||||
} else if body.EntityType == entityTypeRole {
|
} else if body.EntityType == entityTypeRole {
|
||||||
// Max of 50 blacklisted roles
|
// Max of 50 blacklisted roles
|
||||||
count, err := database.Client.RoleBlacklist.GetBlacklistedCount(guildId)
|
count, err := database.Client.RoleBlacklist.GetBlacklistedCount(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -107,7 +107,7 @@ func AddBlacklistHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Client.RoleBlacklist.Add(guildId, body.Snowflake); err != nil {
|
if err := database.Client.RoleBlacklist.Add(ctx, guildId, body.Snowflake); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ func RemoveRoleBlacklistHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Client.RoleBlacklist.Remove(guildId, roleId); err != nil {
|
if err := database.Client.RoleBlacklist.Remove(ctx, guildId, roleId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ func RemoveUserBlacklistHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Client.Blacklist.Remove(guildId, userId); err != nil {
|
if err := database.Client.Blacklist.Remove(ctx, guildId, userId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func CreateForm(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := dbclient.Client.Forms.Create(guildId, data.Title, customId)
|
id, err := dbclient.Client.Forms.Create(ctx, guildId, data.Title, customId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -16,11 +16,11 @@ func DeleteForm(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
form, ok, err := dbclient.Client.Forms.Get(formId)
|
form, ok, err := dbclient.Client.Forms.Get(ctx, formId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.JSON(404, utils.ErrorStr("Form not found"))
|
ctx.JSON(404, utils.ErrorStr("Form not found"))
|
||||||
@ -29,13 +29,13 @@ func DeleteForm(ctx *gin.Context) {
|
|||||||
|
|
||||||
if form.GuildId != guildId {
|
if form.GuildId != guildId {
|
||||||
ctx.JSON(403, utils.ErrorStr("Form does not belong to this guild"))
|
ctx.JSON(403, utils.ErrorStr("Form does not belong to this guild"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.Forms.Delete(formId); err != nil {
|
if err := dbclient.Client.Forms.Delete(ctx, formId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(200, utils.SuccessResponse)
|
ctx.JSON(200, utils.SuccessResponse)
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,13 @@ type embeddedForm struct {
|
|||||||
func GetForms(ctx *gin.Context) {
|
func GetForms(ctx *gin.Context) {
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
forms, err := dbclient.Client.Forms.GetForms(guildId)
|
forms, err := dbclient.Client.Forms.GetForms(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
inputs, err := dbclient.Client.FormInput.GetInputsForGuild(guildId)
|
inputs, err := dbclient.Client.FormInput.GetInputsForGuild(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -27,7 +27,7 @@ func UpdateForm(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
form, ok, err := dbclient.Client.Forms.Get(formId)
|
form, ok, err := dbclient.Client.Forms.Get(ctx, formId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -43,7 +43,7 @@ func UpdateForm(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.Forms.UpdateTitle(formId, data.Title); err != nil {
|
if err := dbclient.Client.Forms.UpdateTitle(ctx, formId, data.Title); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func UpdateInputs(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify form exists and is from the right guild
|
// Verify form exists and is from the right guild
|
||||||
form, ok, err := dbclient.Client.Forms.Get(formId)
|
form, ok, err := dbclient.Client.Forms.Get(ctx, formId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -88,7 +88,7 @@ func UpdateInputs(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
existingInputs, err := dbclient.Client.FormInput.GetInputs(formId)
|
existingInputs, err := dbclient.Client.FormInput.GetInputs(ctx, formId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -145,7 +145,7 @@ func UpdateInputs(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := saveInputs(formId, data, existingInputs); err != nil {
|
if err := saveInputs(ctx, formId, data, existingInputs); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -184,9 +184,9 @@ func arePositionsCorrect(body updateInputsBody) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveInputs(formId int, data updateInputsBody, existingInputs []database.FormInput) error {
|
func saveInputs(ctx context.Context, formId int, data updateInputsBody, existingInputs []database.FormInput) error {
|
||||||
// We can now update in the database
|
// We can now update in the database
|
||||||
tx, err := dbclient.Client.BeginTx()
|
tx, err := dbclient.Client.BeginTx(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ func saveInputs(formId int, data updateInputsBody, existingInputs []database.For
|
|||||||
defer tx.Rollback(context.Background())
|
defer tx.Rollback(context.Background())
|
||||||
|
|
||||||
for _, id := range data.Delete {
|
for _, id := range data.Delete {
|
||||||
if err := dbclient.Client.FormInput.DeleteTx(tx, id, formId); err != nil {
|
if err := dbclient.Client.FormInput.DeleteTx(ctx, tx, id, formId); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,7 +218,7 @@ func saveInputs(formId int, data updateInputsBody, existingInputs []database.For
|
|||||||
MaxLength: &input.MaxLength,
|
MaxLength: &input.MaxLength,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.FormInput.UpdateTx(tx, wrapped); err != nil {
|
if err := dbclient.Client.FormInput.UpdateTx(ctx, tx, wrapped); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,7 +229,7 @@ func saveInputs(formId int, data updateInputsBody, existingInputs []database.For
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := dbclient.Client.FormInput.CreateTx(
|
if _, err := dbclient.Client.FormInput.CreateTx(ctx,
|
||||||
tx,
|
tx,
|
||||||
formId,
|
formId,
|
||||||
customId,
|
customId,
|
||||||
|
@ -90,7 +90,7 @@ func GetGuilds(c *gin.Context) {
|
|||||||
|
|
||||||
func getGuildIntersection(userId uint64) ([]database.UserGuild, error) {
|
func getGuildIntersection(userId uint64) ([]database.UserGuild, error) {
|
||||||
// Get all the guilds that the user is in
|
// Get all the guilds that the user is in
|
||||||
userGuilds, err := dbclient.Client.UserGuilds.Get(userId)
|
userGuilds, err := dbclient.Client.UserGuilds.Get(context.Background(), userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func ActivateIntegrationHandler(ctx *gin.Context) {
|
|||||||
userId := ctx.Keys["userid"].(uint64)
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
activeCount, err := dbclient.Client.CustomIntegrationGuilds.GetGuildIntegrationCount(guildId)
|
activeCount, err := dbclient.Client.CustomIntegrationGuilds.GetGuildIntegrationCount(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -42,7 +42,7 @@ func ActivateIntegrationHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
integration, ok, err := dbclient.Client.CustomIntegrations.Get(integrationId)
|
integration, ok, err := dbclient.Client.CustomIntegrations.Get(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -54,7 +54,7 @@ func ActivateIntegrationHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check the integration is public or the user created it
|
// Check the integration is public or the user created it
|
||||||
canActivate, err := dbclient.Client.CustomIntegrationGuilds.CanActivate(integrationId, userId)
|
canActivate, err := dbclient.Client.CustomIntegrationGuilds.CanActivate(ctx, integrationId, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -66,7 +66,7 @@ func ActivateIntegrationHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check the secret values are valid
|
// Check the secret values are valid
|
||||||
secrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(integrationId)
|
secrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -77,7 +77,7 @@ func ActivateIntegrationHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we've checked the length, we can just iterate over the secrets and they're guaranteed to be correct
|
// Since we've checked the length, we can just iterate over the secrets, and they're guaranteed to be correct
|
||||||
secretMap := make(map[int]string)
|
secretMap := make(map[int]string)
|
||||||
secretValues := make(map[string]string)
|
secretValues := make(map[string]string)
|
||||||
for secretName, value := range data.Secrets {
|
for secretName, value := range data.Secrets {
|
||||||
@ -106,7 +106,7 @@ func ActivateIntegrationHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// Validate secrets
|
// Validate secrets
|
||||||
if integration.Public && integration.Approved && integration.ValidationUrl != nil {
|
if integration.Public && integration.Approved && integration.ValidationUrl != nil {
|
||||||
integrationHeaders, err := dbclient.Client.CustomIntegrationHeaders.GetByIntegration(integrationId)
|
integrationHeaders, err := dbclient.Client.CustomIntegrationHeaders.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -162,7 +162,7 @@ func ActivateIntegrationHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.CustomIntegrationGuilds.AddToGuildWithSecrets(integrationId, guildId, secretMap); err != nil {
|
if err := dbclient.Client.CustomIntegrationGuilds.AddToGuildWithSecrets(ctx, integrationId, guildId, secretMap); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ var validate = newIntegrationValidator()
|
|||||||
func CreateIntegrationHandler(ctx *gin.Context) {
|
func CreateIntegrationHandler(ctx *gin.Context) {
|
||||||
userId := ctx.Keys["userid"].(uint64)
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
|
|
||||||
ownedCount, err := dbclient.Client.CustomIntegrations.GetOwnedCount(userId)
|
ownedCount, err := dbclient.Client.CustomIntegrations.GetOwnedCount(ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -83,7 +83,7 @@ func CreateIntegrationHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
integration, err := dbclient.Client.CustomIntegrations.Create(userId, data.WebhookUrl, data.ValidationUrl, data.Method, data.Name, data.Description, data.ImageUrl, data.PrivacyPolicyUrl)
|
integration, err := dbclient.Client.CustomIntegrations.Create(ctx, userId, data.WebhookUrl, data.ValidationUrl, data.Method, data.Name, data.Description, data.ImageUrl, data.PrivacyPolicyUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -99,7 +99,7 @@ func CreateIntegrationHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := dbclient.Client.CustomIntegrationSecrets.CreateOrUpdate(integration.Id, secrets); err != nil {
|
if _, err := dbclient.Client.CustomIntegrationSecrets.CreateOrUpdate(ctx, integration.Id, secrets); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ func CreateIntegrationHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := dbclient.Client.CustomIntegrationHeaders.CreateOrUpdate(integration.Id, headers); err != nil {
|
if _, err := dbclient.Client.CustomIntegrationHeaders.CreateOrUpdate(ctx, integration.Id, headers); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ func CreateIntegrationHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := dbclient.Client.CustomIntegrationPlaceholders.Set(integration.Id, placeholders); err != nil {
|
if _, err := dbclient.Client.CustomIntegrationPlaceholders.Set(ctx, integration.Id, placeholders); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -149,4 +149,4 @@ func isSameValidationUrlHost(webhookUrl, validationUrl string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return strings.ToLower(utils.SecondLevelDomain(webhookStripped)) == strings.ToLower(utils.SecondLevelDomain(validationStripped)), nil
|
return strings.ToLower(utils.SecondLevelDomain(webhookStripped)) == strings.ToLower(utils.SecondLevelDomain(validationStripped)), nil
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ func DeleteIntegrationHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
integration, ok, err := dbclient.Client.CustomIntegrations.Get(integrationId)
|
integration, ok, err := dbclient.Client.CustomIntegrations.Get(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -33,7 +33,7 @@ func DeleteIntegrationHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.CustomIntegrations.Delete(integration.Id); err != nil {
|
if err := dbclient.Client.CustomIntegrations.Delete(ctx, integration.Id); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func UpdateIntegrationSecretsHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check integration is active
|
// Check integration is active
|
||||||
active, err := dbclient.Client.CustomIntegrationGuilds.IsActive(integrationId, guildId)
|
active, err := dbclient.Client.CustomIntegrationGuilds.IsActive(ctx, integrationId, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -34,7 +34,7 @@ func UpdateIntegrationSecretsHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Check the secret values are valid
|
// Check the secret values are valid
|
||||||
secrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(integrationId)
|
secrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -70,7 +70,7 @@ func UpdateIntegrationSecretsHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.CustomIntegrationSecretValues.UpdateAll(guildId, integrationId, secretMap); err != nil {
|
if err := dbclient.Client.CustomIntegrationSecretValues.UpdateAll(ctx, guildId, integrationId, secretMap); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func GetIntegrationHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
integration, ok, err := dbclient.Client.CustomIntegrations.Get(integrationId)
|
integration, ok, err := dbclient.Client.CustomIntegrations.Get(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -52,7 +52,7 @@ func GetIntegrationHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
placeholders, err := dbclient.Client.CustomIntegrationPlaceholders.GetByIntegration(integrationId)
|
placeholders, err := dbclient.Client.CustomIntegrationPlaceholders.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -63,7 +63,7 @@ func GetIntegrationHandler(ctx *gin.Context) {
|
|||||||
placeholders = make([]database.CustomIntegrationPlaceholder, 0)
|
placeholders = make([]database.CustomIntegrationPlaceholder, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
secrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(integrationId)
|
secrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -24,7 +24,7 @@ func GetIntegrationDetailedHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
integration, ok, err := dbclient.Client.CustomIntegrations.Get(integrationId)
|
integration, ok, err := dbclient.Client.CustomIntegrations.Get(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -42,7 +42,7 @@ func GetIntegrationDetailedHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get placeholders
|
// Get placeholders
|
||||||
placeholders, err := dbclient.Client.CustomIntegrationPlaceholders.GetByIntegration(integrationId)
|
placeholders, err := dbclient.Client.CustomIntegrationPlaceholders.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -54,7 +54,7 @@ func GetIntegrationDetailedHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get headers
|
// Get headers
|
||||||
headers, err := dbclient.Client.CustomIntegrationHeaders.GetByIntegration(integrationId)
|
headers, err := dbclient.Client.CustomIntegrationHeaders.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -66,7 +66,7 @@ func GetIntegrationDetailedHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get secrets
|
// Get secrets
|
||||||
secrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(integrationId)
|
secrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -16,7 +16,7 @@ func IsIntegrationActiveHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
active, err := dbclient.Client.CustomIntegrationGuilds.IsActive(integrationId, guildId)
|
active, err := dbclient.Client.CustomIntegrationGuilds.IsActive(ctx, integrationId, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -46,7 +46,7 @@ func ListIntegrationsHandler(ctx *gin.Context) {
|
|||||||
limit -= builtInCount
|
limit -= builtInCount
|
||||||
}
|
}
|
||||||
|
|
||||||
availableIntegrations, err := dbclient.Client.CustomIntegrationGuilds.GetAvailableIntegrationsWithActive(guildId, userId, limit, page*pageLimit)
|
availableIntegrations, err := dbclient.Client.CustomIntegrationGuilds.GetAvailableIntegrationsWithActive(ctx, guildId, userId, limit, page*pageLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -25,13 +25,13 @@ func GetOwnedIntegrationsHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// Retrieve integrations
|
// Retrieve integrations
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
integrations, err = dbclient.Client.CustomIntegrations.GetAllOwned(userId)
|
integrations, err = dbclient.Client.CustomIntegrations.GetAllOwned(ctx, userId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// Retrieve placeholders
|
// Retrieve placeholders
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
placeholders, err = dbclient.Client.CustomIntegrationPlaceholders.GetAllForOwnedIntegrations(userId)
|
placeholders, err = dbclient.Client.CustomIntegrationPlaceholders.GetAllForOwnedIntegrations(ctx, userId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func RemoveIntegrationHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.CustomIntegrationGuilds.RemoveFromGuild(integrationId, guildId); err != nil {
|
if err := dbclient.Client.CustomIntegrationGuilds.RemoveFromGuild(ctx, integrationId, guildId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TicketsBot/GoPanel/botcontext"
|
"github.com/TicketsBot/GoPanel/botcontext"
|
||||||
"github.com/TicketsBot/GoPanel/config"
|
"github.com/TicketsBot/GoPanel/config"
|
||||||
@ -22,7 +21,7 @@ func SetIntegrationPublicHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
integration, ok, err := dbclient.Client.CustomIntegrations.Get(integrationId)
|
integration, ok, err := dbclient.Client.CustomIntegrations.Get(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -56,7 +55,7 @@ func SetIntegrationPublicHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// TODO: Use proper context
|
// TODO: Use proper context
|
||||||
_, err = rest.ExecuteWebhook(
|
_, err = rest.ExecuteWebhook(
|
||||||
context.Background(),
|
ctx,
|
||||||
config.Conf.Bot.PublicIntegrationRequestWebhookToken,
|
config.Conf.Bot.PublicIntegrationRequestWebhookToken,
|
||||||
botCtx.RateLimiter,
|
botCtx.RateLimiter,
|
||||||
config.Conf.Bot.PublicIntegrationRequestWebhookId,
|
config.Conf.Bot.PublicIntegrationRequestWebhookId,
|
||||||
@ -71,7 +70,7 @@ func SetIntegrationPublicHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.CustomIntegrations.SetPublic(integration.Id); err != nil {
|
if err := dbclient.Client.CustomIntegrations.SetPublic(ctx, integration.Id); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func UpdateIntegrationHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
integration, ok, err := dbclient.Client.CustomIntegrations.Get(integrationId)
|
integration, ok, err := dbclient.Client.CustomIntegrations.Get(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -102,7 +102,7 @@ func UpdateIntegrationHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update integration metadata
|
// Update integration metadata
|
||||||
err = dbclient.Client.CustomIntegrations.Update(database.CustomIntegration{
|
err = dbclient.Client.CustomIntegrations.Update(ctx, database.CustomIntegration{
|
||||||
Id: integration.Id,
|
Id: integration.Id,
|
||||||
OwnerId: integration.OwnerId,
|
OwnerId: integration.OwnerId,
|
||||||
HttpMethod: data.Method,
|
HttpMethod: data.Method,
|
||||||
@ -141,7 +141,7 @@ func UpdateIntegrationHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
func (b *integrationUpdateBody) updatePlaceholders(ctx *gin.Context, integrationId int) bool {
|
func (b *integrationUpdateBody) updatePlaceholders(ctx *gin.Context, integrationId int) bool {
|
||||||
// Verify IDs are valid for the integration
|
// Verify IDs are valid for the integration
|
||||||
existingPlaceholders, err := dbclient.Client.CustomIntegrationPlaceholders.GetByIntegration(integrationId)
|
existingPlaceholders, err := dbclient.Client.CustomIntegrationPlaceholders.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return false
|
return false
|
||||||
@ -179,7 +179,7 @@ func (b *integrationUpdateBody) updatePlaceholders(ctx *gin.Context, integration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := dbclient.Client.CustomIntegrationPlaceholders.Set(integrationId, placeholders); err != nil {
|
if _, err := dbclient.Client.CustomIntegrationPlaceholders.Set(ctx, integrationId, placeholders); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ func (b *integrationUpdateBody) updatePlaceholders(ctx *gin.Context, integration
|
|||||||
|
|
||||||
func (b *integrationUpdateBody) updateHeaders(ctx *gin.Context, integrationId int) bool {
|
func (b *integrationUpdateBody) updateHeaders(ctx *gin.Context, integrationId int) bool {
|
||||||
// Verify IDs are valid for the integration
|
// Verify IDs are valid for the integration
|
||||||
existingHeaders, err := dbclient.Client.CustomIntegrationHeaders.GetByIntegration(integrationId)
|
existingHeaders, err := dbclient.Client.CustomIntegrationHeaders.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return false
|
return false
|
||||||
@ -228,7 +228,7 @@ func (b *integrationUpdateBody) updateHeaders(ctx *gin.Context, integrationId in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := dbclient.Client.CustomIntegrationHeaders.CreateOrUpdate(integrationId, headers); err != nil {
|
if _, err := dbclient.Client.CustomIntegrationHeaders.CreateOrUpdate(ctx, integrationId, headers); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ func (b *integrationUpdateBody) updateHeaders(ctx *gin.Context, integrationId in
|
|||||||
|
|
||||||
func (b *integrationUpdateBody) updateSecrets(ctx *gin.Context, integrationId int) bool {
|
func (b *integrationUpdateBody) updateSecrets(ctx *gin.Context, integrationId int) bool {
|
||||||
// Verify IDs are valid for the integration
|
// Verify IDs are valid for the integration
|
||||||
existingSecrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(integrationId)
|
existingSecrets, err := dbclient.Client.CustomIntegrationSecrets.GetByIntegration(ctx, integrationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return false
|
return false
|
||||||
@ -276,7 +276,7 @@ func (b *integrationUpdateBody) updateSecrets(ctx *gin.Context, integrationId in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := dbclient.Client.CustomIntegrationSecrets.CreateOrUpdate(integrationId, secrets); err != nil {
|
if _, err := dbclient.Client.CustomIntegrationSecrets.CreateOrUpdate(ctx, integrationId, secrets); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func MultiPanelCreate(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get premium status
|
// get premium status
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -96,7 +96,7 @@ func MultiPanelCreate(ctx *gin.Context) {
|
|||||||
SelectMenu: data.SelectMenu,
|
SelectMenu: data.SelectMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
multiPanel.Id, err = dbclient.Client.MultiPanels.Create(multiPanel)
|
multiPanel.Id, err = dbclient.Client.MultiPanels.Create(ctx, multiPanel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -107,7 +107,7 @@ func MultiPanelCreate(ctx *gin.Context) {
|
|||||||
panel := panel
|
panel := panel
|
||||||
|
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
return dbclient.Client.MultiPanelTargets.Insert(multiPanel.Id, panel.PanelId)
|
return dbclient.Client.MultiPanelTargets.Insert(ctx, multiPanel.Id, panel.PanelId)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ func (d *multiPanelCreateData) validatePanels(guildId uint64) (panels []database
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
existingPanels, err := dbclient.Client.Panel.GetByGuild(guildId)
|
existingPanels, err := dbclient.Client.Panel.GetByGuild(context.Background(), guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func MultiPanelDelete(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
panel, ok, err := dbclient.Client.MultiPanels.Get(multiPanelId)
|
panel, ok, err := dbclient.Client.MultiPanels.Get(ctx, multiPanelId)
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.JSON(404, utils.ErrorStr("No panel with matching ID found"))
|
ctx.JSON(404, utils.ErrorStr("No panel with matching ID found"))
|
||||||
return
|
return
|
||||||
@ -46,7 +46,7 @@ func MultiPanelDelete(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
success, err := dbclient.Client.MultiPanels.Delete(guildId, multiPanelId)
|
success, err := dbclient.Client.MultiPanels.Delete(ctx, guildId, multiPanelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -17,7 +17,7 @@ func MultiPanelList(ctx *gin.Context) {
|
|||||||
|
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
multiPanels, err := dbclient.Client.MultiPanels.GetByGuild(guildId)
|
multiPanels, err := dbclient.Client.MultiPanels.GetByGuild(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -35,7 +35,7 @@ func MultiPanelList(ctx *gin.Context) {
|
|||||||
|
|
||||||
// TODO: Use a join
|
// TODO: Use a join
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
panels, err := dbclient.Client.MultiPanelTargets.GetPanels(multiPanel.Id)
|
panels, err := dbclient.Client.MultiPanelTargets.GetPanels(ctx, multiPanel.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func MultiPanelResend(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// retrieve panel from DB
|
// retrieve panel from DB
|
||||||
multiPanel, ok, err := dbclient.Client.MultiPanels.Get(panelId)
|
multiPanel, ok, err := dbclient.Client.MultiPanels.Get(ctx, panelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -61,13 +61,13 @@ func MultiPanelResend(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get premium status
|
// get premium status
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
panels, err := dbclient.Client.MultiPanelTargets.GetPanels(multiPanel.Id)
|
panels, err := dbclient.Client.MultiPanelTargets.GetPanels(ctx, multiPanel.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -87,7 +87,7 @@ func MultiPanelResend(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = dbclient.Client.MultiPanels.UpdateMessageId(multiPanel.Id, messageId); err != nil {
|
if err = dbclient.Client.MultiPanels.UpdateMessageId(ctx, multiPanel.Id, messageId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func MultiPanelUpdate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// retrieve panel from DB
|
// retrieve panel from DB
|
||||||
multiPanel, ok, err := dbclient.Client.MultiPanels.Get(panelId)
|
multiPanel, ok, err := dbclient.Client.MultiPanels.Get(c, panelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, utils.ErrorJson(err))
|
c.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -68,7 +68,7 @@ func MultiPanelUpdate(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.Panel.Update(panel); err != nil {
|
if err := dbclient.Client.Panel.Update(c, panel); err != nil {
|
||||||
c.JSON(500, utils.ErrorJson(err))
|
c.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ func MultiPanelUpdate(c *gin.Context) {
|
|||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
// get premium status
|
// get premium status
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, utils.ErrorJson(err))
|
c.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -128,14 +128,14 @@ func MultiPanelUpdate(c *gin.Context) {
|
|||||||
ThumbnailUrl: data.ThumbnailUrl,
|
ThumbnailUrl: data.ThumbnailUrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = dbclient.Client.MultiPanels.Update(multiPanel.Id, updated); err != nil {
|
if err = dbclient.Client.MultiPanels.Update(c, multiPanel.Id, updated); err != nil {
|
||||||
c.JSON(500, utils.ErrorJson(err))
|
c.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: one query for ACID purposes
|
// TODO: one query for ACID purposes
|
||||||
// delete old targets
|
// delete old targets
|
||||||
if err := dbclient.Client.MultiPanelTargets.DeleteAll(multiPanel.Id); err != nil {
|
if err := dbclient.Client.MultiPanelTargets.DeleteAll(c, multiPanel.Id); err != nil {
|
||||||
c.JSON(500, utils.ErrorJson(err))
|
c.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ func MultiPanelUpdate(c *gin.Context) {
|
|||||||
panel := panel
|
panel := panel
|
||||||
|
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
return dbclient.Client.MultiPanelTargets.Insert(multiPanel.Id, panel.PanelId)
|
return dbclient.Client.MultiPanelTargets.Insert(c, multiPanel.Id, panel.PanelId)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,14 +84,14 @@ func CreatePanel(c *gin.Context) {
|
|||||||
data.MessageId = 0
|
data.MessageId = 0
|
||||||
|
|
||||||
// Check panel quota
|
// Check panel quota
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, false, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(c, guildId, false, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, utils.ErrorJson(err))
|
c.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if premiumTier == premium.None {
|
if premiumTier == premium.None {
|
||||||
panels, err := dbclient.Client.Panel.GetByGuild(guildId)
|
panels, err := dbclient.Client.Panel.GetByGuild(c, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, utils.ErrorJson(err))
|
c.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -194,7 +194,7 @@ func CreatePanel(c *gin.Context) {
|
|||||||
embed, fields := data.WelcomeMessage.IntoDatabaseStruct()
|
embed, fields := data.WelcomeMessage.IntoDatabaseStruct()
|
||||||
embed.GuildId = guildId
|
embed.GuildId = guildId
|
||||||
|
|
||||||
id, err := dbclient.Client.Embeds.CreateWithFields(embed, fields)
|
id, err := dbclient.Client.Embeds.CreateWithFields(c, embed, fields)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, utils.ErrorJson(err))
|
c.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -279,21 +279,21 @@ func storePanel(ctx context.Context, panel database.Panel, options panelCreateOp
|
|||||||
var panelId int
|
var panelId int
|
||||||
err := dbclient.Client.Panel.BeginFunc(ctx, func(tx pgx.Tx) error {
|
err := dbclient.Client.Panel.BeginFunc(ctx, func(tx pgx.Tx) error {
|
||||||
var err error
|
var err error
|
||||||
panelId, err = dbclient.Client.Panel.CreateWithTx(tx, panel)
|
panelId, err = dbclient.Client.Panel.CreateWithTx(ctx, tx, panel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.PanelUserMention.SetWithTx(tx, panelId, options.ShouldMentionUser); err != nil {
|
if err := dbclient.Client.PanelUserMention.SetWithTx(ctx, tx, panelId, options.ShouldMentionUser); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.PanelRoleMentions.ReplaceWithTx(tx, panelId, options.RoleMentions); err != nil {
|
if err := dbclient.Client.PanelRoleMentions.ReplaceWithTx(ctx, tx, panelId, options.RoleMentions); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Already validated, we are safe to insert
|
// Already validated, we are safe to insert
|
||||||
if err := dbclient.Client.PanelTeams.ReplaceWithTx(tx, panelId, options.TeamIds); err != nil {
|
if err := dbclient.Client.PanelTeams.ReplaceWithTx(ctx, tx, panelId, options.TeamIds); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func DeletePanel(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
panel, err := database.Client.Panel.GetById(panelId)
|
panel, err := database.Client.Panel.GetById(ctx, panelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -47,7 +47,7 @@ func DeletePanel(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get any multi panels this panel is part of to use later
|
// Get any multi panels this panel is part of to use later
|
||||||
multiPanels, err := database.Client.MultiPanelTargets.GetMultiPanels(panelId)
|
multiPanels, err := database.Client.MultiPanelTargets.GetMultiPanels(ctx, panelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -55,13 +55,13 @@ func DeletePanel(ctx *gin.Context) {
|
|||||||
|
|
||||||
// Delete welcome message embed
|
// Delete welcome message embed
|
||||||
if panel.WelcomeMessageEmbed != nil {
|
if panel.WelcomeMessageEmbed != nil {
|
||||||
if err := database.Client.Embeds.Delete(*panel.WelcomeMessageEmbed); err != nil {
|
if err := database.Client.Embeds.Delete(ctx, *panel.WelcomeMessageEmbed); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Client.Panel.Delete(panelId); err != nil {
|
if err := database.Client.Panel.Delete(ctx, panelId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func DeletePanel(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get premium tier
|
// Get premium tier
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -89,7 +89,7 @@ func DeletePanel(ctx *gin.Context) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
panels, err := database.Client.MultiPanelTargets.GetPanels(multiPanel.Id)
|
panels, err := database.Client.MultiPanelTargets.GetPanels(ctx, multiPanel.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -110,7 +110,7 @@ func DeletePanel(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Client.MultiPanels.UpdateMessageId(multiPanel.Id, messageId); err != nil {
|
if err := database.Client.MultiPanels.UpdateMessageId(ctx, multiPanel.Id, messageId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func ListPanels(ctx *gin.Context) {
|
|||||||
|
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
panels, err := dbclient.Client.Panel.GetByGuildWithWelcomeMessage(guildId)
|
panels, err := dbclient.Client.Panel.GetByGuildWithWelcomeMessage(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -37,7 +37,7 @@ func ListPanels(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
allFields, err := dbclient.Client.EmbedFields.GetAllFieldsForPanels(guildId)
|
allFields, err := dbclient.Client.EmbedFields.GetAllFieldsForPanels(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -56,7 +56,7 @@ func ListPanels(ctx *gin.Context) {
|
|||||||
var mentions []string
|
var mentions []string
|
||||||
|
|
||||||
// get if we should mention the ticket opener
|
// get if we should mention the ticket opener
|
||||||
shouldMention, err := dbclient.Client.PanelUserMention.ShouldMentionUser(p.PanelId)
|
shouldMention, err := dbclient.Client.PanelUserMention.ShouldMentionUser(ctx, p.PanelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ func ListPanels(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get role mentions
|
// get role mentions
|
||||||
roles, err := dbclient.Client.PanelRoleMentions.GetRoles(p.PanelId)
|
roles, err := dbclient.Client.PanelRoleMentions.GetRoles(ctx, p.PanelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func ListPanels(ctx *gin.Context) {
|
|||||||
mentions = append(mentions, strconv.FormatUint(roleId, 10))
|
mentions = append(mentions, strconv.FormatUint(roleId, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
teamIds, err := dbclient.Client.PanelTeams.GetTeamIds(p.PanelId)
|
teamIds, err := dbclient.Client.PanelTeams.GetTeamIds(ctx, p.PanelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func ResendPanel(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get existing
|
// get existing
|
||||||
panel, err := dbclient.Client.Panel.GetById(panelId)
|
panel, err := dbclient.Client.Panel.GetById(ctx, panelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -62,7 +62,7 @@ func ResendPanel(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -81,7 +81,7 @@ func ResendPanel(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = dbclient.Client.Panel.UpdateMessageId(panel.PanelId, msgId); err != nil {
|
if err = dbclient.Client.Panel.UpdateMessageId(ctx, panel.PanelId, msgId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get existing
|
// get existing
|
||||||
existing, err := dbclient.Client.Panel.GetById(panelId)
|
existing, err := dbclient.Client.Panel.GetById(ctx, panelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -61,7 +61,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
// Apply defaults
|
// Apply defaults
|
||||||
ApplyPanelDefaults(&data)
|
ApplyPanelDefaults(&data)
|
||||||
|
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -173,7 +173,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
var welcomeMessageEmbed *int
|
var welcomeMessageEmbed *int
|
||||||
if data.WelcomeMessage == nil {
|
if data.WelcomeMessage == nil {
|
||||||
if existing.WelcomeMessageEmbed != nil { // If welcome message wasn't null, but now is, delete the embed
|
if existing.WelcomeMessageEmbed != nil { // If welcome message wasn't null, but now is, delete the embed
|
||||||
if err := dbclient.Client.Embeds.Delete(*existing.WelcomeMessageEmbed); err != nil {
|
if err := dbclient.Client.Embeds.Delete(ctx, *existing.WelcomeMessageEmbed); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
embed, fields := data.WelcomeMessage.IntoDatabaseStruct()
|
embed, fields := data.WelcomeMessage.IntoDatabaseStruct()
|
||||||
embed.GuildId = guildId
|
embed.GuildId = guildId
|
||||||
|
|
||||||
id, err := dbclient.Client.Embeds.CreateWithFields(embed, fields)
|
id, err := dbclient.Client.Embeds.CreateWithFields(ctx, embed, fields)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -198,7 +198,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
embed.Id = *existing.WelcomeMessageEmbed
|
embed.Id = *existing.WelcomeMessageEmbed
|
||||||
embed.GuildId = guildId
|
embed.GuildId = guildId
|
||||||
|
|
||||||
if err := dbclient.Client.Embeds.UpdateWithFields(embed, fields); err != nil {
|
if err := dbclient.Client.Embeds.UpdateWithFields(ctx, embed, fields); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -254,20 +254,20 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = dbclient.Client.Panel.BeginFunc(ctx, func(tx pgx.Tx) error {
|
err = dbclient.Client.Panel.BeginFunc(ctx, func(tx pgx.Tx) error {
|
||||||
if err := dbclient.Client.Panel.UpdateWithTx(tx, panel); err != nil {
|
if err := dbclient.Client.Panel.UpdateWithTx(ctx, tx, panel); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.PanelUserMention.SetWithTx(tx, panel.PanelId, shouldMentionUser); err != nil {
|
if err := dbclient.Client.PanelUserMention.SetWithTx(ctx, tx, panel.PanelId, shouldMentionUser); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.PanelRoleMentions.ReplaceWithTx(tx, panel.PanelId, roleMentions); err != nil {
|
if err := dbclient.Client.PanelRoleMentions.ReplaceWithTx(ctx, tx, panel.PanelId, roleMentions); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are safe to insert, team IDs already validated
|
// We are safe to insert, team IDs already validated
|
||||||
if err := dbclient.Client.PanelTeams.ReplaceWithTx(tx, panel.PanelId, data.Teams); err != nil {
|
if err := dbclient.Client.PanelTeams.ReplaceWithTx(ctx, tx, panel.PanelId, data.Teams); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
|
|
||||||
// check if this will break a multi-panel;
|
// check if this will break a multi-panel;
|
||||||
// first, get any multipanels this panel belongs to
|
// first, get any multipanels this panel belongs to
|
||||||
multiPanels, err := dbclient.Client.MultiPanelTargets.GetMultiPanels(existing.PanelId)
|
multiPanels, err := dbclient.Client.MultiPanelTargets.GetMultiPanels(ctx, existing.PanelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -300,7 +300,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
panels, err := dbclient.Client.MultiPanelTargets.GetPanels(multiPanel.Id)
|
panels, err := dbclient.Client.MultiPanelTargets.GetPanels(ctx, multiPanel.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -323,7 +323,7 @@ func UpdatePanel(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.MultiPanels.UpdateMessageId(multiPanel.Id, messageId); err != nil {
|
if err := dbclient.Client.MultiPanels.UpdateMessageId(ctx, multiPanel.Id, messageId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ func validatedNullableFormId(guildId uint64, formId *int) validation.ValidationF
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
form, ok, err := dbclient.Client.Forms.Get(*formId)
|
form, ok, err := dbclient.Client.Forms.Get(context.Background(), *formId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ func validateTeams(ctx PanelValidationContext) validation.ValidationFunc {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ok, err := dbclient.Client.SupportTeam.AllTeamsExistForGuild(ctx.GuildId, ctx.Data.Teams)
|
ok, err := dbclient.Client.SupportTeam.AllTeamsExistForGuild(context.Background(), ctx.GuildId, ctx.Data.Teams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ func PremiumHandler(ctx *gin.Context) {
|
|||||||
// If error, will default to false
|
// If error, will default to false
|
||||||
includeVoting, _ := strconv.ParseBool(ctx.Query("include_voting"))
|
includeVoting, _ := strconv.ParseBool(ctx.Query("include_voting"))
|
||||||
|
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, includeVoting, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, includeVoting, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -27,7 +27,7 @@ func SessionHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tier, err := rpc.PremiumClient.GetTierByUser(userId, false)
|
tier, err := rpc.PremiumClient.GetTierByUser(ctx, userId, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -50,19 +50,19 @@ func GetSettingsHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// main settings
|
// main settings
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.Settings, err = dbclient.Client.Settings.Get(guildId)
|
settings.Settings, err = dbclient.Client.Settings.Get(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// claim settings
|
// claim settings
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.ClaimSettings, err = dbclient.Client.ClaimSettings.Get(guildId)
|
settings.ClaimSettings, err = dbclient.Client.ClaimSettings.Get(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// auto close settings
|
// auto close settings
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
tmp, err := dbclient.Client.AutoClose.Get(guildId)
|
tmp, err := dbclient.Client.AutoClose.Get(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ func GetSettingsHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// ticket permissions
|
// ticket permissions
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.TicketPermissions, err = dbclient.Client.TicketPermissions.Get(guildId)
|
settings.TicketPermissions, err = dbclient.Client.TicketPermissions.Get(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ func GetSettingsHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// welcome message
|
// welcome message
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.WelcomeMessage, err = dbclient.Client.WelcomeMessages.Get(guildId)
|
settings.WelcomeMessage, err = dbclient.Client.WelcomeMessages.Get(ctx, guildId)
|
||||||
if err == nil && settings.WelcomeMessage == "" {
|
if err == nil && settings.WelcomeMessage == "" {
|
||||||
settings.WelcomeMessage = "Thank you for contacting support.\nPlease describe your issue and await a response."
|
settings.WelcomeMessage = "Thank you for contacting support.\nPlease describe your issue and await a response."
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ func GetSettingsHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// ticket limit
|
// ticket limit
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.TicketLimit, err = dbclient.Client.TicketLimit.Get(guildId)
|
settings.TicketLimit, err = dbclient.Client.TicketLimit.Get(ctx, guildId)
|
||||||
if err == nil && settings.TicketLimit == 0 {
|
if err == nil && settings.TicketLimit == 0 {
|
||||||
settings.TicketLimit = 5 // Set default
|
settings.TicketLimit = 5 // Set default
|
||||||
}
|
}
|
||||||
@ -105,43 +105,43 @@ func GetSettingsHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
// category
|
// category
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.Category, err = dbclient.Client.ChannelCategory.Get(guildId)
|
settings.Category, err = dbclient.Client.ChannelCategory.Get(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// archive channel
|
// archive channel
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.ArchiveChannel, err = dbclient.Client.ArchiveChannel.Get(guildId)
|
settings.ArchiveChannel, err = dbclient.Client.ArchiveChannel.Get(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// allow users to close
|
// allow users to close
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.UsersCanClose, err = dbclient.Client.UsersCanClose.Get(guildId)
|
settings.UsersCanClose, err = dbclient.Client.UsersCanClose.Get(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// naming scheme
|
// naming scheme
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.NamingScheme, err = dbclient.Client.NamingScheme.Get(guildId)
|
settings.NamingScheme, err = dbclient.Client.NamingScheme.Get(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// close confirmation
|
// close confirmation
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.CloseConfirmation, err = dbclient.Client.CloseConfirmation.Get(guildId)
|
settings.CloseConfirmation, err = dbclient.Client.CloseConfirmation.Get(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// close confirmation
|
// close confirmation
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
settings.FeedbackEnabled, err = dbclient.Client.FeedbackEnabled.Get(guildId)
|
settings.FeedbackEnabled, err = dbclient.Client.FeedbackEnabled.Get(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
// language
|
// language
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
locale, err := dbclient.Client.ActiveLanguage.Get(guildId)
|
locale, err := dbclient.Client.ActiveLanguage.Get(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ func GetSettingsHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getColourMap(guildId uint64) (ColourMap, error) {
|
func getColourMap(guildId uint64) (ColourMap, error) {
|
||||||
raw, err := dbclient.Client.CustomColours.GetAll(guildId)
|
raw, err := dbclient.Client.CustomColours.GetAll(context.Background(), guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,13 @@ func UpdateSettingsHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Includes voting
|
// Includes voting
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := settings.Validate(guildId, premiumTier); err != nil {
|
if err := settings.Validate(ctx, guildId, premiumTier); err != nil {
|
||||||
ctx.JSON(400, utils.ErrorJson(err))
|
ctx.JSON(400, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -57,11 +57,11 @@ func UpdateSettingsHandler(ctx *gin.Context) {
|
|||||||
group, _ := errgroup.WithContext(context.Background())
|
group, _ := errgroup.WithContext(context.Background())
|
||||||
|
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
return settings.updateSettings(guildId)
|
return settings.updateSettings(ctx, guildId)
|
||||||
})
|
})
|
||||||
|
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
return settings.updateClaimSettings(guildId)
|
return settings.updateClaimSettings(ctx, guildId)
|
||||||
})
|
})
|
||||||
|
|
||||||
addToWaitGroup(group, guildId, settings.updateTicketPermissions)
|
addToWaitGroup(group, guildId, settings.updateTicketPermissions)
|
||||||
@ -97,12 +97,12 @@ func UpdateSettingsHandler(ctx *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateSettings(guildId uint64) error {
|
func (s *Settings) updateSettings(ctx context.Context, guildId uint64) error {
|
||||||
return dbclient.Client.Settings.Set(guildId, s.Settings)
|
return dbclient.Client.Settings.Set(ctx, guildId, s.Settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateClaimSettings(guildId uint64) error {
|
func (s *Settings) updateClaimSettings(ctx context.Context, guildId uint64) error {
|
||||||
return dbclient.Client.ClaimSettings.Set(guildId, s.ClaimSettings)
|
return dbclient.Client.ClaimSettings.Set(ctx, guildId, s.ClaimSettings)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -110,7 +110,7 @@ var (
|
|||||||
activeColours = []customisation.Colour{customisation.Green, customisation.Red}
|
activeColours = []customisation.Colour{customisation.Green, customisation.Red}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Settings) Validate(guildId uint64, premiumTier premium.PremiumTier) error {
|
func (s *Settings) Validate(ctx context.Context, guildId uint64, premiumTier premium.PremiumTier) error {
|
||||||
// Sync checks
|
// Sync checks
|
||||||
if s.ClaimSettings.SupportCanType && !s.ClaimSettings.SupportCanView {
|
if s.ClaimSettings.SupportCanType && !s.ClaimSettings.SupportCanView {
|
||||||
return errors.New("Must be able to view channel to type")
|
return errors.New("Must be able to view channel to type")
|
||||||
@ -180,7 +180,7 @@ func (s *Settings) Validate(guildId uint64, premiumTier premium.PremiumTier) err
|
|||||||
if s.ContextMenuPanel != nil {
|
if s.ContextMenuPanel != nil {
|
||||||
panelId := *s.ContextMenuPanel
|
panelId := *s.ContextMenuPanel
|
||||||
|
|
||||||
panel, err := dbclient.Client.Panel.GetById(panelId)
|
panel, err := dbclient.Client.Panel.GetById(ctx, panelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -267,7 +267,7 @@ func (s *Settings) updateWelcomeMessage(guildId uint64) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
go dbclient.Client.WelcomeMessages.Set(guildId, s.WelcomeMessage)
|
go dbclient.Client.WelcomeMessages.Set(context.Background(), guildId, s.WelcomeMessage)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ func (s *Settings) updateTicketLimit(guildId uint64) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
go dbclient.Client.TicketLimit.Set(guildId, s.TicketLimit)
|
go dbclient.Client.TicketLimit.Set(context.Background(), guildId, s.TicketLimit)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,13 +293,13 @@ func (s *Settings) updateCategory(channels []channel.Channel, guildId uint64) bo
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
go dbclient.Client.ChannelCategory.Set(guildId, s.Category)
|
go dbclient.Client.ChannelCategory.Set(context.Background(), guildId, s.Category)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateArchiveChannel(channels []channel.Channel, guildId uint64) bool {
|
func (s *Settings) updateArchiveChannel(channels []channel.Channel, guildId uint64) bool {
|
||||||
if s.ArchiveChannel == nil {
|
if s.ArchiveChannel == nil {
|
||||||
go dbclient.Client.ArchiveChannel.Set(guildId, nil)
|
go dbclient.Client.ArchiveChannel.Set(context.Background(), guildId, nil)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ func (s *Settings) updateArchiveChannel(channels []channel.Channel, guildId uint
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
go dbclient.Client.ArchiveChannel.Set(guildId, s.ArchiveChannel)
|
go dbclient.Client.ArchiveChannel.Set(context.Background(), guildId, s.ArchiveChannel)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,32 +334,32 @@ func (s *Settings) updateNamingScheme(guildId uint64) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
go dbclient.Client.NamingScheme.Set(guildId, s.NamingScheme)
|
go dbclient.Client.NamingScheme.Set(context.Background(), guildId, s.NamingScheme)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateUsersCanClose(guildId uint64) {
|
func (s *Settings) updateUsersCanClose(guildId uint64) {
|
||||||
go dbclient.Client.UsersCanClose.Set(guildId, s.UsersCanClose)
|
go dbclient.Client.UsersCanClose.Set(context.Background(), guildId, s.UsersCanClose)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateCloseConfirmation(guildId uint64) {
|
func (s *Settings) updateCloseConfirmation(guildId uint64) {
|
||||||
go dbclient.Client.CloseConfirmation.Set(guildId, s.CloseConfirmation)
|
go dbclient.Client.CloseConfirmation.Set(context.Background(), guildId, s.CloseConfirmation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateFeedbackEnabled(guildId uint64) {
|
func (s *Settings) updateFeedbackEnabled(guildId uint64) {
|
||||||
go dbclient.Client.FeedbackEnabled.Set(guildId, s.FeedbackEnabled)
|
go dbclient.Client.FeedbackEnabled.Set(context.Background(), guildId, s.FeedbackEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateLanguage(guildId uint64) error {
|
func (s *Settings) updateLanguage(guildId uint64) error {
|
||||||
if s.Language == nil {
|
if s.Language == nil {
|
||||||
return dbclient.Client.ActiveLanguage.Delete(guildId)
|
return dbclient.Client.ActiveLanguage.Delete(context.Background(), guildId)
|
||||||
} else {
|
} else {
|
||||||
return dbclient.Client.ActiveLanguage.Set(guildId, string(*s.Language))
|
return dbclient.Client.ActiveLanguage.Set(context.Background(), guildId, string(*s.Language))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateTicketPermissions(guildId uint64) error {
|
func (s *Settings) updateTicketPermissions(guildId uint64) error {
|
||||||
return dbclient.Client.TicketPermissions.Set(guildId, s.TicketPermissions) // No validation required
|
return dbclient.Client.TicketPermissions.Set(context.Background(), guildId, s.TicketPermissions) // No validation required
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateColours(guildId uint64) error {
|
func (s *Settings) updateColours(guildId uint64) error {
|
||||||
@ -369,12 +369,12 @@ func (s *Settings) updateColours(guildId uint64) error {
|
|||||||
converted[int16(colour)] = int(hex)
|
converted[int16(colour)] = int(hex)
|
||||||
}
|
}
|
||||||
|
|
||||||
return dbclient.Client.CustomColours.BatchSet(guildId, converted)
|
return dbclient.Client.CustomColours.BatchSet(context.Background(), guildId, converted)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Settings) updateAutoClose(guildId uint64) error {
|
func (s *Settings) updateAutoClose(guildId uint64) error {
|
||||||
data := s.AutoCloseSettings.ConvertToDatabase() // Already validated
|
data := s.AutoCloseSettings.ConvertToDatabase() // Already validated
|
||||||
return dbclient.Client.AutoClose.Set(guildId, data)
|
return dbclient.Client.AutoClose.Set(context.Background(), guildId, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d AutoCloseData) ConvertToDatabase() (settings database.AutoCloseSettings) {
|
func (d AutoCloseData) ConvertToDatabase() (settings database.AutoCloseSettings) {
|
||||||
|
@ -23,7 +23,7 @@ func CreateOverrideHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expires := time.Now().Add(time.Hour * time.Duration(body.TimePeriod))
|
expires := time.Now().Add(time.Hour * time.Duration(body.TimePeriod))
|
||||||
if err := database.Client.StaffOverride.Set(guildId, expires); err != nil {
|
if err := database.Client.StaffOverride.Set(ctx, guildId, expires); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
func DeleteOverrideHandler(ctx *gin.Context) {
|
func DeleteOverrideHandler(ctx *gin.Context) {
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
if err := database.Client.StaffOverride.Delete(guildId); err != nil {
|
if err := database.Client.StaffOverride.Delete(ctx, guildId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
func GetOverrideHandler(ctx *gin.Context) {
|
func GetOverrideHandler(ctx *gin.Context) {
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
hasOverride, err := database.Client.StaffOverride.HasActiveOverride(guildId)
|
hasOverride, err := database.Client.StaffOverride.HasActiveOverride(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/TicketsBot/GoPanel/botcontext"
|
||||||
dbclient "github.com/TicketsBot/GoPanel/database"
|
dbclient "github.com/TicketsBot/GoPanel/database"
|
||||||
|
"github.com/TicketsBot/GoPanel/rpc"
|
||||||
"github.com/TicketsBot/GoPanel/utils"
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
"github.com/TicketsBot/GoPanel/utils/types"
|
"github.com/TicketsBot/GoPanel/utils/types"
|
||||||
|
"github.com/TicketsBot/common/premium"
|
||||||
"github.com/TicketsBot/database"
|
"github.com/TicketsBot/database"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
|
"github.com/rxdn/gdl/objects/interaction"
|
||||||
|
"github.com/rxdn/gdl/rest"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tag struct {
|
type tag struct {
|
||||||
Id string `json:"id" validate:"required,min=1,max=16"`
|
Id string `json:"id" validate:"required,min=1,max=16"`
|
||||||
UseGuildCommand bool `json:"use_guild_command"` // Not yet implemented
|
UseGuildCommand bool `json:"use_guild_command"`
|
||||||
Content *string `json:"content" validate:"omitempty,min=1,max=4096"`
|
Content *string `json:"content" validate:"omitempty,min=1,max=4096"`
|
||||||
UseEmbed bool `json:"use_embed"`
|
UseEmbed bool `json:"use_embed"`
|
||||||
Embed *types.CustomEmbed `json:"embed" validate:"omitempty,dive"`
|
Embed *types.CustomEmbed `json:"embed" validate:"omitempty,dive"`
|
||||||
@ -28,7 +34,7 @@ func CreateTag(ctx *gin.Context) {
|
|||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
// Max of 200 tags
|
// Max of 200 tags
|
||||||
count, err := dbclient.Client.Tag.GetTagCount(guildId)
|
count, err := dbclient.Client.Tag.GetTagCount(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -45,6 +51,8 @@ func CreateTag(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.Id = strings.ToLower(data.Id)
|
||||||
|
|
||||||
if !data.UseEmbed {
|
if !data.UseEmbed {
|
||||||
data.Embed = nil
|
data.Embed = nil
|
||||||
}
|
}
|
||||||
@ -62,11 +70,35 @@ func CreateTag(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !data.verifyId() {
|
||||||
|
ctx.JSON(400, utils.ErrorStr("Tag IDs must be alphanumeric (including hyphens and underscores), and be between 1 and 16 characters long"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !data.verifyContent() {
|
if !data.verifyContent() {
|
||||||
ctx.JSON(400, utils.ErrorStr("You have not provided any content for the tag"))
|
ctx.JSON(400, utils.ErrorStr("You have not provided any content for the tag"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
botContext, err := botcontext.ContextForGuild(guildId)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.UseGuildCommand {
|
||||||
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if premiumTier < premium.Premium {
|
||||||
|
ctx.JSON(400, utils.ErrorStr("Premium is required to use custom commands"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var embed *database.CustomEmbedWithFields
|
var embed *database.CustomEmbedWithFields
|
||||||
if data.Embed != nil {
|
if data.Embed != nil {
|
||||||
customEmbed, fields := data.Embed.IntoDatabaseStruct()
|
customEmbed, fields := data.Embed.IntoDatabaseStruct()
|
||||||
@ -76,15 +108,32 @@ func CreateTag(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapped := database.Tag{
|
var applicationCommandId *uint64
|
||||||
Id: data.Id,
|
if data.UseGuildCommand {
|
||||||
GuildId: guildId,
|
cmd, err := botContext.CreateGuildCommand(ctx, guildId, rest.CreateCommandData{
|
||||||
UseGuildCommand: data.UseGuildCommand,
|
Name: data.Id,
|
||||||
Content: data.Content,
|
Description: fmt.Sprintf("Alias for /tag %s", data.Id),
|
||||||
Embed: embed,
|
Options: nil,
|
||||||
|
Type: interaction.ApplicationCommandTypeChatInput,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
applicationCommandId = &cmd.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.Tag.Set(wrapped); err != nil {
|
wrapped := database.Tag{
|
||||||
|
Id: data.Id,
|
||||||
|
GuildId: guildId,
|
||||||
|
Content: data.Content,
|
||||||
|
Embed: embed,
|
||||||
|
ApplicationCommandId: applicationCommandId,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := dbclient.Client.Tag.Set(ctx, wrapped); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TicketsBot/GoPanel/botcontext"
|
||||||
"github.com/TicketsBot/GoPanel/database"
|
"github.com/TicketsBot/GoPanel/database"
|
||||||
"github.com/TicketsBot/GoPanel/utils"
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -25,7 +26,32 @@ func DeleteTag(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.Client.Tag.Delete(guildId, body.TagId); err != nil {
|
// Fetch tag to see if we need to delete a guild command
|
||||||
|
tag, exists, err := database.Client.Tag.Get(ctx, guildId, body.TagId)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
ctx.JSON(404, utils.ErrorStr("Tag not found"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if tag.ApplicationCommandId != nil {
|
||||||
|
botContext, err := botcontext.ContextForGuild(guildId)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := botContext.DeleteGuildCommand(ctx, guildId, *tag.ApplicationCommandId); err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.Client.Tag.Delete(ctx, guildId, body.TagId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
func TagsListHandler(ctx *gin.Context) {
|
func TagsListHandler(ctx *gin.Context) {
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
tags, err := database.Client.Tag.GetByGuild(guildId)
|
tags, err := database.Client.Tag.GetByGuild(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -25,7 +25,7 @@ func TagsListHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
wrapped[id] = tag{
|
wrapped[id] = tag{
|
||||||
Id: data.Id,
|
Id: data.Id,
|
||||||
UseGuildCommand: data.UseGuildCommand,
|
UseGuildCommand: data.ApplicationCommandId != nil,
|
||||||
Content: data.Content,
|
Content: data.Content,
|
||||||
UseEmbed: data.Embed != nil,
|
UseEmbed: data.Embed != nil,
|
||||||
Embed: embed,
|
Embed: embed,
|
||||||
|
@ -57,9 +57,9 @@ func addDefaultMember(ctx *gin.Context, guildId, snowflake uint64, entityType en
|
|||||||
var err error
|
var err error
|
||||||
switch entityType {
|
switch entityType {
|
||||||
case entityTypeUser:
|
case entityTypeUser:
|
||||||
err = dbclient.Client.Permissions.AddSupport(guildId, snowflake)
|
err = dbclient.Client.Permissions.AddSupport(ctx, guildId, snowflake)
|
||||||
case entityTypeRole:
|
case entityTypeRole:
|
||||||
err = dbclient.Client.RolePermissions.AddSupport(guildId, snowflake)
|
err = dbclient.Client.RolePermissions.AddSupport(ctx, guildId, snowflake)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -71,7 +71,7 @@ func addDefaultMember(ctx *gin.Context, guildId, snowflake uint64, entityType en
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addTeamMember(ctx *gin.Context, teamId int, guildId, snowflake uint64, entityType entityType) {
|
func addTeamMember(ctx *gin.Context, teamId int, guildId, snowflake uint64, entityType entityType) {
|
||||||
exists, err := dbclient.Client.SupportTeam.Exists(teamId, guildId)
|
exists, err := dbclient.Client.SupportTeam.Exists(ctx, teamId, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -84,9 +84,9 @@ func addTeamMember(ctx *gin.Context, teamId int, guildId, snowflake uint64, enti
|
|||||||
|
|
||||||
switch entityType {
|
switch entityType {
|
||||||
case entityTypeUser:
|
case entityTypeUser:
|
||||||
err = dbclient.Client.SupportTeamMembers.Add(teamId, snowflake)
|
err = dbclient.Client.SupportTeamMembers.Add(ctx, teamId, snowflake)
|
||||||
case entityTypeRole:
|
case entityTypeRole:
|
||||||
err = dbclient.Client.SupportTeamRoles.Add(teamId, snowflake)
|
err = dbclient.Client.SupportTeamRoles.Add(ctx, teamId, snowflake)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -25,7 +25,7 @@ func CreateTeam(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := dbclient.Client.SupportTeam.Create(guildId, data.Name)
|
id, err := dbclient.Client.SupportTeam.Create(ctx, guildId, data.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -17,7 +17,7 @@ func DeleteTeam(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check team belongs to guild
|
// check team belongs to guild
|
||||||
exists, err := dbclient.Client.SupportTeam.Exists(teamId, guildId)
|
exists, err := dbclient.Client.SupportTeam.Exists(ctx, teamId, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -28,7 +28,7 @@ func DeleteTeam(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.SupportTeam.Delete(teamId); err != nil {
|
if err := dbclient.Client.SupportTeam.Delete(ctx, teamId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -37,13 +37,13 @@ func getDefaultMembers(ctx *gin.Context, guildId uint64) {
|
|||||||
// get IDs of support users & roles
|
// get IDs of support users & roles
|
||||||
var userIds []uint64
|
var userIds []uint64
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
userIds, err = dbclient.Client.Permissions.GetSupport(guildId)
|
userIds, err = dbclient.Client.Permissions.GetSupport(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
var roleIds []uint64
|
var roleIds []uint64
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
roleIds, err = dbclient.Client.RolePermissions.GetSupportRoles(guildId)
|
roleIds, err = dbclient.Client.RolePermissions.GetSupportRoles(ctx, guildId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ func getDefaultMembers(ctx *gin.Context, guildId uint64) {
|
|||||||
|
|
||||||
func getTeamMembers(ctx *gin.Context, teamId int, guildId uint64) {
|
func getTeamMembers(ctx *gin.Context, teamId int, guildId uint64) {
|
||||||
// Verify team exists
|
// Verify team exists
|
||||||
exists, err := dbclient.Client.SupportTeam.Exists(teamId, guildId)
|
exists, err := dbclient.Client.SupportTeam.Exists(ctx, teamId, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -78,13 +78,13 @@ func getTeamMembers(ctx *gin.Context, teamId int, guildId uint64) {
|
|||||||
// get IDs of support users & roles
|
// get IDs of support users & roles
|
||||||
var userIds []uint64
|
var userIds []uint64
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
userIds, err = dbclient.Client.SupportTeamMembers.Get(teamId)
|
userIds, err = dbclient.Client.SupportTeamMembers.Get(ctx, teamId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
var roleIds []uint64
|
var roleIds []uint64
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
roleIds, err = dbclient.Client.SupportTeamRoles.Get(teamId)
|
roleIds, err = dbclient.Client.SupportTeamRoles.Get(ctx, teamId)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
func GetTeams(ctx *gin.Context) {
|
func GetTeams(ctx *gin.Context) {
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
teams, err := dbclient.Client.SupportTeam.Get(guildId)
|
teams, err := dbclient.Client.SupportTeam.Get(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -56,9 +56,9 @@ func removeDefaultMember(ctx *gin.Context, guildId, selfId, snowflake uint64, en
|
|||||||
var err error
|
var err error
|
||||||
switch entityType {
|
switch entityType {
|
||||||
case entityTypeUser:
|
case entityTypeUser:
|
||||||
isAdmin, err = dbclient.Client.Permissions.IsAdmin(guildId, snowflake)
|
isAdmin, err = dbclient.Client.Permissions.IsAdmin(ctx, guildId, snowflake)
|
||||||
case entityTypeRole:
|
case entityTypeRole:
|
||||||
isAdmin, err = dbclient.Client.RolePermissions.IsAdmin(snowflake)
|
isAdmin, err = dbclient.Client.RolePermissions.IsAdmin(ctx, snowflake)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -89,9 +89,9 @@ func removeDefaultMember(ctx *gin.Context, guildId, selfId, snowflake uint64, en
|
|||||||
|
|
||||||
switch entityType {
|
switch entityType {
|
||||||
case entityTypeUser:
|
case entityTypeUser:
|
||||||
err = dbclient.Client.Permissions.RemoveSupport(guildId, snowflake)
|
err = dbclient.Client.Permissions.RemoveSupport(ctx, guildId, snowflake)
|
||||||
case entityTypeRole:
|
case entityTypeRole:
|
||||||
err = dbclient.Client.RolePermissions.RemoveSupport(guildId, snowflake)
|
err = dbclient.Client.RolePermissions.RemoveSupport(ctx, guildId, snowflake)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -100,7 +100,7 @@ func removeDefaultMember(ctx *gin.Context, guildId, selfId, snowflake uint64, en
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove on-call role
|
// Remove on-call role
|
||||||
metadata, err := dbclient.Client.GuildMetadata.Get(guildId)
|
metadata, err := dbclient.Client.GuildMetadata.Get(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -131,7 +131,7 @@ func removeDefaultMember(ctx *gin.Context, guildId, selfId, snowflake uint64, en
|
|||||||
}
|
}
|
||||||
} else if entityType == entityTypeRole {
|
} else if entityType == entityTypeRole {
|
||||||
// Recreate role
|
// Recreate role
|
||||||
if err := dbclient.Client.GuildMetadata.SetOnCallRole(guildId, nil); err != nil {
|
if err := dbclient.Client.GuildMetadata.SetOnCallRole(ctx, guildId, nil); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ func removeDefaultMember(ctx *gin.Context, guildId, selfId, snowflake uint64, en
|
|||||||
}
|
}
|
||||||
|
|
||||||
func removeTeamMember(ctx *gin.Context, teamId int, guildId, snowflake uint64, entityType entityType) {
|
func removeTeamMember(ctx *gin.Context, teamId int, guildId, snowflake uint64, entityType entityType) {
|
||||||
team, exists, err := dbclient.Client.SupportTeam.GetById(guildId, teamId)
|
team, exists, err := dbclient.Client.SupportTeam.GetById(ctx, guildId, teamId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -170,9 +170,9 @@ func removeTeamMember(ctx *gin.Context, teamId int, guildId, snowflake uint64, e
|
|||||||
// Remove from DB
|
// Remove from DB
|
||||||
switch entityType {
|
switch entityType {
|
||||||
case entityTypeUser:
|
case entityTypeUser:
|
||||||
err = dbclient.Client.SupportTeamMembers.Delete(teamId, snowflake)
|
err = dbclient.Client.SupportTeamMembers.Delete(ctx, teamId, snowflake)
|
||||||
case entityTypeRole:
|
case entityTypeRole:
|
||||||
err = dbclient.Client.SupportTeamRoles.Delete(teamId, snowflake)
|
err = dbclient.Client.SupportTeamRoles.Delete(ctx, teamId, snowflake)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -210,7 +210,7 @@ func removeTeamMember(ctx *gin.Context, teamId int, guildId, snowflake uint64, e
|
|||||||
_ = botContext.RemoveGuildMemberRole(context.Background(), guildId, snowflake, *team.OnCallRole)
|
_ = botContext.RemoveGuildMemberRole(context.Background(), guildId, snowflake, *team.OnCallRole)
|
||||||
} else if entityType == entityTypeRole {
|
} else if entityType == entityTypeRole {
|
||||||
// Recreate role
|
// Recreate role
|
||||||
if err := dbclient.Client.SupportTeam.SetOnCallRole(teamId, nil); err != nil {
|
if err := dbclient.Client.SupportTeam.SetOnCallRole(ctx, teamId, nil); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -254,11 +254,11 @@ func createOnCallRole(botContext *botcontext.BotContext, guildId uint64, team *d
|
|||||||
}
|
}
|
||||||
|
|
||||||
if team == nil {
|
if team == nil {
|
||||||
if err := dbclient.Client.GuildMetadata.SetOnCallRole(guildId, &role.Id); err != nil {
|
if err := dbclient.Client.GuildMetadata.SetOnCallRole(context.Background(), guildId, &role.Id); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := dbclient.Client.SupportTeam.SetOnCallRole(team.Id, &role.Id); err != nil {
|
if err := dbclient.Client.SupportTeam.SetOnCallRole(context.Background(), team.Id, &role.Id); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ func CloseTicket(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the ticket struct
|
// Get the ticket struct
|
||||||
ticket, err := database.Client.Tickets.Get(ticketId, guildId)
|
ticket, err := database.Client.Tickets.Get(ctx, ticketId, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, gin.H{
|
ctx.JSON(500, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
|
@ -41,7 +41,7 @@ func GetTicket(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the ticket struct
|
// Get the ticket struct
|
||||||
ticket, err := database.Client.Tickets.Get(ticketId, guildId)
|
ticket, err := database.Client.Tickets.Get(ctx, ticketId, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, gin.H{
|
ctx.JSON(500, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
|
@ -18,13 +18,13 @@ type ticketResponse struct {
|
|||||||
func GetTickets(ctx *gin.Context) {
|
func GetTickets(ctx *gin.Context) {
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
tickets, err := database.Client.Tickets.GetGuildOpenTickets(guildId)
|
tickets, err := database.Client.Tickets.GetGuildOpenTickets(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
panels, err := database.Client.Panel.GetByGuild(guildId)
|
panels, err := database.Client.Panel.GetByGuild(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -68,7 +68,7 @@ func (c *Client) handleAuthEvent(data AuthData) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the ticket
|
// Get the ticket
|
||||||
ticket, err := dbclient.Client.Tickets.Get(c.TicketId, c.GuildId)
|
ticket, err := dbclient.Client.Tickets.Get(context.Background(), c.TicketId, c.GuildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.NewErrorWithMessage(http.StatusInternalServerError, err, "Error retrieving ticket data")
|
return api.NewErrorWithMessage(http.StatusInternalServerError, err, "Error retrieving ticket data")
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ func (c *Client) handleAuthEvent(data AuthData) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify the guild is premium
|
// Verify the guild is premium
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(c.GuildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(context.Background(), c.GuildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.NewErrorWithMessage(http.StatusInternalServerError, err, "Error retrieving premium tier")
|
return api.NewErrorWithMessage(http.StatusInternalServerError, err, "Error retrieving premium tier")
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func SendMessage(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify guild is premium
|
// Verify guild is premium
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(ctx, guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -75,7 +75,7 @@ func SendMessage(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get ticket
|
// Get ticket
|
||||||
ticket, err := database.Client.Tickets.Get(ticketId, guildId)
|
ticket, err := database.Client.Tickets.Get(ctx, ticketId, guildId)
|
||||||
|
|
||||||
// Verify the ticket exists
|
// Verify the ticket exists
|
||||||
if ticket.UserId == 0 {
|
if ticket.UserId == 0 {
|
||||||
@ -100,7 +100,7 @@ func SendMessage(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Preferably send via a webhook
|
// Preferably send via a webhook
|
||||||
webhook, err := database.Client.Webhooks.Get(guildId, ticketId)
|
webhook, err := database.Client.Webhooks.Get(ctx, guildId, ticketId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, gin.H{
|
ctx.JSON(500, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
@ -109,7 +109,7 @@ func SendMessage(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
settings, err := database.Client.Settings.Get(guildId)
|
settings, err := database.Client.Settings.Get(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorStr("Failed to fetch settings"))
|
ctx.JSON(500, utils.ErrorStr("Failed to fetch settings"))
|
||||||
return
|
return
|
||||||
@ -150,7 +150,7 @@ func SendMessage(ctx *gin.Context) {
|
|||||||
// We can delete the webhook in this case
|
// We can delete the webhook in this case
|
||||||
var unwrapped request.RestError
|
var unwrapped request.RestError
|
||||||
if errors.As(err, &unwrapped); unwrapped.StatusCode == 403 || unwrapped.StatusCode == 404 {
|
if errors.As(err, &unwrapped); unwrapped.StatusCode == 403 || unwrapped.StatusCode == 404 {
|
||||||
go database.Client.Webhooks.Delete(guildId, ticketId)
|
go database.Client.Webhooks.Delete(ctx, guildId, ticketId)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.JSON(200, gin.H{
|
ctx.JSON(200, gin.H{
|
||||||
|
@ -22,7 +22,7 @@ func GetTranscriptHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get ticket object
|
// get ticket object
|
||||||
ticket, err := dbclient.Client.Tickets.Get(ticketId, guildId)
|
ticket, err := dbclient.Client.Tickets.Get(ctx, ticketId, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, gin.H{
|
ctx.JSON(500, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
@ -37,7 +37,7 @@ func ListTranscripts(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tickets, err := dbclient.Client.Tickets.GetByOptions(opts)
|
tickets, err := dbclient.Client.Tickets.GetByOptions(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -82,14 +82,14 @@ func ListTranscripts(ctx *gin.Context) {
|
|||||||
ticketIds[i] = ticket.Id
|
ticketIds[i] = ticket.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
ratings, err := dbclient.Client.ServiceRatings.GetMulti(guildId, ticketIds)
|
ratings, err := dbclient.Client.ServiceRatings.GetMulti(ctx, guildId, ticketIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get close reasons
|
// Get close reasons
|
||||||
closeReasons, err := dbclient.Client.CloseReason.GetMulti(guildId, ticketIds)
|
closeReasons, err := dbclient.Client.CloseReason.GetMulti(ctx, guildId, ticketIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -37,7 +37,7 @@ func ListSelfTranscripts(ctx *gin.Context) {
|
|||||||
Offset: offset,
|
Offset: offset,
|
||||||
}
|
}
|
||||||
|
|
||||||
tickets, err := dbclient.Client.Tickets.GetByOptions(opts)
|
tickets, err := dbclient.Client.Tickets.GetByOptions(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -22,7 +22,7 @@ func GetTranscriptRenderHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get ticket object
|
// get ticket object
|
||||||
ticket, err := dbclient.Client.Tickets.Get(ticketId, guildId)
|
ticket, err := dbclient.Client.Tickets.Get(ctx, ticketId, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, gin.H{
|
ctx.JSON(500, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
@ -11,7 +11,7 @@ func WhitelabelDelete(ctx *gin.Context) {
|
|||||||
userId := ctx.Keys["userid"].(uint64)
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
|
|
||||||
// Check if this is a different token
|
// Check if this is a different token
|
||||||
if err := database.Client.Whitelabel.Delete(userId); err != nil {
|
if err := database.Client.Whitelabel.Delete(ctx, userId); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func GetWhitelabelCreateInteractions() func(*gin.Context) {
|
|||||||
userId := ctx.Keys["userid"].(uint64)
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
|
|
||||||
// Get bot
|
// Get bot
|
||||||
bot, err := database.Client.Whitelabel.GetByUserId(userId)
|
bot, err := database.Client.Whitelabel.GetByUserId(ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -20,7 +20,7 @@ func WhitelabelGet(ctx *gin.Context) {
|
|||||||
userId := ctx.Keys["userid"].(uint64)
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
|
|
||||||
// Check if this is a different token
|
// Check if this is a different token
|
||||||
bot, err := database.Client.Whitelabel.GetByUserId(userId)
|
bot, err := database.Client.Whitelabel.GetByUserId(ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -32,14 +32,14 @@ func WhitelabelGet(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get public key
|
// Get public key
|
||||||
publicKey, err := database.Client.WhitelabelKeys.Get(bot.BotId)
|
publicKey, err := database.Client.WhitelabelKeys.Get(ctx, bot.BotId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get status
|
// Get status
|
||||||
status, statusType, _, err := database.Client.WhitelabelStatuses.Get(bot.BotId)
|
status, statusType, _, err := database.Client.WhitelabelStatuses.Get(ctx, bot.BotId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
func WhitelabelGetErrors(ctx *gin.Context) {
|
func WhitelabelGetErrors(ctx *gin.Context) {
|
||||||
userId := ctx.Keys["userid"].(uint64)
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
|
|
||||||
errors, err := database.Client.WhitelabelErrors.GetRecent(userId, 10)
|
errors, err := database.Client.WhitelabelErrors.GetRecent(ctx, userId, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -14,14 +14,14 @@ import (
|
|||||||
func WhitelabelGetGuilds(ctx *gin.Context) {
|
func WhitelabelGetGuilds(ctx *gin.Context) {
|
||||||
userId := ctx.Keys["userid"].(uint64)
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
|
|
||||||
bot, err := database.Client.Whitelabel.GetByUserId(userId)
|
bot, err := database.Client.Whitelabel.GetByUserId(ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// id -> name
|
// id -> name
|
||||||
guilds := make(map[string]string, 0)
|
guilds := make(map[string]string)
|
||||||
if bot.BotId == 0 {
|
if bot.BotId == 0 {
|
||||||
ctx.JSON(404, gin.H{
|
ctx.JSON(404, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
@ -30,7 +30,7 @@ func WhitelabelGetGuilds(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ids, err := database.Client.WhitelabelGuilds.GetGuilds(bot.BotId)
|
ids, err := database.Client.WhitelabelGuilds.GetGuilds(ctx, bot.BotId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -46,7 +46,7 @@ func WhitelabelPost() func(*gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is a different token
|
// Check if this is a different token
|
||||||
existing, err := dbclient.Client.Whitelabel.GetByUserId(userId)
|
existing, err := dbclient.Client.Whitelabel.GetByUserId(ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -59,7 +59,7 @@ func WhitelabelPost() func(*gin.Context) {
|
|||||||
|
|
||||||
// Set token in DB so that http-gateway can use it when Discord validates the interactions endpoint
|
// Set token in DB so that http-gateway can use it when Discord validates the interactions endpoint
|
||||||
// TODO: Use a transaction
|
// TODO: Use a transaction
|
||||||
if err := dbclient.Client.Whitelabel.Set(database.WhitelabelBot{
|
if err := dbclient.Client.Whitelabel.Set(ctx, database.WhitelabelBot{
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
BotId: bot.Id,
|
BotId: bot.Id,
|
||||||
Token: data.Token,
|
Token: data.Token,
|
||||||
@ -68,7 +68,7 @@ func WhitelabelPost() func(*gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dbclient.Client.WhitelabelKeys.Set(bot.Id, bot.VerifyKey); err != nil {
|
if err := dbclient.Client.WhitelabelKeys.Set(ctx, bot.Id, bot.VerifyKey); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ func WhitelabelPost() func(*gin.Context) {
|
|||||||
|
|
||||||
if _, err := rest.EditCurrentApplication(context.Background(), data.Token, nil, editData); err != nil {
|
if _, err := rest.EditCurrentApplication(context.Background(), data.Token, nil, editData); err != nil {
|
||||||
// TODO: Use a transaction
|
// TODO: Use a transaction
|
||||||
if err := dbclient.Client.Whitelabel.Delete(bot.Id); err != nil {
|
if err := dbclient.Client.Whitelabel.Delete(ctx, bot.Id); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ func WhitelabelStatusPost(ctx *gin.Context) {
|
|||||||
userId := ctx.Keys["userid"].(uint64)
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
|
|
||||||
// Get bot
|
// Get bot
|
||||||
bot, err := database.Client.Whitelabel.GetByUserId(userId)
|
bot, err := database.Client.Whitelabel.GetByUserId(ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
@ -56,7 +56,7 @@ func WhitelabelStatusPost(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update in database
|
// Update in database
|
||||||
if err := database.Client.WhitelabelStatuses.Set(bot.BotId, data.Status, int16(data.StatusType)); err != nil {
|
if err := database.Client.WhitelabelStatuses.Set(ctx, bot.BotId, data.Status, int16(data.StatusType)); err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ func VerifyWhitelabel(isApi bool) func(ctx *gin.Context) {
|
|||||||
return func(ctx *gin.Context) {
|
return func(ctx *gin.Context) {
|
||||||
userId := ctx.Keys["userid"].(uint64)
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
|
|
||||||
tier, err := rpc.PremiumClient.GetTierByUser(userId, false)
|
tier, err := rpc.PremiumClient.GetTierByUser(ctx, userId, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -36,7 +36,7 @@ func (c *BotContext) Cache() permission.PermissionCache {
|
|||||||
return permission.NewRedisCache(redis.Client.Client)
|
return permission.NewRedisCache(redis.Client.Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BotContext) IsBotAdmin(userId uint64) bool {
|
func (c *BotContext) IsBotAdmin(_ context.Context, userId uint64) bool {
|
||||||
for _, id := range config.Conf.Admins {
|
for _, id := range config.Conf.Admins {
|
||||||
if id == userId {
|
if id == userId {
|
||||||
return true
|
return true
|
||||||
@ -65,18 +65,18 @@ func (c *BotContext) GetGuild(ctx context.Context, guildId uint64) (guild.Guild,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BotContext) GetGuildOwner(guildId uint64) (uint64, error) {
|
func (c *BotContext) GetGuildOwner(ctx context.Context, guildId uint64) (uint64, error) {
|
||||||
cachedOwner, err := cacheclient.Instance.GetGuildOwner(context.Background(), guildId)
|
cachedOwner, err := cacheclient.Instance.GetGuildOwner(ctx, guildId)
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return cachedOwner, nil
|
return cachedOwner, nil
|
||||||
case errors.Is(err, cache.ErrNotFound):
|
case errors.Is(err, cache.ErrNotFound):
|
||||||
guild, err := c.GetGuild(context.Background(), guildId)
|
guild, err := c.GetGuild(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cacheclient.Instance.StoreGuild(context.Background(), guild); err != nil {
|
if err := cacheclient.Instance.StoreGuild(ctx, guild); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package botcontext
|
package botcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TicketsBot/GoPanel/config"
|
"github.com/TicketsBot/GoPanel/config"
|
||||||
dbclient "github.com/TicketsBot/GoPanel/database"
|
dbclient "github.com/TicketsBot/GoPanel/database"
|
||||||
@ -10,13 +11,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ContextForGuild(guildId uint64) (*BotContext, error) {
|
func ContextForGuild(guildId uint64) (*BotContext, error) {
|
||||||
whitelabelBotId, isWhitelabel, err := dbclient.Client.WhitelabelGuilds.GetBotByGuild(guildId)
|
whitelabelBotId, isWhitelabel, err := dbclient.Client.WhitelabelGuilds.GetBotByGuild(context.Background(), guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if isWhitelabel {
|
if isWhitelabel {
|
||||||
res, err := dbclient.Client.Whitelabel.GetByBotId(whitelabelBotId)
|
res, err := dbclient.Client.Whitelabel.GetByBotId(context.Background(), whitelabelBotId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,26 @@
|
|||||||
<div class:col-1={col1} class:col-2={col2} class:col-3={col3} class:col-4={col4}>
|
<div class:col-1={col1} class:col-2={col2} class:col-3={col3} class:col-4={col4}>
|
||||||
<slot name="label">
|
<div class="label-wrapper">
|
||||||
<label for="input" class="form-label">
|
<slot name="label">
|
||||||
{label}
|
<label for="input" class="form-label">
|
||||||
</label>
|
{label}
|
||||||
</slot>
|
</label>
|
||||||
|
</slot>
|
||||||
|
{#if premiumBadge}
|
||||||
|
<div style="margin-bottom: 5px">
|
||||||
|
<PremiumBadge />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
<input id="input" class="form-checkbox" type=checkbox bind:checked={value} on:change {disabled}>
|
<input id="input" class="form-checkbox" type=checkbox bind:checked={value} on:change {disabled}>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import PremiumBadge from "../PremiumBadge.svelte";
|
||||||
|
|
||||||
export let value;
|
export let value;
|
||||||
export let label;
|
export let label;
|
||||||
export let disabled = false;
|
export let disabled = false;
|
||||||
|
export let premiumBadge = false;
|
||||||
|
|
||||||
export let col1 = false;
|
export let col1 = false;
|
||||||
export let col2 = false;
|
export let col2 = false;
|
||||||
@ -24,4 +34,11 @@
|
|||||||
width: 40px;
|
width: 40px;
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.label-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 4px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
<ConfirmationModal icon="fas fa-floppy-disk" on:confirm={() => dispatch("confirm", data)} on:cancel={() => dispatch("cancel", {})}>
|
<ConfirmationModal icon="fas fa-floppy-disk" on:confirm={() => dispatch("confirm", data)} on:cancel={() => dispatch("cancel", {})}>
|
||||||
<span slot="title">Tag Editor</span>
|
<span slot="title">Tag Editor</span>
|
||||||
<div slot="body" class="body-wrapper">
|
<div slot="body" class="body-wrapper">
|
||||||
<div class="row">
|
<div class="row"">
|
||||||
<Input col4 label="Tag ID" placeholder="docs" bind:value={data.id}
|
<Input col4 label="Tag ID" placeholder="docs" bind:value={data.id}
|
||||||
tooltipText='If the command is "/tag docs", then the ID is "docs"'/>
|
tooltipText='If the command is "/tag docs", then the ID is "docs"'/>
|
||||||
|
<Checkbox col2 label="Create Custom Command Alias" bind:value={data.use_guild_command}
|
||||||
|
disabled={!isPremium} premiumBadge={true} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -44,6 +46,7 @@
|
|||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
export let isPremium;
|
||||||
|
|
||||||
function handleKeydown(e) {
|
function handleKeydown(e) {
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{#if tagCreateModal}
|
{#if tagCreateModal}
|
||||||
<TagEditor on:cancel={() => tagCreateModal = false} on:confirm={createTag}/>
|
<TagEditor {isPremium} on:cancel={() => tagCreateModal = false} on:confirm={createTag}/>
|
||||||
{:else if tagEditModal}
|
{:else if tagEditModal}
|
||||||
<TagEditor bind:data={editData} on:cancel={cancelEdit} on:confirm={editTag}/>
|
<TagEditor {isPremium} bind:data={editData} on:cancel={cancelEdit} on:confirm={editTag}/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="parent">
|
<div class="parent">
|
||||||
@ -51,6 +51,7 @@
|
|||||||
export let currentRoute;
|
export let currentRoute;
|
||||||
let guildId = currentRoute.namedParams.id;
|
let guildId = currentRoute.namedParams.id;
|
||||||
|
|
||||||
|
let isPremium = false;
|
||||||
let tags = {};
|
let tags = {};
|
||||||
let editData;
|
let editData;
|
||||||
let editId;
|
let editId;
|
||||||
@ -164,11 +165,29 @@
|
|||||||
for (const id in tags) {
|
for (const id in tags) {
|
||||||
tags[id].use_embed = tags[id].embed !== null;
|
tags[id].use_embed = tags[id].embed !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isPremium) {
|
||||||
|
for (const id in tags) {
|
||||||
|
tag[id].use_guild_commands = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadPremium() {
|
||||||
|
const res = await axios.get(`${API_URL}/api/${guildId}/premium`);
|
||||||
|
if (res.status !== 200) {
|
||||||
|
notifyError(res.data.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isPremium = res.data.premium;
|
||||||
}
|
}
|
||||||
|
|
||||||
withLoadingScreen(async () => {
|
withLoadingScreen(async () => {
|
||||||
setDefaultHeaders();
|
setDefaultHeaders();
|
||||||
await loadTags();
|
|
||||||
|
await loadPremium();
|
||||||
|
await loadTags(); // Depends on isPremium
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
6
go.mod
6
go.mod
@ -7,10 +7,10 @@ toolchain go1.22.4
|
|||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.2.1
|
github.com/BurntSushi/toml v1.2.1
|
||||||
github.com/TicketsBot/archiverclient v0.0.0-20240613013458-accc062facc2
|
github.com/TicketsBot/archiverclient v0.0.0-20240613013458-accc062facc2
|
||||||
github.com/TicketsBot/common v0.0.0-20240613013221-1e27eb8bfe37
|
github.com/TicketsBot/common v0.0.0-20240710005307-9cc26f78d8e3
|
||||||
github.com/TicketsBot/database v0.0.0-20240622123318-f2e43bd962cb
|
github.com/TicketsBot/database v0.0.0-20240720222825-35466fd5fc96
|
||||||
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c
|
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c
|
||||||
github.com/TicketsBot/worker v0.0.0-20240709182730-429809492f5e
|
github.com/TicketsBot/worker v0.0.0-20240720223640-84817ecc3309
|
||||||
github.com/apex/log v1.1.2
|
github.com/apex/log v1.1.2
|
||||||
github.com/getsentry/sentry-go v0.24.0
|
github.com/getsentry/sentry-go v0.24.0
|
||||||
github.com/gin-gonic/contrib v0.0.0-20191209060500-d6e26eeaa607
|
github.com/gin-gonic/contrib v0.0.0-20191209060500-d6e26eeaa607
|
||||||
|
12
go.sum
12
go.sum
@ -47,14 +47,26 @@ github.com/TicketsBot/archiverclient v0.0.0-20240613013458-accc062facc2 h1:x2AZW
|
|||||||
github.com/TicketsBot/archiverclient v0.0.0-20240613013458-accc062facc2/go.mod h1:sc1kAppJn1fX6ZCsiU3ltGiXIj9GEZkjkdh8fbmwxWQ=
|
github.com/TicketsBot/archiverclient v0.0.0-20240613013458-accc062facc2/go.mod h1:sc1kAppJn1fX6ZCsiU3ltGiXIj9GEZkjkdh8fbmwxWQ=
|
||||||
github.com/TicketsBot/common v0.0.0-20240613013221-1e27eb8bfe37 h1:NC5fn+uAup0JxLiX85+bjVdyfUUXW3pKZYmp72/29hw=
|
github.com/TicketsBot/common v0.0.0-20240613013221-1e27eb8bfe37 h1:NC5fn+uAup0JxLiX85+bjVdyfUUXW3pKZYmp72/29hw=
|
||||||
github.com/TicketsBot/common v0.0.0-20240613013221-1e27eb8bfe37/go.mod h1:UZ6Kzobh9akWyon7iGLPb4w/9gmKV+sLuR6PmthsS+U=
|
github.com/TicketsBot/common v0.0.0-20240613013221-1e27eb8bfe37/go.mod h1:UZ6Kzobh9akWyon7iGLPb4w/9gmKV+sLuR6PmthsS+U=
|
||||||
|
github.com/TicketsBot/common v0.0.0-20240710005307-9cc26f78d8e3 h1:Z4Ri2MC03YqLO+gY32SuWzt8SIL+QqwQYs59iizr7k8=
|
||||||
|
github.com/TicketsBot/common v0.0.0-20240710005307-9cc26f78d8e3/go.mod h1:W1AwQkgiRyLxrpf8civa7p5ksKOGCyS0QocT5CPZVq8=
|
||||||
github.com/TicketsBot/database v0.0.0-20240622123318-f2e43bd962cb h1://4tzbjko/3ji+9lrp0tHGtBWavvJusBkfxmmLEIigs=
|
github.com/TicketsBot/database v0.0.0-20240622123318-f2e43bd962cb h1://4tzbjko/3ji+9lrp0tHGtBWavvJusBkfxmmLEIigs=
|
||||||
github.com/TicketsBot/database v0.0.0-20240622123318-f2e43bd962cb/go.mod h1:gAtOoQKZfCkQ4AoNWQUSl51Fnlqk+odzD/hZ1e1sXyI=
|
github.com/TicketsBot/database v0.0.0-20240622123318-f2e43bd962cb/go.mod h1:gAtOoQKZfCkQ4AoNWQUSl51Fnlqk+odzD/hZ1e1sXyI=
|
||||||
|
github.com/TicketsBot/database v0.0.0-20240715172214-86ee61a85834/go.mod h1:gAtOoQKZfCkQ4AoNWQUSl51Fnlqk+odzD/hZ1e1sXyI=
|
||||||
|
github.com/TicketsBot/database v0.0.0-20240720222825-35466fd5fc96 h1:iOf8LxG3y7v5d5FErpc2i9gRzYN5wJzbd63iBTIllYY=
|
||||||
|
github.com/TicketsBot/database v0.0.0-20240720222825-35466fd5fc96/go.mod h1:gAtOoQKZfCkQ4AoNWQUSl51Fnlqk+odzD/hZ1e1sXyI=
|
||||||
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c h1:OqGjFH6mbE6gd+NqI2ARJdtH3UUvhiAkD0r0fhGJK2s=
|
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c h1:OqGjFH6mbE6gd+NqI2ARJdtH3UUvhiAkD0r0fhGJK2s=
|
||||||
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c/go.mod h1:jgi2OXQKsd5nUnTIRkwvPmeuD/i7OhN68LKMssuQY1c=
|
github.com/TicketsBot/logarchiver v0.0.0-20220326162808-cdf0310f5e1c/go.mod h1:jgi2OXQKsd5nUnTIRkwvPmeuD/i7OhN68LKMssuQY1c=
|
||||||
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM=
|
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM=
|
||||||
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261/go.mod h1:2zPxDAN2TAPpxUPjxszjs3QFKreKrQh5al/R3cMXmYk=
|
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261/go.mod h1:2zPxDAN2TAPpxUPjxszjs3QFKreKrQh5al/R3cMXmYk=
|
||||||
|
github.com/TicketsBot/worker v0.0.0-20240709182702-fbfec6b1b10a h1:G4Ma9QlWbAogjWIgAYQDrn5O5A4QmDN4flVv4FFUVJ4=
|
||||||
|
github.com/TicketsBot/worker v0.0.0-20240709182702-fbfec6b1b10a/go.mod h1:v3MELoiC3pcso5wgAm4XSF2hFSSAKx208nmk3E0FUEw=
|
||||||
github.com/TicketsBot/worker v0.0.0-20240709182730-429809492f5e h1:3qpH34ZlTZU2u7cKfUAQQFCCzMP6YNcwK+U0oUHmvHo=
|
github.com/TicketsBot/worker v0.0.0-20240709182730-429809492f5e h1:3qpH34ZlTZU2u7cKfUAQQFCCzMP6YNcwK+U0oUHmvHo=
|
||||||
github.com/TicketsBot/worker v0.0.0-20240709182730-429809492f5e/go.mod h1:dSZB/NnwAykwleOEx6VmvDxcY96+JjdQtVh95zs0wLo=
|
github.com/TicketsBot/worker v0.0.0-20240709182730-429809492f5e/go.mod h1:dSZB/NnwAykwleOEx6VmvDxcY96+JjdQtVh95zs0wLo=
|
||||||
|
github.com/TicketsBot/worker v0.0.0-20240716011908-6750831195fe h1:W/GhCASTuox8JroIa7nNAnGzqJe4/qkdcd+d0YXY+aw=
|
||||||
|
github.com/TicketsBot/worker v0.0.0-20240716011908-6750831195fe/go.mod h1:JKke725voiVNSnNRE2VkdeRUFehzCGHxa4TzJfJmHes=
|
||||||
|
github.com/TicketsBot/worker v0.0.0-20240720222927-f8792f3dec68/go.mod h1:JKke725voiVNSnNRE2VkdeRUFehzCGHxa4TzJfJmHes=
|
||||||
|
github.com/TicketsBot/worker v0.0.0-20240720223640-84817ecc3309 h1:KR5YkLLZJwD6MHN/0lygDfNfjO7OJeywOYjqAb4RDyo=
|
||||||
|
github.com/TicketsBot/worker v0.0.0-20240720223640-84817ecc3309/go.mod h1:0E2EZSbwyaWo438KB7YnqiDxrJEdQECZXsfSmn4+7tY=
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
|
@ -39,5 +39,5 @@ func LoadGuilds(accessToken string, userId uint64) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return dbclient.Client.UserGuilds.Set(userId, wrappedGuilds)
|
return dbclient.Client.UserGuilds.Set(context.Background(), userId, wrappedGuilds)
|
||||||
}
|
}
|
||||||
|
@ -18,19 +18,19 @@ func GetPermissionLevel(ctx context.Context, guildId, userId uint64) (permission
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do this check here before trying to get the member
|
// do this check here before trying to get the member
|
||||||
if botContext.IsBotAdmin(userId) {
|
if botContext.IsBotAdmin(ctx, userId) {
|
||||||
return permission.Admin, nil
|
return permission.Admin, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check staff override
|
// Check staff override
|
||||||
staffOverride, err := dbclient.Client.StaffOverride.HasActiveOverride(guildId)
|
staffOverride, err := dbclient.Client.StaffOverride.HasActiveOverride(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return permission.Everyone, err
|
return permission.Everyone, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If staff override enabled and the user is bot staff, grant admin permissions
|
// If staff override enabled and the user is bot staff, grant admin permissions
|
||||||
if staffOverride {
|
if staffOverride {
|
||||||
isBotStaff, err := dbclient.Client.BotStaff.IsStaff(userId)
|
isBotStaff, err := dbclient.Client.BotStaff.IsStaff(ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return permission.Everyone, err
|
return permission.Everyone, err
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ func GetPermissionLevel(ctx context.Context, guildId, userId uint64) (permission
|
|||||||
return permission.Everyone, err
|
return permission.Everyone, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return permission.GetPermissionLevel(botContext, member, guildId)
|
return permission.GetPermissionLevel(ctx, botContext, member, guildId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use this on the ticket list
|
// TODO: Use this on the ticket list
|
||||||
@ -62,19 +62,19 @@ func HasPermissionToViewTicket(ctx context.Context, guildId, userId uint64, tick
|
|||||||
return false, api.NewInternalServerError(err, "Error retrieving guild context")
|
return false, api.NewInternalServerError(err, "Error retrieving guild context")
|
||||||
}
|
}
|
||||||
|
|
||||||
if botContext.IsBotAdmin(userId) {
|
if botContext.IsBotAdmin(ctx, userId) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check staff override
|
// Check staff override
|
||||||
staffOverride, err := dbclient.Client.StaffOverride.HasActiveOverride(guildId)
|
staffOverride, err := dbclient.Client.StaffOverride.HasActiveOverride(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, api.NewDatabaseError(err)
|
return false, api.NewDatabaseError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If staff override enabled and the user is bot staff, grant admin permissions
|
// If staff override enabled and the user is bot staff, grant admin permissions
|
||||||
if staffOverride {
|
if staffOverride {
|
||||||
isBotStaff, err := dbclient.Client.BotStaff.IsStaff(userId)
|
isBotStaff, err := dbclient.Client.BotStaff.IsStaff(ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, api.NewDatabaseError(err)
|
return false, api.NewDatabaseError(err)
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ func HasPermissionToViewTicket(ctx context.Context, guildId, userId uint64, tick
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Admins should have access to all tickets
|
// Admins should have access to all tickets
|
||||||
isAdmin, err := dbclient.Client.Permissions.IsAdmin(guildId, userId)
|
isAdmin, err := dbclient.Client.Permissions.IsAdmin(ctx, guildId, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, api.NewDatabaseError(err)
|
return false, api.NewDatabaseError(err)
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ func HasPermissionToViewTicket(ctx context.Context, guildId, userId uint64, tick
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Check in db
|
// TODO: Check in db
|
||||||
adminRoles, err := dbclient.Client.RolePermissions.GetAdminRoles(guildId)
|
adminRoles, err := dbclient.Client.RolePermissions.GetAdminRoles(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, api.NewDatabaseError(err)
|
return false, api.NewDatabaseError(err)
|
||||||
}
|
}
|
||||||
@ -123,20 +123,20 @@ func HasPermissionToViewTicket(ctx context.Context, guildId, userId uint64, tick
|
|||||||
|
|
||||||
// If ticket is not from a panel, we can use default team perms
|
// If ticket is not from a panel, we can use default team perms
|
||||||
if ticket.PanelId == nil {
|
if ticket.PanelId == nil {
|
||||||
canView, err := isOnDefaultTeam(guildId, member)
|
canView, err := isOnDefaultTeam(ctx, guildId, member)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return canView, nil
|
return canView, nil
|
||||||
} else {
|
} else {
|
||||||
panel, err := dbclient.Client.Panel.GetById(*ticket.PanelId)
|
panel, err := dbclient.Client.Panel.GetById(ctx, *ticket.PanelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, api.NewDatabaseError(err)
|
return false, api.NewDatabaseError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if panel.WithDefaultTeam {
|
if panel.WithDefaultTeam {
|
||||||
canView, err := isOnDefaultTeam(guildId, member)
|
canView, err := isOnDefaultTeam(ctx, guildId, member)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ func HasPermissionToViewTicket(ctx context.Context, guildId, userId uint64, tick
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If panel does not use the default team, or the user is not assigned to it, check support teams
|
// If panel does not use the default team, or the user is not assigned to it, check support teams
|
||||||
supportTeams, err := dbclient.Client.PanelTeams.GetTeams(*ticket.PanelId)
|
supportTeams, err := dbclient.Client.PanelTeams.GetTeams(ctx, *ticket.PanelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, api.NewDatabaseError(err)
|
return false, api.NewDatabaseError(err)
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ func HasPermissionToViewTicket(ctx context.Context, guildId, userId uint64, tick
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is added to support team directly
|
// Check if user is added to support team directly
|
||||||
isSupport, err := dbclient.Client.SupportTeamMembers.IsSupportSubset(guildId, userId, supportTeamIds)
|
isSupport, err := dbclient.Client.SupportTeamMembers.IsSupportSubset(ctx, guildId, userId, supportTeamIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, api.NewDatabaseError(err)
|
return false, api.NewDatabaseError(err)
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@ func HasPermissionToViewTicket(ctx context.Context, guildId, userId uint64, tick
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is added to support team via a role
|
// Check if user is added to support team via a role
|
||||||
isSupport, err = dbclient.Client.SupportTeamRoles.IsSupportAnySubset(guildId, member.Roles, supportTeamIds)
|
isSupport, err = dbclient.Client.SupportTeamRoles.IsSupportAnySubset(ctx, guildId, member.Roles, supportTeamIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, api.NewDatabaseError(err)
|
return false, api.NewDatabaseError(err)
|
||||||
}
|
}
|
||||||
@ -183,10 +183,10 @@ func HasPermissionToViewTicket(ctx context.Context, guildId, userId uint64, tick
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isOnDefaultTeam(guildId uint64, member member.Member) (bool, *api.RequestError) {
|
func isOnDefaultTeam(ctx context.Context, guildId uint64, member member.Member) (bool, *api.RequestError) {
|
||||||
// Admin perms are already checked straight away, so we don't need to check for them here
|
// Admin perms are already checked straight away, so we don't need to check for them here
|
||||||
// Check user perms for support
|
// Check user perms for support
|
||||||
if isSupport, err := dbclient.Client.Permissions.IsSupport(guildId, member.User.Id); err == nil {
|
if isSupport, err := dbclient.Client.Permissions.IsSupport(ctx, guildId, member.User.Id); err == nil {
|
||||||
if isSupport {
|
if isSupport {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ func isOnDefaultTeam(guildId uint64, member member.Member) (bool, *api.RequestEr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check DB for support roles
|
// Check DB for support roles
|
||||||
supportRoles, err := dbclient.Client.RolePermissions.GetSupportRoles(guildId)
|
supportRoles, err := dbclient.Client.RolePermissions.GetSupportRoles(ctx, guildId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, api.NewDatabaseError(err)
|
return false, api.NewDatabaseError(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user