Skip to content

Commit 043218d

Browse files
committed
fix: missing label
1 parent e483e5c commit 043218d

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

ash.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,14 @@ func run(ctx context.Context, metaDB *sql.DB, messagesDB *sql.DB, cfg *Config) e
698698
} else if cmdCfg, ok := botCfg.Commands[cmd]; ok {
699699
// Run bot command in a goroutine to avoid blocking other messages
700700
go func() {
701-
resp, err := FetchBotCommand(evCtx, &cmdCfg, cfg.LinkstashURL, ev, client, cfg.GroqAPIKey)
701+
label := "> "
702+
// Precedence: config.BOT_REPLY_LABEL -> bot.json label -> default
703+
if cfg != nil && cfg.BotReplyLabel != "" {
704+
label = cfg.BotReplyLabel
705+
} else if botCfg != nil && botCfg.Label != "" {
706+
label = botCfg.Label
707+
}
708+
resp, err := FetchBotCommand(evCtx, &cmdCfg, cfg.LinkstashURL, ev, client, cfg.GroqAPIKey, label)
702709
var body string
703710
if err != nil {
704711
log.Error().Err(err).Str("cmd", cmd).Msg("failed to execute bot command")
@@ -709,13 +716,7 @@ func run(ctx context.Context, metaDB *sql.DB, messagesDB *sql.DB, cfg *Config) e
709716
// Command sent its own message (like images), don't send a text reply
710717
return
711718
}
712-
label := "> "
713-
// Precedence: config.BOT_REPLY_LABEL -> bot.json label -> default
714-
if cfg != nil && cfg.BotReplyLabel != "" {
715-
label = cfg.BotReplyLabel
716-
} else if botCfg != nil && botCfg.Label != "" {
717-
label = botCfg.Label
718-
}
719+
719720
body = label + body
720721
content := event.MessageEventContent{
721722
MsgType: event.MsgText,

bot.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func detectImageExtension(inputPath string) string {
201201
}
202202

203203
// FetchBotCommand executes the configured command and returns a string to post.
204-
func FetchBotCommand(ctx context.Context, c *BotCommand, linkstashURL string, ev *event.Event, matrixClient *mautrix.Client, groqAPIKey string) (string, error) {
204+
func FetchBotCommand(ctx context.Context, c *BotCommand, linkstashURL string, ev *event.Event, matrixClient *mautrix.Client, groqAPIKey string, replyLabel string) (string, error) {
205205
if c.Response != "" {
206206
return c.Response, nil
207207
}
@@ -212,7 +212,7 @@ func FetchBotCommand(ctx context.Context, c *BotCommand, linkstashURL string, ev
212212
case "exec":
213213
return handleExecCommand(ctx, ev, matrixClient, c)
214214
case "ai":
215-
return handleAiCommand(ctx, ev, matrixClient, c, groqAPIKey)
215+
return handleAiCommand(ctx, ev, matrixClient, c, groqAPIKey, replyLabel)
216216
default:
217217
return "", fmt.Errorf("unknown command type: %s", c.Type)
218218
}
@@ -524,7 +524,7 @@ func handleExecCommand(ctx context.Context, ev *event.Event, matrixClient *mautr
524524
}
525525

526526
// handleAiCommand handles AI-based commands using Groq
527-
func handleAiCommand(ctx context.Context, ev *event.Event, matrixClient *mautrix.Client, c *BotCommand, groqAPIKey string) (string, error) {
527+
func handleAiCommand(ctx context.Context, ev *event.Event, matrixClient *mautrix.Client, c *BotCommand, groqAPIKey string, replyLabel string) (string, error) {
528528
var targetText string
529529
// Track replied-to event ID if present so we can reply to the original
530530
var originalEventID id.EventID
@@ -740,9 +740,15 @@ func handleAiCommand(ctx context.Context, ev *event.Event, matrixClient *mautrix
740740
response := groqResp.Choices[0].Message.Content
741741
// If we fetched a replied-to event earlier, send the response directly as a reply to that event
742742
if originalEventID != "" {
743+
// Prefix reply with the configured label (fallback to "> ")
744+
label := replyLabel
745+
if label == "" {
746+
label = "> "
747+
}
748+
body := label + response
743749
content := event.MessageEventContent{
744750
MsgType: event.MsgText,
745-
Body: response,
751+
Body: body,
746752
RelatesTo: &event.RelatesTo{InReplyTo: &event.InReplyTo{EventID: originalEventID}},
747753
}
748754
_, err := matrixClient.SendMessageEvent(ctx, ev.RoomID, event.EventMessage, &content)

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/polarhive/ash
22

3-
go 1.25.0
3+
go 1.26.0
44

55
require (
6-
github.com/mattn/go-sqlite3 v1.14.33
6+
github.com/mattn/go-sqlite3 v1.14.34
77
github.com/rs/zerolog v1.34.0
88
github.com/sashabaranov/go-openai v1.41.2
99
maunium.net/go/mautrix v0.26.2
@@ -19,9 +19,9 @@ require (
1919
github.com/tidwall/pretty v1.2.1 // indirect
2020
github.com/tidwall/sjson v1.2.5 // indirect
2121
go.mau.fi/util v0.9.5 // indirect
22-
golang.org/x/crypto v0.47.0 // indirect
23-
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
24-
golang.org/x/net v0.49.0 // indirect
22+
golang.org/x/crypto v0.48.0 // indirect
23+
golang.org/x/exp v0.0.0-20260212183809-81e46e3db34a // indirect
24+
golang.org/x/net v0.50.0 // indirect
2525
golang.org/x/sys v0.41.0 // indirect
26-
golang.org/x/text v0.33.0 // indirect
26+
golang.org/x/text v0.34.0 // indirect
2727
)

go.sum

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
1313
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
1414
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
1515
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
16-
github.com/mattn/go-sqlite3 v1.14.33 h1:A5blZ5ulQo2AtayQ9/limgHEkFreKj1Dv226a1K73s0=
17-
github.com/mattn/go-sqlite3 v1.14.33/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
16+
github.com/mattn/go-sqlite3 v1.14.34 h1:3NtcvcUnFBPsuRcno8pUtupspG/GM+9nZ88zgJcp6Zk=
17+
github.com/mattn/go-sqlite3 v1.14.34/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
1818
github.com/petermattis/goid v0.0.0-20260113132338-7c7de50cc741 h1:KPpdlQLZcHfTMQRi6bFQ7ogNO0ltFT4PmtwTLW4W+14=
1919
github.com/petermattis/goid v0.0.0-20260113132338-7c7de50cc741/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
2020
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -40,21 +40,19 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
4040
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
4141
go.mau.fi/util v0.9.5 h1:7AoWPCIZJGv4jvtFEuCe3GhAbI7uF9ckIooaXvwlIR4=
4242
go.mau.fi/util v0.9.5/go.mod h1:g1uvZ03VQhtTt2BgaRGVytS/Zj67NV0YNIECch0sQCQ=
43-
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
44-
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
45-
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 h1:Z/6YuSHTLOHfNFdb8zVZomZr7cqNgTJvA8+Qz75D8gU=
46-
golang.org/x/exp v0.0.0-20260112195511-716be5621a96/go.mod h1:nzimsREAkjBCIEFtHiYkrJyT+2uy9YZJB7H1k68CXZU=
47-
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
48-
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
43+
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
44+
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
45+
golang.org/x/exp v0.0.0-20260212183809-81e46e3db34a h1:ovFr6Z0MNmU7nH8VaX5xqw+05ST2uO1exVfZPVqRC5o=
46+
golang.org/x/exp v0.0.0-20260212183809-81e46e3db34a/go.mod h1:K79w1Vqn7PoiZn+TkNpx3BUWUQksGO3JcVX6qIjytmA=
47+
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
48+
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
4949
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5050
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5151
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
52-
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
53-
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
5452
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
5553
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
56-
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
57-
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
54+
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
55+
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
5856
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
5957
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6058
maunium.net/go/mautrix v0.26.2 h1:rLiZLQoSKCJDZ+mF1gBQS4p74h3jZXs83g8D4W6Te8g=

0 commit comments

Comments
 (0)