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
104 lines
2.2 KiB
Go
104 lines
2.2 KiB
Go
package tgbot
|
||
|
||
import (
|
||
"fmt"
|
||
"strconv"
|
||
"strings"
|
||
|
||
tele "gopkg.in/telebot.v4"
|
||
"server/rutor"
|
||
"server/rutor/models"
|
||
sets "server/settings"
|
||
"server/torr"
|
||
"server/torznab"
|
||
)
|
||
|
||
const inlineMaxResults = 20
|
||
|
||
func handleInlineQuery(c tele.Context) error {
|
||
query := strings.TrimSpace(c.Query().Text)
|
||
uid := int64(0)
|
||
if c.Query().Sender != nil {
|
||
uid = c.Query().Sender.ID
|
||
}
|
||
|
||
var results tele.Results
|
||
id := 0
|
||
|
||
if query == "" || strings.ToLower(query) == "list" || strings.ToLower(query) == "play" {
|
||
torrents := torr.ListTorrent()
|
||
host := getHost()
|
||
for _, t := range torrents {
|
||
if id >= inlineMaxResults {
|
||
break
|
||
}
|
||
hash := t.Hash().HexString()
|
||
url := fmt.Sprintf("%s/play/%s/1", host, hash)
|
||
title := t.Title
|
||
if len(title) > 60 {
|
||
title = title[:57] + "..."
|
||
}
|
||
results = append(results, &tele.ArticleResult{
|
||
ResultBase: tele.ResultBase{ID: strconv.Itoa(id)},
|
||
Title: "▶ " + title,
|
||
Description: hash[:8] + "...",
|
||
URL: url,
|
||
Text: url,
|
||
})
|
||
id++
|
||
}
|
||
}
|
||
|
||
if len(query) >= 2 && sets.BTsets != nil && (sets.BTsets.EnableRutorSearch || sets.BTsets.EnableTorznabSearch) {
|
||
var list []*models.TorrentDetails
|
||
if sets.BTsets.EnableRutorSearch {
|
||
list = append(list, rutor.Search(query)...)
|
||
}
|
||
if sets.BTsets.EnableTorznabSearch {
|
||
list = append(list, torznab.Search(query, -1)...)
|
||
}
|
||
for _, item := range list {
|
||
if id >= inlineMaxResults {
|
||
break
|
||
}
|
||
link := item.Magnet
|
||
if link == "" {
|
||
link = item.Link
|
||
}
|
||
if link == "" {
|
||
continue
|
||
}
|
||
title := item.Title
|
||
if len(title) > 60 {
|
||
title = title[:57] + "..."
|
||
}
|
||
size := item.Size
|
||
if size == "" {
|
||
size = "?"
|
||
}
|
||
results = append(results, &tele.ArticleResult{
|
||
ResultBase: tele.ResultBase{ID: strconv.Itoa(id)},
|
||
Title: "➕ " + title,
|
||
Description: fmt.Sprintf("%s S:%d P:%d", size, item.Seed, item.Peer),
|
||
Text: link,
|
||
})
|
||
id++
|
||
}
|
||
}
|
||
|
||
if len(results) == 0 {
|
||
results = append(results, &tele.ArticleResult{
|
||
ResultBase: tele.ResultBase{ID: "0"},
|
||
Title: tr(uid, "no_torrents"),
|
||
Description: tr(uid, "add_magnet"),
|
||
Text: "",
|
||
})
|
||
}
|
||
|
||
return c.Answer(&tele.QueryResponse{
|
||
Results: results,
|
||
CacheTime: 60,
|
||
IsPersonal: true,
|
||
})
|
||
}
|