* feat: WIP. add parser functionality and text message handling * fix: use json to marshal js result * feat: add metadata handling and version validation for jsParser * refactor: rename parser package to parsers and restructure parser handling * refactor: core code struct and impl parse task handle * feat: impl parsed download * fix: seek cache file when processing tph picture * feat: implement parsed task handling and progress tracking * feat: enhance task processing with concurrency control and progress tracking * feat: add resource ID generation and improve resource processing handling * feat: improve message formatting in parsed text and progress completion * feat: add example js plugin * feat: implement Twitter parser * fix: twitter parse video json decode error * feat: impl stream mode for parse task
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package msgelem
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gotd/td/telegram/message/entity"
|
|
"github.com/gotd/td/telegram/message/styling"
|
|
"github.com/gotd/td/tg"
|
|
"github.com/krau/SaveAny-Bot/pkg/parser"
|
|
)
|
|
|
|
func BuildParsedTextEntity(item parser.Item) (string, []tg.MessageEntityClass, error) {
|
|
eb := entity.Builder{}
|
|
if err := styling.Perform(&eb,
|
|
styling.Bold(fmt.Sprintf("[%s]%s", item.Site, item.Title)),
|
|
styling.Plain("\n链接: "),
|
|
styling.Code(item.URL),
|
|
styling.Plain("\n作者: "),
|
|
styling.Code(item.Author),
|
|
styling.Plain("\n描述: "),
|
|
styling.Code(item.Description),
|
|
styling.Plain("\n文件数量: "),
|
|
styling.Code(fmt.Sprintf("%d", len(item.Resources))),
|
|
styling.Plain("\n预计总大小: "),
|
|
styling.Code(fmt.Sprintf("%.2f MB", func() float64 {
|
|
var totalSize int64
|
|
for _, res := range item.Resources {
|
|
totalSize += res.Size
|
|
}
|
|
return float64(totalSize) / 1024 / 1024
|
|
}())),
|
|
styling.Plain("\n请选择存储位置"),
|
|
); err != nil {
|
|
return "", nil, fmt.Errorf("构建消息失败: %w", err)
|
|
}
|
|
text, entities := eb.Complete()
|
|
return text, entities, nil
|
|
}
|