Compare commits

..

No commits in common. "3f1ecbdde4d0ca37fd096de916699443e4ee4ea1" and "2d02edf9079c90006b0f19e76e67d2a9e47758aa" have entirely different histories.

2 changed files with 8 additions and 14 deletions

View file

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

18
main.go
View file

@ -7,7 +7,6 @@ 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"
@ -54,20 +53,15 @@ 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.IsURL() { if e.Type != "url" {
continue continue
} }
// ugh https://github.com/go-telegram-bot-api/telegram-bot-api/issues/231 urlString := searchMsg.Text[e.Offset : e.Offset+e.Length]
text := update.Message.Text url, err := url.Parse(urlString)
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 %s.", text)) bot.Send(respondWithMany(msg, "No se pudo detectar la URL ", urlString, "."))
} }
continue continue
} }
@ -94,7 +88,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 ", url.String(), " no es compatible con este bot.")) bot.Send(respondWithMany(msg, "La URL ", urlString, " no es compatible con este bot."))
continue continue
} }
@ -103,7 +97,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 ", url.String(), ".")) bot.Send(respondWithMany(update.Message, "Hubo un error al descargar ", urlString, "."))
continue continue
} }
} }