managarten/services/mana-matrix-bot/internal/plugins/projectdoc/projectdoc.go
Till JS 819568c3df feat(infra): consolidate 21 Matrix bots into Go binary + add Go API gateway
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>
2026-03-27 21:03:00 +01:00

71 lines
2.4 KiB
Go

package projectdoc
import (
"context"
"log/slog"
"github.com/manacore/mana-matrix-bot/internal/plugin"
"github.com/manacore/mana-matrix-bot/internal/services"
)
func init() {
plugin.Register("projectdoc", func() plugin.Plugin { return &ProjectDocPlugin{} })
}
type ProjectDocPlugin struct {
backend *services.BackendClient
router *plugin.CommandRouter
detector *plugin.KeywordDetector
}
func (p *ProjectDocPlugin) Name() string { return "projectdoc" }
func (p *ProjectDocPlugin) Init(_ context.Context, cfg plugin.PluginConfig) error {
if cfg.BackendURL != "" {
p.backend = services.NewBackendClient(cfg.BackendURL)
}
p.router = plugin.NewCommandRouter()
p.router.Handle("!help", p.cmdHelp)
p.router.Handle("!hilfe", p.cmdHelp)
p.router.Handle("!docs", p.cmdDocs)
p.router.Handle("!generate", p.cmdGenerate)
p.router.Handle("!status", p.cmdStatus)
p.detector = plugin.NewKeywordDetector(plugin.CommonKeywords)
slog.Info("projectdoc plugin initialized")
return nil
}
func (p *ProjectDocPlugin) Commands() []plugin.CommandDef {
return []plugin.CommandDef{
{Patterns: []string{"!docs"}, Description: "Dokumentation anzeigen", Category: "Docs"},
{Patterns: []string{"!generate"}, Description: "Doku generieren", Category: "Docs"},
}
}
func (p *ProjectDocPlugin) HandleTextMessage(ctx context.Context, mc *plugin.MessageContext) error {
matched, err := p.router.Route(mc)
if matched {
return err
}
if p.detector.Detect(mc.Body) == "help" {
return p.cmdHelp(mc, "")
}
return nil
}
func (p *ProjectDocPlugin) cmdDocs(mc *plugin.MessageContext, _ string) error {
mc.Client.SendReply(context.Background(), mc.RoomID, mc.EventID, "**📄 Dokumentation**\n\n_Projekt-Dokumentation über die Web-App._")
return nil
}
func (p *ProjectDocPlugin) cmdGenerate(mc *plugin.MessageContext, args string) error {
mc.Client.SendReply(context.Background(), mc.RoomID, mc.EventID, "**📄 Doku generieren**\n\n_Beschreibe das zu dokumentierende Projekt._")
return nil
}
func (p *ProjectDocPlugin) cmdStatus(mc *plugin.MessageContext, _ string) error {
mc.Client.SendReply(context.Background(), mc.RoomID, mc.EventID, "**ProjectDoc Bot:** ✅ Online")
return nil
}
func (p *ProjectDocPlugin) cmdHelp(mc *plugin.MessageContext, _ string) error {
mc.Client.SendReply(context.Background(), mc.RoomID, mc.EventID, "**📄 ProjectDoc Bot**\n\n• `!docs` — Dokumentation\n• `!generate` — Doku generieren\n• `!status` — Status")
return nil
}