Skip to content

Commit 25173bb

Browse files
committed
refactor: improve reply handling by trimming whitespace and removing admin check
1 parent a197b86 commit 25173bb

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

internal/bot/commands/reply_handler.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package commands
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github-webhook/internal/cache"
89
"github-webhook/internal/db"
@@ -35,20 +36,23 @@ func (h *ReplyHandler) HandleReply(b *gotgbot.Bot, ctx *ext.Context) error {
3536
if msg.ReplyToMessage == nil {
3637
return nil
3738
}
38-
if err := requireAdminOrPrivate(b, ctx, "Only admins can comment on GitHub items from this chat."); err != nil {
39-
return err
40-
}
4139

4240
key := fmt.Sprintf("%d:%d", ctx.EffectiveChat.Id, msg.ReplyToMessage.MessageId)
4341
mContext, found := h.ContextCache.Get(key)
4442
if !found {
4543
return nil
4644
}
4745

48-
commentBody := msg.Text
46+
commentBody := strings.TrimSpace(msg.Text)
47+
if commentBody == "" {
48+
return nil
49+
}
50+
4951
client, err := github.GetClientForUser(context.Background(), h.DB, h.ClientFactory, ctx.EffectiveUser.Id, h.EncryptionKey)
5052
if err != nil {
51-
if err.Error() != "unauthorized" {
53+
if err.Error() == "unauthorized" {
54+
_, _ = msg.Reply(b, "Please /connect your GitHub account in a private chat before replying to GitHub items.", nil)
55+
} else {
5256
_, _ = msg.Reply(b, "Auth error. Reconnect via /connect", nil)
5357
}
5458
return nil

0 commit comments

Comments
 (0)