Compare commits

..

3 commits

Author SHA1 Message Date
3f1ecbdde4 hacer el arreglo bien
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-05-09 20:59:23 -03:00
80a0a7d6cb tranquilizar build flags 2023-05-09 20:51:59 -03:00
d1466dd415 ugh unicode (entities son utf-16) 2023-05-09 20:51:56 -03:00
2 changed files with 14 additions and 8 deletions

View file

@ -1,9 +1,9 @@
version: '3' version: "3"
tasks: tasks:
build: build:
cmds: cmds:
- CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' . - go build -tags=netgo .
upload: upload:
deps: deps:
- task: build - task: build

18
main.go
View file

@ -7,6 +7,7 @@ import (
"net/url" "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"
@ -53,15 +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
} }
urlString := searchMsg.Text[e.Offset : e.Offset+e.Length] // ugh https://github.com/go-telegram-bot-api/telegram-bot-api/issues/231
url, err := url.Parse(urlString) 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 ", urlString, ".")) bot.Send(respondWithMany(msg, "No se pudo detectar la URL %s.", text))
} }
continue continue
} }
@ -88,7 +94,7 @@ func (config Config) handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update)
} }
if explicit && érror == common.NotValid { if explicit && érror == common.NotValid {
bot.Send(respondWithMany(msg, "La URL ", urlString, " no es compatible con este bot.")) bot.Send(respondWithMany(msg, "La URL ", url.String(), " no es compatible con este bot."))
continue continue
} }
@ -97,7 +103,7 @@ func (config Config) handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update)
} }
if érror == common.HadError { if érror == common.HadError {
bot.Send(respondWithMany(update.Message, "Hubo un error al descargar ", urlString, ".")) bot.Send(respondWithMany(update.Message, "Hubo un error al descargar ", url.String(), "."))
continue continue
} }
} }