mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-11 22:49:40 +08:00
feat: file name staregy
This commit is contained in:
@@ -2,20 +2,21 @@ package tfile
|
||||
|
||||
import "github.com/gotd/td/tg"
|
||||
|
||||
type TGFileOptions func(*tgFile)
|
||||
type TGFileOption func(*tgFile)
|
||||
|
||||
func WithMessage(msg *tg.Message) TGFileOptions {
|
||||
func WithMessage(msg *tg.Message) TGFileOption {
|
||||
return func(f *tgFile) {
|
||||
f.message = msg
|
||||
}
|
||||
}
|
||||
func WithName(name string) TGFileOptions {
|
||||
|
||||
func WithName(name string) TGFileOption {
|
||||
return func(f *tgFile) {
|
||||
f.name = name
|
||||
}
|
||||
}
|
||||
|
||||
func WithNameIfEmpty(name string) TGFileOptions {
|
||||
func WithNameIfEmpty(name string) TGFileOption {
|
||||
return func(f *tgFile) {
|
||||
if f.name == "" {
|
||||
f.name = name
|
||||
@@ -23,13 +24,13 @@ func WithNameIfEmpty(name string) TGFileOptions {
|
||||
}
|
||||
}
|
||||
|
||||
func WithSize(size int64) TGFileOptions {
|
||||
func WithSize(size int64) TGFileOption {
|
||||
return func(f *tgFile) {
|
||||
f.size = size
|
||||
}
|
||||
}
|
||||
|
||||
func WithSizeIfZero(size int64) TGFileOptions {
|
||||
func WithSizeIfZero(size int64) TGFileOption {
|
||||
return func(f *tgFile) {
|
||||
if f.size == 0 {
|
||||
f.size = size
|
||||
|
||||
@@ -54,7 +54,7 @@ func NewTGFile(
|
||||
dler downloader.Client,
|
||||
size int64,
|
||||
name string,
|
||||
opts ...TGFileOptions,
|
||||
opts ...TGFileOption,
|
||||
) TGFile {
|
||||
f := &tgFile{
|
||||
location: location,
|
||||
@@ -68,7 +68,7 @@ func NewTGFile(
|
||||
return f
|
||||
}
|
||||
|
||||
func FromMedia(media tg.MessageMediaClass, client downloader.Client, opts ...TGFileOptions) (TGFile, error) {
|
||||
func FromMedia(media tg.MessageMediaClass, client downloader.Client, opts ...TGFileOption) (TGFile, error) {
|
||||
switch m := media.(type) {
|
||||
case *tg.MessageMediaDocument:
|
||||
document, ok := m.Document.AsNotEmpty()
|
||||
@@ -125,7 +125,7 @@ func FromMedia(media tg.MessageMediaClass, client downloader.Client, opts ...TGF
|
||||
return nil, fmt.Errorf("unsupported media type: %T", media)
|
||||
}
|
||||
|
||||
func FromMediaMessage(media tg.MessageMediaClass, client downloader.Client, msg *tg.Message, opts ...TGFileOptions) (TGFileMessage, error) {
|
||||
func FromMediaMessage(media tg.MessageMediaClass, client downloader.Client, msg *tg.Message, opts ...TGFileOption) (TGFileMessage, error) {
|
||||
file, err := FromMedia(media, client, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user