Skip to content

Commit

Permalink
Various bug fixes and vendored libraries update
Browse files Browse the repository at this point in the history
  • Loading branch information
Civil committed Jul 3, 2024
1 parent cfb3200 commit 985809f
Show file tree
Hide file tree
Showing 1,227 changed files with 609,724 additions and 11,176 deletions.
38 changes: 32 additions & 6 deletions endpoints/telegram/telegram_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func InitializeTelegramEndpoint(token string, exitChan <-chan struct{}, database
e.commands = map[string]handlerWithDescription{
"/new": {
f: e.handlerNew,
description: "```/new repo filter\\_name filter_regexp``` \\-\\- creates new available subscription" + `
description: "`/new repo filter\\_name filter_regexp` \\-\\- creates new available subscription" + `
Example:
` + "`/new lomik/go\\-carbon all ^V`" + `
Expand Down Expand Up @@ -335,7 +335,10 @@ func (e *TelegramEndpoint) sendMessage(chatID int64, messageID int, message stri
message,
).WithParseMode(telego.ModeMarkdownV2)
if messageID != 0 {
msg = msg.WithReplyToMessageID(messageID)
replyParams := &telego.ReplyParameters{
MessageID: messageID,
}
msg = msg.WithReplyParameters(replyParams)
}

_, err := e.api.SendMessage(msg)
Expand All @@ -354,7 +357,10 @@ func (e *TelegramEndpoint) sendRawMessage(chatID int64, messageID int, message s
message,
)
if messageID != 0 {
msg = msg.WithReplyToMessageID(messageID)
replyParams := &telego.ReplyParameters{
MessageID: messageID,
}
msg = msg.WithReplyParameters(replyParams)
}

_, err := e.api.SendMessage(msg)
Expand Down Expand Up @@ -498,7 +504,7 @@ func (e *TelegramEndpoint) handlerNew(tokens []string, update *telego.Update) er

feeds.UpdateFeeds([]*feeds.Feed{feed})

return e.sendMessage(update.Message.Chat.ID, update.Message.MessageID, "done")
return e.sendMessage(update.Message.Chat.ID, update.Message.MessageID, fmt.Sprintf("new filter has been created, to subscribe it use `/subscribe %s %s` command", repo, name))
}

func (e *TelegramEndpoint) handlerForceProcess(tokens []string, update *telego.Update) error {
Expand Down Expand Up @@ -625,16 +631,35 @@ func (e *TelegramEndpoint) unsubscribe(logger *zap.Logger, chatID int64, url str
}

func (e *TelegramEndpoint) handlerList(tokens []string, update *telego.Update) error {
response := "Configured feeds:\n"
responses := make([]string, 0, 4)
response := ""
feedsPerMessage := 50
idx := 0
configs.Config.RLock()
for _, feed := range configs.Config.FeedsConfig {
for _, feedFilter := range feed.Filters {
response = response + "`" + feed.Repo + "`: `" + feedFilter.Name + "`\n"
idx++
if idx == feedsPerMessage {
responses = append(responses, response)
response = ""
idx = 0
}
}
}
responses = append(responses, response)
configs.Config.RUnlock()

return e.sendMessage(update.Message.Chat.ID, update.Message.MessageID, response)
var err error
for i, response := range responses {
response = fmt.Sprintf("Configured feeds %v/%v:\n%s", i+1, len(responses), response)
err2 := e.sendMessage(update.Message.Chat.ID, update.Message.MessageID, response)
if err2 != nil {
e.logger.Error("error sending list", zap.Error(err))
err = err2
}
}
return err
}

func (e *TelegramEndpoint) handlerHelp(_ []string, update *telego.Update) error {
Expand All @@ -656,6 +681,7 @@ func (e *TelegramEndpoint) handlerHelp(_ []string, update *telego.Update) error
func (e *TelegramEndpoint) checkUnrecoverableSendError(err error) bool {
if strings.Contains(err.Error(), "chat not found") ||
strings.Contains(err.Error(), "bot was kicked") ||
strings.Contains(err.Error(), "the group chat was deleted") ||
strings.Contains(err.Error(), "bot was blocked by the user") ||
strings.Contains(err.Error(), "not enough rights to send text messages") {
return false
Expand Down
16 changes: 8 additions & 8 deletions feeds/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (f *Feed) processSingleItem(cfg *configs.FeedsConfig, url string, item *gof
}
content = strings.Replace(content, "```", "", 1)

notification += "\nRelease notes:\n```\n" + content + "\n```"
notification += "\nRelease notes:\n```\n" + content + "\n```\n"
if contentTruncated {
notification += "[More](" + item.Link + ")"
}
Expand Down Expand Up @@ -375,13 +375,13 @@ func (f *Feed) ProcessFeed() {
zap.Error(err),
)
if strings.Contains(err.Error(), "404 Not Found") {
err = f.db.RemoveFeed(f.Name, f.Repo, f.Filter, f.MessagePattern)
if err != nil {
f.logger.Error("error removing feed", zap.Error(err))
continue
}
f.logger.Info("feed removed")
return
// err = f.db.RemoveFeed(f.Name, f.Repo, f.Filter, f.MessagePattern)
// if err != nil {
// f.logger.Error("error removing feed", zap.Error(err))
// continue
// }
f.logger.Info("feed should be removed")
// return
}
continue
}
Expand Down
47 changes: 29 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
module github.com/Civil/github2telegram

go 1.21.2
go 1.22.3

toolchain go1.22.5

require (
github.com/lomik/zapwriter v0.0.0-20210624082824-c1161d1eb463
github.com/lunny/html2md v0.0.0-20181018071239-7d234de44546
github.com/mattn/go-sqlite3 v1.14.17
github.com/mmcdole/gofeed v1.2.1
github.com/mymmrac/telego v0.26.3
github.com/mattn/go-sqlite3 v1.14.22
github.com/mmcdole/gofeed v1.3.0
github.com/mymmrac/telego v0.30.2
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.26.0
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/PuerkitoBio/goquery v1.8.0 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/PuerkitoBio/goquery v1.9.2 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/bytedance/sonic v1.11.9 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fasthttp/router v1.4.20 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/fasthttp/router v1.5.1 // indirect
github.com/grbit/go-json v0.11.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/mmcdole/goxpp v1.1.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/mmcdole/goxpp v1.1.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.50.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/text v0.8.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 985809f

Please sign in to comment.