Compare commits
3 commits
2d02edf907
...
3f1ecbdde4
Author | SHA1 | Date | |
---|---|---|---|
3f1ecbdde4 | |||
80a0a7d6cb | |||
d1466dd415 |
2 changed files with 14 additions and 8 deletions
|
@ -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
18
main.go
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue