mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-11 19:29:41 +08:00
feat: implement GenFileNameFromMessage function for improved file naming
This commit is contained in:
18
bot/utils.go
18
bot/utils.go
@@ -3,6 +3,8 @@ package bot
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/celestix/gotgproto/dispatcher"
|
||||
@@ -270,3 +272,19 @@ func HandleSilentAddTask(ctx *ext.Context, update *ext.Update, user *dao.User, t
|
||||
})
|
||||
return dispatcher.EndGroups
|
||||
}
|
||||
|
||||
func GenFileNameFromMessage(message tg.Message, file *types.File) string {
|
||||
if file.FileName != "" {
|
||||
return file.FileName
|
||||
}
|
||||
text := strings.TrimSpace(message.GetMessage())
|
||||
if text == "" {
|
||||
return file.Hash()
|
||||
}
|
||||
tags := common.ExtractTagsFromText(text)
|
||||
if len(tags) > 0 {
|
||||
return fmt.Sprintf("%s_%s", strings.Join(tags, "_"), strconv.Itoa(message.GetID()))
|
||||
}
|
||||
runes := []rune(text)
|
||||
return string(runes[:min(128, len(runes))])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user