Skip to content

Commit

Permalink
Replace ZWNJ nonsense with new LinkPreviewOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Brawl345 committed Jan 24, 2024
1 parent f69e4ea commit bebf834
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
8 changes: 5 additions & 3 deletions plugin/covid/covid.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ func OnCountry(b *gotgbot.Bot, c plugin.GobotContext) error {
}

var sb strings.Builder
if result.CountryInfo.Flag != "" {
sb.WriteString(utils.EmbedImage(result.CountryInfo.Flag))
}

sb.WriteString(
fmt.Sprintf(
Expand Down Expand Up @@ -202,6 +199,11 @@ func OnCountry(b *gotgbot.Bot, c plugin.GobotContext) error {
)

_, err = c.EffectiveMessage.Reply(b, sb.String(), &gotgbot.SendMessageOpts{
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: result.CountryInfo.Flag == "",
Url: result.CountryInfo.Flag,
PreferLargeMedia: true,
},
ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true},
ParseMode: gotgbot.ParseModeHTML,
})
Expand Down
13 changes: 5 additions & 8 deletions plugin/myanimelist/myanimelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,6 @@ func (p *Plugin) onAnime(b *gotgbot.Bot, c plugin.GobotContext) error {
}

var sb strings.Builder
disableWebPagePreview := true

// Main Picture
if anime.GetMainPicture() != "" && !anime.NSFW() {
disableWebPagePreview = false
sb.WriteString(utils.EmbedImage(anime.GetMainPicture()))
}

// Title
sb.WriteString(
Expand Down Expand Up @@ -391,7 +384,11 @@ func (p *Plugin) onAnime(b *gotgbot.Bot, c plugin.GobotContext) error {
}

_, err = c.EffectiveMessage.Reply(b, sb.String(), &gotgbot.SendMessageOpts{
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{IsDisabled: disableWebPagePreview},
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
IsDisabled: anime.GetMainPicture() == "" || anime.NSFW(),
Url: anime.GetMainPicture(),
PreferLargeMedia: true,
},
ParseMode: gotgbot.ParseModeHTML,
ReplyParameters: &gotgbot.ReplyParameters{AllowSendingWithoutReply: true},
DisableNotification: true,
Expand Down
4 changes: 3 additions & 1 deletion plugin/twitter/twitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,10 @@ func (p *Plugin) OnStatus(b *gotgbot.Bot, c plugin.GobotContext) error {
media := result.Legacy.ExtendedEntities.Media
if len(media) == 1 && (media[0].IsPhoto() || media[0].IsGIF()) { // One picture or GIF = send as preview
sendOptions.LinkPreviewOptions.IsDisabled = false
sendOptions.LinkPreviewOptions.Url = media[0].Link()
sendOptions.LinkPreviewOptions.PreferLargeMedia = true
_, err := c.EffectiveMessage.Reply(b,
utils.EmbedImage(media[0].Link())+sb.String(),
sb.String(),
sendOptions,
)
return err
Expand Down
12 changes: 0 additions & 12 deletions utils/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ func FormatFloat(f float64) string {
return fmt.Sprintf("%s,%02d", result.String(), fractionalPart)
}

func EmbedImage(url string) string {
var sb strings.Builder

sb.WriteString("<a href=\"")
sb.WriteString(url)
sb.WriteString("\">")
sb.WriteString("\u200c") // ZWNJ
sb.WriteString("</a>")

return sb.String()
}

func EmbedGUID(guid string) string {
var sb strings.Builder
sb.WriteString("\n")
Expand Down

0 comments on commit bebf834

Please sign in to comment.