Skip to content

Commit

Permalink
fix: cannot unsubscribe when using action button in private message (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomeowww committed Sep 21, 2023
1 parent 623f9a5 commit 08525bb
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 100 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/maxbrunsfeld/counterfeiter/v6 v6.6.1
github.com/nekomeowww/fo v1.1.2
github.com/nekomeowww/fo v1.2.1
github.com/nekomeowww/go-pinecone v0.1.0
github.com/nekomeowww/timecapsule/v2 v2.1.3
github.com/nekomeowww/xo v1.1.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/nekomeowww/fo v1.1.2 h1:nc5cvBY9rCOYFI169LvuGeHk17QM3pG7p4+QdwRFQoA=
github.com/nekomeowww/fo v1.1.2/go.mod h1:9avQL8Q+yJPkoy/UtHVm58Tk38cPQmbIoTf/Wtv6l1s=
github.com/nekomeowww/fo v1.2.1 h1:7bb3x2Kz7NAoPVvYnvZf5wdpjsg9QvxgmGpcFMJd/9o=
github.com/nekomeowww/fo v1.2.1/go.mod h1:9avQL8Q+yJPkoy/UtHVm58Tk38cPQmbIoTf/Wtv6l1s=
github.com/nekomeowww/go-pinecone v0.1.0 h1:byYmyHQJ4velNUeECvNuCN6KbXGuyVjSFlvO9VV2zj8=
github.com/nekomeowww/go-pinecone v0.1.0/go.mod h1:p8I6F7G7fSrfaa9k3HpsWNxf2y+W1wqn8tw0jsV9e1s=
github.com/nekomeowww/timecapsule/v2 v2.1.3 h1:KIg6jZSg4RkQG9qV2k5TMq9LUzM6cO3MiXvTyLnqZ9U=
Expand Down
4 changes: 2 additions & 2 deletions internal/bots/telegram/handlers/recap/callback_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,12 @@ func (h *CallbackQueryHandler) handleCallbackQueryUnsubscribe(c *tgbot.Context)
WithEdit(msg).
WithReplyMarkup(tgbotapi.NewInlineKeyboardMarkup(msg.ReplyMarkup.InlineKeyboard...))
}
if actionData.ChatID != chatID || actionData.FromID != fromID {
if actionData.FromID != fromID {
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))
return nil, nil
}

err = h.tgchats.UnsubscribeToAutoRecaps(chatID, fromID)
err = h.tgchats.UnsubscribeToAutoRecaps(actionData.ChatID, fromID)
if err != nil {
return nil, tgbot.
NewExceptionError(err).
Expand Down
3 changes: 2 additions & 1 deletion internal/configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"

"github.com/joho/godotenv"
"github.com/nekomeowww/xo"
"github.com/samber/lo"
goopenai "github.com/sashabaranov/go-openai"
)
Expand Down Expand Up @@ -125,7 +126,7 @@ type Config struct {

func NewConfig() func() (*Config, error) {
return func() (*Config, error) {
envs, err := godotenv.Read()
envs, err := godotenv.Read(xo.RelativePathOf("../../.env"))
if err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/models/chathistories/chat_histories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestExtractTextFromMessage(t *testing.T) {
}, nil
}

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)"
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"
assert.Equal(expect, model.ExtractTextFromMessage(message))
})
}
Expand Down
44 changes: 0 additions & 44 deletions internal/models/smr/smr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,50 +55,6 @@ func TestExtractContentFromURL(t *testing.T) {
assert.NotEmpty(article.Title)
assert.NotEmpty(article.TextContent)
})

t.Run("Twitter", func(t *testing.T) {
t.Run("twitter.com", func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

article, err := model.extractContentFromURL(context.Background(), "https://twitter.com/GoogleDevEurope/status/1640667303158198272")
require.NoError(err)
require.NotNil(article)

assert.NotEmpty(article.Title)
assert.NotEmpty(article.Byline)
assert.NotEmpty(article.Content)
assert.NotEmpty(article.TextContent)
})

t.Run("vxtwitter.com", func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

article, err := model.extractContentFromURL(context.Background(), "https://vxtwitter.com/GoogleDevEurope/status/1640667303158198272")
require.NoError(err)
require.NotNil(article)

assert.NotEmpty(article.Title)
assert.NotEmpty(article.Byline)
assert.NotEmpty(article.Content)
assert.NotEmpty(article.TextContent)
})

t.Run("fxtwitter.com", func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

article, err := model.extractContentFromURL(context.Background(), "https://fxtwitter.com/GoogleDevEurope/status/1640667303158198272")
require.NoError(err)
require.NotNil(article)

assert.NotEmpty(article.Title)
assert.NotEmpty(article.Byline)
assert.NotEmpty(article.Content)
assert.NotEmpty(article.TextContent)
})
})
}

func TestContentTypeCheck(t *testing.T) {
Expand Down
51 changes: 0 additions & 51 deletions pkg/linkprev/linkprev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"context"
"strings"
"testing"
"time"

"github.com/PuerkitoBio/goquery"
"github.com/nekomeowww/insights-bot/pkg/opengraph"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestPreview(t *testing.T) {
Expand All @@ -33,55 +31,6 @@ func TestPreview(t *testing.T) {
},
}, meta)
})

t.Run("Twitter", func(t *testing.T) {
t.Run("twitter.com", func(t *testing.T) {
meta, err := NewClient().Preview(context.Background(), "https://twitter.com/GoogleDevEurope/status/1640667303158198272")
require.NoError(t, err)
assert.Equal(t, Meta{
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",
OpenGraph: opengraph.OpenGraph{
Title: "Google for Developers Europe on X",
Type: "article",
Image: "https://pbs.twimg.com/media/FsTSN8nWwAA278D.png:large",
URL: "https://twitter.com/GoogleDevEurope/status/1640667303158198272",
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!",
SiteName: "Twitter",
},
}, meta)
})

time.Sleep(time.Second)

t.Run("fxtwitter.com", func(t *testing.T) {
meta, err := NewClient().Preview(context.Background(), "https://fxtwitter.com/GoogleDevEurope/status/1640667303158198272")
require.NoError(t, err)
assert.Equal(t, Meta{
OpenGraph: opengraph.OpenGraph{
Title: "Google for Developers Europe (@GoogleDevEurope)",
Image: "https://pbs.twimg.com/media/FsTSN8nWwAA278D.png",
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!",
SiteName: "FixTweet - 🆕 x.com link? Try fixupx.com",
},
}, meta)
})

t.Run("vxtwitter.com", func(t *testing.T) {
meta, err := NewClient().Preview(context.Background(), "https://vxtwitter.com/GoogleDevEurope/status/1640667303158198272")
require.NoError(t, err)
assert.Equal(t, Meta{
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",
OpenGraph: opengraph.OpenGraph{
Title: "Google for Developers Europe on X",
Type: "article",
Image: "https://pbs.twimg.com/media/FsTSN8nWwAA278D.png:large",
URL: "https://twitter.com/GoogleDevEurope/status/1640667303158198272",
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!",
SiteName: "Twitter",
},
}, meta)
})
})
}

func TestNewMetaFrom(t *testing.T) {
Expand Down

0 comments on commit 08525bb

Please sign in to comment.