mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 08:19:41 +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>
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
package stats
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/manacore/mana-matrix-bot/internal/plugin"
|
|
"github.com/manacore/mana-matrix-bot/internal/services"
|
|
)
|
|
|
|
func init() {
|
|
plugin.Register("stats", func() plugin.Plugin { return &StatsPlugin{} })
|
|
}
|
|
|
|
// StatsPlugin reports system statistics via Matrix.
|
|
type StatsPlugin struct {
|
|
backend *services.BackendClient
|
|
router *plugin.CommandRouter
|
|
detector *plugin.KeywordDetector
|
|
}
|
|
|
|
func (p *StatsPlugin) Name() string { return "stats" }
|
|
|
|
func (p *StatsPlugin) 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("!stats", p.cmdStats)
|
|
p.router.Handle("!report", p.cmdStats)
|
|
p.router.Handle("!bericht", p.cmdStats)
|
|
p.router.Handle("!status", p.cmdStatus)
|
|
|
|
p.detector = plugin.NewKeywordDetector(plugin.CommonKeywords)
|
|
|
|
slog.Info("stats plugin initialized")
|
|
return nil
|
|
}
|
|
|
|
func (p *StatsPlugin) Commands() []plugin.CommandDef {
|
|
return []plugin.CommandDef{
|
|
{Patterns: []string{"!stats", "!report"}, Description: "Systemstatistiken", Category: "Stats"},
|
|
{Patterns: []string{"!status"}, Description: "Bot-Status", Category: "System"},
|
|
}
|
|
}
|
|
|
|
func (p *StatsPlugin) HandleTextMessage(ctx context.Context, mc *plugin.MessageContext) error {
|
|
matched, err := p.router.Route(mc)
|
|
if matched {
|
|
return err
|
|
}
|
|
cmd := p.detector.Detect(mc.Body)
|
|
if cmd == "help" {
|
|
return p.cmdHelp(mc, "")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *StatsPlugin) cmdStats(mc *plugin.MessageContext, _ string) error {
|
|
ctx := context.Background()
|
|
mc.Client.SendReply(ctx, mc.RoomID, mc.EventID, "**📊 Systemstatistiken**\n\n_Verfügbar wenn VictoriaMetrics verbunden._")
|
|
return nil
|
|
}
|
|
|
|
func (p *StatsPlugin) cmdStatus(mc *plugin.MessageContext, _ string) error {
|
|
ctx := context.Background()
|
|
mc.Client.SendReply(ctx, mc.RoomID, mc.EventID, "**Stats Bot:** ✅ Online")
|
|
return nil
|
|
}
|
|
|
|
func (p *StatsPlugin) cmdHelp(mc *plugin.MessageContext, _ string) error {
|
|
ctx := context.Background()
|
|
mc.Client.SendReply(ctx, mc.RoomID, mc.EventID, fmt.Sprintf("**📊 Stats Bot**\n\n• `!stats` — Systemstatistiken\n• `!status` — Bot-Status"))
|
|
return nil
|
|
}
|