mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 17:39:40 +02:00
Replace 21 separate NestJS Matrix bot processes (~2.1 GB RAM, ~4.2 GB Docker images) with a single Go binary using plugin architecture (8.6 MB binary, ~30 MB RAM). New services: - services/mana-matrix-bot/ — Go Matrix bot with 21 plugins (mautrix-go, Redis sessions) - services/mana-api-gateway-go/ — Go API gateway (rate limiting, API keys, credit billing) Deleted: - 21 services/matrix-*-bot/ directories - packages/bot-services/ and packages/matrix-bot-common/ - Legacy deploy scripts and CI build jobs Updated: - docker-compose.macmini.yml: new Go services, legacy bots removed - CI/CD: change detection + build jobs for Go services - Root package.json: new dev:matrix, build:matrix, test:matrix scripts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package matrix
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
reBold = regexp.MustCompile(`\*\*(.+?)\*\*`)
|
|
reItalic = regexp.MustCompile(`\*(.+?)\*`)
|
|
reStrikethrough = regexp.MustCompile(`~~(.+?)~~`)
|
|
reCode = regexp.MustCompile("`(.+?)`")
|
|
)
|
|
|
|
// MarkdownToHTML converts simple markdown to HTML for Matrix messages.
|
|
// Matches the exact behavior of the TypeScript markdownToHtml function.
|
|
func MarkdownToHTML(text string) string {
|
|
result := text
|
|
result = reBold.ReplaceAllString(result, "<strong>$1</strong>")
|
|
result = reItalic.ReplaceAllString(result, "<em>$1</em>")
|
|
result = reStrikethrough.ReplaceAllString(result, "<del>$1</del>")
|
|
result = reCode.ReplaceAllString(result, "<code>$1</code>")
|
|
result = strings.ReplaceAll(result, "\n", "<br>")
|
|
return result
|
|
}
|
|
|
|
// EscapeHTML escapes HTML special characters.
|
|
func EscapeHTML(text string) string {
|
|
r := strings.NewReplacer(
|
|
"&", "&",
|
|
"<", "<",
|
|
">", ">",
|
|
`"`, """,
|
|
"'", "'",
|
|
)
|
|
return r.Replace(text)
|
|
}
|
|
|
|
// FormatNumberedList formats items as a numbered markdown list.
|
|
func FormatNumberedList[T any](items []T, formatter func(T, int) string) string {
|
|
var sb strings.Builder
|
|
for i, item := range items {
|
|
if i > 0 {
|
|
sb.WriteByte('\n')
|
|
}
|
|
sb.WriteString(fmt.Sprintf("%d. %s", i+1, formatter(item, i)))
|
|
}
|
|
return sb.String()
|
|
}
|
|
|
|
// FormatBulletList formats items as a bullet markdown list.
|
|
func FormatBulletList[T any](items []T, formatter func(T) string) string {
|
|
var sb strings.Builder
|
|
for i, item := range items {
|
|
if i > 0 {
|
|
sb.WriteByte('\n')
|
|
}
|
|
sb.WriteString("• ")
|
|
sb.WriteString(formatter(item))
|
|
}
|
|
return sb.String()
|
|
}
|