Post Discord questions as named threads.
CI / test (pull_request) Successful in 6m26s

This commit is contained in:
2026-08-29 11:22:16 -07:00
parent 573f54afd2
commit 86ce35e482
4 changed files with 83 additions and 29 deletions
+40 -4
View File
@@ -39,7 +39,7 @@ func formatMessage(ev events.PostEvent) Message {
Description: truncateRunes(strings.TrimSpace(ev.Body), embedDescriptionLimit),
City: strings.TrimSpace(ev.City),
Author: author,
ThreadName: threadName(ev.Title),
ThreadName: threadName(author, ev.Title),
}
for _, img := range ev.Images {
url := strings.TrimSpace(img.URL)
@@ -51,12 +51,16 @@ func formatMessage(ev events.PostEvent) Message {
return msg
}
func threadName(title string) string {
func threadName(author, title string) string {
author = strings.TrimSpace(author)
if author == "" {
author = "Someone"
}
title = strings.TrimSpace(title)
if title == "" {
return "Question"
title = "Question"
}
return truncateRunes(title, threadNameLimit)
return truncateRunes(author+" asks: "+title, threadNameLimit)
}
func truncateRunes(s string, max int) string {
@@ -73,3 +77,35 @@ func truncateRunes(s string, max int) string {
func isRoot(ev events.PostEvent) bool {
return strings.TrimSpace(ev.ParentID) == ""
}
func messageContent(msg Message) string {
var parts []string
if body := strings.TrimSpace(msg.Description); body != "" {
parts = append(parts, body)
}
var meta []string
if msg.City != "" {
meta = append(meta, msg.City)
}
if msg.Author != "" {
meta = append(meta, msg.Author)
}
if len(meta) > 0 {
parts = append(parts, strings.Join(meta, " · "))
}
if u := publicURL(msg.URL); u != "" {
parts = append(parts, u)
}
return truncateRunes(strings.Join(parts, "\n"), 2000)
}
func publicURL(raw string) string {
raw = strings.TrimSpace(raw)
if !strings.HasPrefix(raw, "https://") {
return ""
}
if strings.Contains(raw, "localhost") || strings.Contains(raw, "127.0.0.1") {
return ""
}
return raw
}