hacer el arreglo bien
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Cat /dev/Nulo 2023-05-09 20:59:23 -03:00
parent 80a0a7d6cb
commit 3f1ecbdde4

14
main.go
View file

@ -4,8 +4,10 @@ import (
"io" "io"
"log" "log"
"net/http" "net/http"
"net/url"
"os" "os"
"strings" "strings"
"unicode/utf16"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"nulo.in/dlbot/common" "nulo.in/dlbot/common"
@ -52,14 +54,20 @@ func (config Config) handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update)
for i := 0; i < len(searchMsg.Entities); i++ { for i := 0; i < len(searchMsg.Entities); i++ {
e := searchMsg.Entities[i] e := searchMsg.Entities[i]
if e.Type != "url" { if !e.IsURL() {
continue continue
} }
url, err := e.ParseURL() // ugh https://github.com/go-telegram-bot-api/telegram-bot-api/issues/231
text := update.Message.Text
utfEncodedString := utf16.Encode([]rune(text))
runeString := utf16.Decode(utfEncodedString[e.Offset : e.Offset+e.Length])
text = string(runeString)
url, err := url.Parse(text)
if err != nil { if err != nil {
if explicit { if explicit {
bot.Send(respondWithMany(msg, "No se pudo detectar la URL.")) bot.Send(respondWithMany(msg, "No se pudo detectar la URL %s.", text))
} }
continue continue
} }