616c6b1c62
Release Docker multi arch / docker (push) Has been cancelled
Test Install Script / Test Script Syntax (push) Has been cancelled
Test Install Script / Test on almalinux-10 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-10 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (root) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (default) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (root) (push) Has been cancelled
Test Install Script / Test on debian-11 (default) (push) Has been cancelled
Test Install Script / Test on debian-11 (root) (push) Has been cancelled
Test Install Script / Test on debian-12 (default) (push) Has been cancelled
Test Install Script / Test on debian-12 (root) (push) Has been cancelled
Test Install Script / Test on debian-13 (default) (push) Has been cancelled
Test Install Script / Test on debian-13 (root) (push) Has been cancelled
Test Install Script / Test on fedora-latest (default) (push) Has been cancelled
Test Install Script / Test on fedora-latest (root) (push) Has been cancelled
Test Install Script / Test on rocky-10 (default) (push) Has been cancelled
Test Install Script / Test on rocky-10 (root) (push) Has been cancelled
Test Install Script / Test on rocky-8 (default) (push) Has been cancelled
Test Install Script / Test on rocky-8 (root) (push) Has been cancelled
Test Install Script / Test on rocky-9 (default) (push) Has been cancelled
Test Install Script / Test on rocky-9 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (root) (push) Has been cancelled
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package tgbot
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
tele "gopkg.in/telebot.v4"
|
|
)
|
|
|
|
var magnetRegex = regexp.MustCompile(`magnet:\?[^\s]+`)
|
|
var torrsRegex = regexp.MustCompile(`torrs://[^\s]+`)
|
|
var hashRegex = regexp.MustCompile(`\b([a-fA-F0-9]{40})\b`)
|
|
|
|
func cmdImport(c tele.Context) error {
|
|
text := ""
|
|
if c.Message() != nil && c.Message().Text != "" {
|
|
text = strings.TrimPrefix(strings.TrimSpace(c.Message().Text), "/import")
|
|
text = strings.TrimSpace(text)
|
|
}
|
|
if text == "" {
|
|
return c.Send(tr(c.Sender().ID, "import_usage"))
|
|
}
|
|
var links []string
|
|
seen := make(map[string]bool)
|
|
for _, m := range magnetRegex.FindAllString(text, -1) {
|
|
m = strings.TrimSpace(m)
|
|
if m != "" && !seen[m] {
|
|
seen[m] = true
|
|
links = append(links, m)
|
|
}
|
|
}
|
|
for _, m := range torrsRegex.FindAllString(text, -1) {
|
|
m = strings.TrimSpace(m)
|
|
if m != "" && !seen[m] {
|
|
seen[m] = true
|
|
links = append(links, m)
|
|
}
|
|
}
|
|
for _, m := range hashRegex.FindAllString(text, -1) {
|
|
h := strings.ToLower(strings.TrimSpace(m))
|
|
if h != "" && !seen[h] {
|
|
seen[h] = true
|
|
links = append(links, h)
|
|
}
|
|
}
|
|
if len(links) == 0 {
|
|
return c.Send(tr(c.Sender().ID, "import_no_links"))
|
|
}
|
|
uid := c.Sender().ID
|
|
added := 0
|
|
for _, link := range links {
|
|
if err := addTorrent(c, link); err != nil {
|
|
_ = c.Send(fmt.Sprintf(tr(uid, "add_error"), err.Error()))
|
|
continue
|
|
}
|
|
added++
|
|
}
|
|
return c.Send(fmt.Sprintf(tr(uid, "import_done"), added, len(links)))
|
|
}
|