Skip to content

Commit 08525bb

Browse files
authored
fix: cannot unsubscribe when using action button in private message (#175)
1 parent 623f9a5 commit 08525bb

File tree

7 files changed

+8
-100
lines changed

7 files changed

+8
-100
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/joho/godotenv v1.5.1
1818
github.com/lib/pq v1.10.9
1919
github.com/maxbrunsfeld/counterfeiter/v6 v6.6.1
20-
github.com/nekomeowww/fo v1.1.2
20+
github.com/nekomeowww/fo v1.2.1
2121
github.com/nekomeowww/go-pinecone v0.1.0
2222
github.com/nekomeowww/timecapsule/v2 v2.1.3
2323
github.com/nekomeowww/xo v1.1.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
149149
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
150150
github.com/nekomeowww/fo v1.1.2 h1:nc5cvBY9rCOYFI169LvuGeHk17QM3pG7p4+QdwRFQoA=
151151
github.com/nekomeowww/fo v1.1.2/go.mod h1:9avQL8Q+yJPkoy/UtHVm58Tk38cPQmbIoTf/Wtv6l1s=
152+
github.com/nekomeowww/fo v1.2.1 h1:7bb3x2Kz7NAoPVvYnvZf5wdpjsg9QvxgmGpcFMJd/9o=
153+
github.com/nekomeowww/fo v1.2.1/go.mod h1:9avQL8Q+yJPkoy/UtHVm58Tk38cPQmbIoTf/Wtv6l1s=
152154
github.com/nekomeowww/go-pinecone v0.1.0 h1:byYmyHQJ4velNUeECvNuCN6KbXGuyVjSFlvO9VV2zj8=
153155
github.com/nekomeowww/go-pinecone v0.1.0/go.mod h1:p8I6F7G7fSrfaa9k3HpsWNxf2y+W1wqn8tw0jsV9e1s=
154156
github.com/nekomeowww/timecapsule/v2 v2.1.3 h1:KIg6jZSg4RkQG9qV2k5TMq9LUzM6cO3MiXvTyLnqZ9U=

internal/bots/telegram/handlers/recap/callback_query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,12 @@ func (h *CallbackQueryHandler) handleCallbackQueryUnsubscribe(c *tgbot.Context)
358358
WithEdit(msg).
359359
WithReplyMarkup(tgbotapi.NewInlineKeyboardMarkup(msg.ReplyMarkup.InlineKeyboard...))
360360
}
361-
if actionData.ChatID != chatID || actionData.FromID != fromID {
361+
if actionData.FromID != fromID {
362362
h.logger.Warn("action skipped, callback query is not from the same actor or the same chat", zap.Int64("from_id", fromID), zap.Int64("chat_id", chatID))
363363
return nil, nil
364364
}
365365

366-
err = h.tgchats.UnsubscribeToAutoRecaps(chatID, fromID)
366+
err = h.tgchats.UnsubscribeToAutoRecaps(actionData.ChatID, fromID)
367367
if err != nil {
368368
return nil, tgbot.
369369
NewExceptionError(err).

internal/configs/configs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88

99
"github.com/joho/godotenv"
10+
"github.com/nekomeowww/xo"
1011
"github.com/samber/lo"
1112
goopenai "github.com/sashabaranov/go-openai"
1213
)
@@ -125,7 +126,7 @@ type Config struct {
125126

126127
func NewConfig() func() (*Config, error) {
127128
return func() (*Config, error) {
128-
envs, err := godotenv.Read()
129+
envs, err := godotenv.Read(xo.RelativePathOf("../../.env"))
129130
if err != nil && !errors.Is(err, os.ErrNotExist) {
130131
return nil, err
131132
}

internal/models/chathistories/chat_histories_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestExtractTextFromMessage(t *testing.T) {
9393
}, nil
9494
}
9595

96-
expect := "看看这些链接:[Documentation](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/stringsandcharacters/#Extended-Grapheme-Clusters) 、[GPT-4 Developer Livestream - YouTube](https://www.youtube.com/watch?v=outcGtbnMuQ) [GitHub - nekomeowww/insights-bot: A bot works with OpenAI GPT models to provide insights for your info flows.](https://github.com/nekomeowww/insights-bot) 还有 [这个](https://matters.town/@1435Club/322889-这几天-web3在大理发生了什么),和这个 [11年前,Go 1发布了。Google Developers Europe呼吁大家庆祝这一天,加入当地见面会和试用Go Playground。如果你和他们一样是一位Gopher,请分享这条推文。](https://twitter.com/GoogleDevEurope/status/1640667303158198272)"
96+
expect := "看看这些链接:[Documentation](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/stringsandcharacters/#Extended-Grapheme-Clusters) 、[GPT-4 Developer Livestream - YouTube](https://www.youtube.com/watch?v=outcGtbnMuQ) [GitHub - nekomeowww/insights-bot: A bot works with OpenAI GPT models to provide insights for your info flows.](https://github.com/nekomeowww/insights-bot) 还有 [这个](https://matters.town/@1435Club/322889-这几天-web3在大理发生了什么),和这个 https://twitter.com/GoogleDevEurope/status/1640667303158198272"
9797
assert.Equal(expect, model.ExtractTextFromMessage(message))
9898
})
9999
}

internal/models/smr/smr_test.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,50 +55,6 @@ func TestExtractContentFromURL(t *testing.T) {
5555
assert.NotEmpty(article.Title)
5656
assert.NotEmpty(article.TextContent)
5757
})
58-
59-
t.Run("Twitter", func(t *testing.T) {
60-
t.Run("twitter.com", func(t *testing.T) {
61-
assert := assert.New(t)
62-
require := require.New(t)
63-
64-
article, err := model.extractContentFromURL(context.Background(), "https://twitter.com/GoogleDevEurope/status/1640667303158198272")
65-
require.NoError(err)
66-
require.NotNil(article)
67-
68-
assert.NotEmpty(article.Title)
69-
assert.NotEmpty(article.Byline)
70-
assert.NotEmpty(article.Content)
71-
assert.NotEmpty(article.TextContent)
72-
})
73-
74-
t.Run("vxtwitter.com", func(t *testing.T) {
75-
assert := assert.New(t)
76-
require := require.New(t)
77-
78-
article, err := model.extractContentFromURL(context.Background(), "https://vxtwitter.com/GoogleDevEurope/status/1640667303158198272")
79-
require.NoError(err)
80-
require.NotNil(article)
81-
82-
assert.NotEmpty(article.Title)
83-
assert.NotEmpty(article.Byline)
84-
assert.NotEmpty(article.Content)
85-
assert.NotEmpty(article.TextContent)
86-
})
87-
88-
t.Run("fxtwitter.com", func(t *testing.T) {
89-
assert := assert.New(t)
90-
require := require.New(t)
91-
92-
article, err := model.extractContentFromURL(context.Background(), "https://fxtwitter.com/GoogleDevEurope/status/1640667303158198272")
93-
require.NoError(err)
94-
require.NotNil(article)
95-
96-
assert.NotEmpty(article.Title)
97-
assert.NotEmpty(article.Byline)
98-
assert.NotEmpty(article.Content)
99-
assert.NotEmpty(article.TextContent)
100-
})
101-
})
10258
}
10359

10460
func TestContentTypeCheck(t *testing.T) {

pkg/linkprev/linkprev_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import (
44
"context"
55
"strings"
66
"testing"
7-
"time"
87

98
"github.com/PuerkitoBio/goquery"
109
"github.com/nekomeowww/insights-bot/pkg/opengraph"
1110
"github.com/samber/lo"
1211
"github.com/stretchr/testify/assert"
13-
"github.com/stretchr/testify/require"
1412
)
1513

1614
func TestPreview(t *testing.T) {
@@ -33,55 +31,6 @@ func TestPreview(t *testing.T) {
3331
},
3432
}, meta)
3533
})
36-
37-
t.Run("Twitter", func(t *testing.T) {
38-
t.Run("twitter.com", func(t *testing.T) {
39-
meta, err := NewClient().Preview(context.Background(), "https://twitter.com/GoogleDevEurope/status/1640667303158198272")
40-
require.NoError(t, err)
41-
assert.Equal(t, Meta{
42-
Title: "Google for Developers Europe on X: \"🎉 Happy Birthday @golang!\n\nDid you know that 11 years ago today Go 1 was publicly released? Join us in celebrating this day by:\n\n🎁 Checking out local meetups → https://t.co/TCNAZL0oOj\n🎁 Trying out the Go Playground → https://t.co/nnkaugz32x\n\nRT if you are a fellow Gopher! https://t.co/jiE7UTMHll\" / X",
43-
OpenGraph: opengraph.OpenGraph{
44-
Title: "Google for Developers Europe on X",
45-
Type: "article",
46-
Image: "https://pbs.twimg.com/media/FsTSN8nWwAA278D.png:large",
47-
URL: "https://twitter.com/GoogleDevEurope/status/1640667303158198272",
48-
Description: "🎉 Happy Birthday @golang!\n\nDid you know that 11 years ago today Go 1 was publicly released? Join us in celebrating this day by:\n\n🎁 Checking out local meetups → https://t.co/TCNAZL0oOj\n🎁 Trying out the Go Playground → https://t.co/nnkaugz32x\n\nRT if you are a fellow Gopher!",
49-
SiteName: "Twitter",
50-
},
51-
}, meta)
52-
})
53-
54-
time.Sleep(time.Second)
55-
56-
t.Run("fxtwitter.com", func(t *testing.T) {
57-
meta, err := NewClient().Preview(context.Background(), "https://fxtwitter.com/GoogleDevEurope/status/1640667303158198272")
58-
require.NoError(t, err)
59-
assert.Equal(t, Meta{
60-
OpenGraph: opengraph.OpenGraph{
61-
Title: "Google for Developers Europe (@GoogleDevEurope)",
62-
Image: "https://pbs.twimg.com/media/FsTSN8nWwAA278D.png",
63-
Description: "🎉 Happy Birthday @golang!\n\nDid you know that 11 years ago today Go 1 was publicly released? Join us in celebrating this day by:\n\n🎁 Checking out local meetups → https://goo.gle/3zaGgRi\n🎁 Trying out the Go Playground → https://goo.gle/3zaGurC\n\nRT if you are a fellow Gopher!",
64-
SiteName: "FixTweet - 🆕 x.com link? Try fixupx.com",
65-
},
66-
}, meta)
67-
})
68-
69-
t.Run("vxtwitter.com", func(t *testing.T) {
70-
meta, err := NewClient().Preview(context.Background(), "https://vxtwitter.com/GoogleDevEurope/status/1640667303158198272")
71-
require.NoError(t, err)
72-
assert.Equal(t, Meta{
73-
Title: "Google for Developers Europe on X: \"🎉 Happy Birthday @golang!\n\nDid you know that 11 years ago today Go 1 was publicly released? Join us in celebrating this day by:\n\n🎁 Checking out local meetups → https://t.co/TCNAZL0oOj\n🎁 Trying out the Go Playground → https://t.co/nnkaugz32x\n\nRT if you are a fellow Gopher! https://t.co/jiE7UTMHll\" / X",
74-
OpenGraph: opengraph.OpenGraph{
75-
Title: "Google for Developers Europe on X",
76-
Type: "article",
77-
Image: "https://pbs.twimg.com/media/FsTSN8nWwAA278D.png:large",
78-
URL: "https://twitter.com/GoogleDevEurope/status/1640667303158198272",
79-
Description: "🎉 Happy Birthday @golang!\n\nDid you know that 11 years ago today Go 1 was publicly released? Join us in celebrating this day by:\n\n🎁 Checking out local meetups → https://t.co/TCNAZL0oOj\n🎁 Trying out the Go Playground → https://t.co/nnkaugz32x\n\nRT if you are a fellow Gopher!",
80-
SiteName: "Twitter",
81-
},
82-
}, meta)
83-
})
84-
})
8534
}
8635

8736
func TestNewMetaFrom(t *testing.T) {

0 commit comments

Comments
 (0)