Refine Telegram thread commands

This commit is contained in:
Codex
2026-06-23 11:19:48 +00:00
parent ac8d5c2803
commit 595e8aee0e
9 changed files with 628 additions and 102 deletions

View File

@@ -496,6 +496,41 @@ func ParseResumePageCallbackData(data string) (int, bool) {
return page, err == nil && page >= 0
}
func ThreadActionCallbackData(action string, id int64) string {
return fmt.Sprintf("thread:%s:%d", action, id)
}
func ParseThreadActionCallbackData(data string) (string, int64, bool) {
parts := strings.Split(data, ":")
if len(parts) != 3 || parts[0] != "thread" || !isThreadAction(parts[1]) {
return "", 0, false
}
id, err := strconv.ParseInt(parts[2], 10, 64)
return parts[1], id, err == nil && id > 0
}
func ThreadActionPageCallbackData(action string, page int) string {
return fmt.Sprintf("threadpage:%s:%d", action, page)
}
func ParseThreadActionPageCallbackData(data string) (string, int, bool) {
parts := strings.Split(data, ":")
if len(parts) != 3 || parts[0] != "threadpage" || !isThreadAction(parts[1]) {
return "", 0, false
}
page, err := strconv.Atoi(parts[2])
return parts[1], page, err == nil && page >= 0
}
func isThreadAction(action string) bool {
switch action {
case threadActionResume, threadActionArchive, threadActionUnarchive, threadActionDelete:
return true
default:
return false
}
}
func ModelCallbackData(modelID string) (string, bool) {
encoded := base64.RawURLEncoding.EncodeToString([]byte(modelID))
data := "model:" + encoded