Compare commits

...

3 commits

Author SHA1 Message Date
Cat /dev/Nulo 3f1ecbdde4 hacer el arreglo bien
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-05-09 20:59:23 -03:00
Cat /dev/Nulo 80a0a7d6cb tranquilizar build flags 2023-05-09 20:51:59 -03:00
Cat /dev/Nulo 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:
build:
cmds:
- CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' .
- go build -tags=netgo .
upload:
deps:
- task: build

18
main.go
View file

@ -7,6 +7,7 @@ import (
"net/url"
"os"
"strings"
"unicode/utf16"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"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++ {
e := searchMsg.Entities[i]
if e.Type != "url" {
if !e.IsURL() {
continue
}
urlString := searchMsg.Text[e.Offset : e.Offset+e.Length]
url, err := url.Parse(urlString)
// 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 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
}
@ -88,7 +94,7 @@ func (config Config) handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update)
}
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
}
@ -97,7 +103,7 @@ func (config Config) handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update)
}
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
}
}