feat: implement GenFileNameFromMessage function for improved file naming

This commit is contained in:
krau
2025-03-22 09:33:50 +08:00
parent 635f00ac71
commit 19efab0665
6 changed files with 40 additions and 12 deletions

View File

@@ -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))])
}