mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-08 12:48:09 +00:00
Backport #34084 by @Mopcho Fixes [#34027](https://github.com/go-gitea/gitea/issues/34027) Discord does not allow for description bigger than 2048 bytes. If the description is bigger than that it will throw 400 and the event won't appear in discord. To fix that, in the createPayload method we now slice the description to ensure it doesn’t exceed the limit. --------- Co-authored-by: Mopcho <47301161+Mopcho@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
0e6489317e
commit
66ccae8b90
@ -14,6 +14,7 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
@ -101,6 +102,13 @@ var (
|
||||
redColor = color("ff3232")
|
||||
)
|
||||
|
||||
// https://discord.com/developers/docs/resources/message#embed-object-embed-limits
|
||||
// Discord has some limits in place for the embeds.
|
||||
// According to some tests, there is no consistent limit for different character sets.
|
||||
// For example: 4096 ASCII letters are allowed, but only 2490 emoji characters are allowed.
|
||||
// To keep it simple, we currently truncate at 2000.
|
||||
const discordDescriptionCharactersLimit = 2000
|
||||
|
||||
type discordConvertor struct {
|
||||
Username string
|
||||
AvatarURL string
|
||||
@ -307,7 +315,7 @@ func (d discordConvertor) createPayload(s *api.User, title, text, url string, co
|
||||
Embeds: []DiscordEmbed{
|
||||
{
|
||||
Title: title,
|
||||
Description: text,
|
||||
Description: base.TruncateString(text, discordDescriptionCharactersLimit),
|
||||
URL: url,
|
||||
Color: color,
|
||||
Author: DiscordEmbedAuthor{
|
||||
|
Loading…
x
Reference in New Issue
Block a user