Compare commits
No commits in common. "3f1ecbdde4d0ca37fd096de916699443e4ee4ea1" and "2d02edf9079c90006b0f19e76e67d2a9e47758aa" have entirely different histories.
3f1ecbdde4
...
2d02edf907
2 changed files with 8 additions and 14 deletions
|
@ -1,9 +1,9 @@
|
|||
version: "3"
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
build:
|
||||
cmds:
|
||||
- go build -tags=netgo .
|
||||
- CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' .
|
||||
upload:
|
||||
deps:
|
||||
- task: build
|
||||
|
|
18
main.go
18
main.go
|
@ -7,7 +7,6 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"unicode/utf16"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"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++ {
|
||||
e := searchMsg.Entities[i]
|
||||
if !e.IsURL() {
|
||||
if e.Type != "url" {
|
||||
continue
|
||||
}
|
||||
|
||||
// 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)
|
||||
urlString := searchMsg.Text[e.Offset : e.Offset+e.Length]
|
||||
url, err := url.Parse(urlString)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
@ -94,7 +88,7 @@ func (config Config) handleMessage(bot *tgbotapi.BotAPI, update tgbotapi.Update)
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -103,7 +97,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 ", url.String(), "."))
|
||||
bot.Send(respondWithMany(update.Message, "Hubo un error al descargar ", urlString, "."))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue