Skip to content

Commit d180d17

Browse files
author
Igor Rybak
committed
remove unused code. remove redundant logs
1 parent 3ff1e96 commit d180d17

File tree

4 files changed

+15
-52
lines changed

4 files changed

+15
-52
lines changed

habr/feedReader.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type FeedReader interface {
2020
}
2121

2222
type FeedItem struct {
23-
LinkToImage string
2423
Message string
2524
ID string
2625
}
@@ -96,13 +95,11 @@ func NewHabrReader() FeedReader {
9695
}
9796

9897
func processItem(item *gofeed.Item) FeedItem {
99-
linkToImage := getFirstImageLink(item.Description)
10098
msg := "<a href=\"" + item.Link + "\">" + item.Title + "</a>\n"
10199
msg += stripTags(item.Description)
102100
postID := getPostID(item.Link)
103101

104102
return FeedItem{
105-
LinkToImage: linkToImage,
106103
Message: msg,
107104
ID: postID}
108105
}
@@ -152,7 +149,7 @@ func (HabrReader) GetBestFeed() []FeedItem {
152149
log.Printf("Feed response: %s", body)
153150
log.Fatalln("Error parsing RSS feed:", err.Error())
154151
}
155-
log.Printf("RSS feed is pulled. Description %s, Published: %s", feed.Description, feed.Published)
152+
log.Printf("RSS feed is pulled. Published: %s, Number of items: %d", feed.Published, len(feed.Items))
156153

157154
for _, item := range feed.Items {
158155
response = append(response, processItem(item))

habrbestbot_test.go

+10-20
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ func TestHabrBestBot_updateFeedToChannel_OneItem(t *testing.T) {
1313
fr := feedReaderMocked{
1414
items: []habr.FeedItem{
1515
{
16-
LinkToImage: "http://",
17-
Message: "text",
18-
ID: "id1",
16+
Message: "text",
17+
ID: "id1",
1918
},
2019
},
2120
}
@@ -37,14 +36,12 @@ func TestHabrBestBot_updateFeedToChannel_TwoItems(t *testing.T) {
3736
fr := feedReaderMocked{
3837
items: []habr.FeedItem{
3938
{
40-
LinkToImage: "http://",
41-
Message: "text",
42-
ID: "id1",
39+
Message: "text",
40+
ID: "id1",
4341
},
4442
{
45-
LinkToImage: "http://",
46-
Message: "text",
47-
ID: "id2",
43+
Message: "text",
44+
ID: "id2",
4845
},
4946
},
5047
}
@@ -67,14 +64,12 @@ func TestHabrBestBot_updateFeedToChannel_TwoSameItems(t *testing.T) {
6764
fr := feedReaderMocked{
6865
items: []habr.FeedItem{
6966
{
70-
LinkToImage: "http://",
71-
Message: "text",
72-
ID: "id1",
67+
Message: "text",
68+
ID: "id1",
7369
},
7470
{
75-
LinkToImage: "http://",
76-
Message: "text",
77-
ID: "id1",
71+
Message: "text",
72+
ID: "id1",
7873
},
7974
},
8075
}
@@ -94,11 +89,6 @@ type telegramBotMocked struct {
9489
newMessagesCount int
9590
}
9691

97-
func (t *telegramBotMocked) NewMessageToChat(chatID int64, text string) error {
98-
t.newMessagesCount++
99-
return nil
100-
}
101-
10292
func (t *telegramBotMocked) NewMessageToChannel(username string, text string) error {
10393
t.newMessagesCount++
10494
return nil

telegram/bot.go

+4-27
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@ import (
66
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
77
)
88

9-
type updateMessage struct {
10-
Text string
11-
ChatID int64
12-
}
13-
14-
type updatesChannel <-chan updateMessage
15-
169
type Bot struct {
17-
botAPI *tgbotapi.BotAPI
18-
updates updatesChannel
10+
botAPI *tgbotapi.BotAPI
1911
}
2012

2113
// NewBot returns an instance of Bot which implements Messenger interface
@@ -32,29 +24,14 @@ func NewBot(token string) Messenger {
3224
return &b
3325
}
3426

35-
func (b *Bot) NewMessageToChat(chatID int64, text string) error {
36-
if len(text) > 4096 {
37-
log.Printf("trim too long string %s", text)
38-
text = text[:4090] + "..."
39-
}
40-
msg := tgbotapi.NewMessage(chatID, text)
41-
msg.ParseMode = "HTML"
42-
log.Println(msg)
43-
_, err := b.botAPI.Send(msg)
44-
if err != nil {
45-
return err
46-
}
47-
return nil
48-
}
49-
5027
func (b *Bot) NewMessageToChannel(username string, text string) error {
51-
if len(text) > 4096 {
28+
MAX_LENGTH := 4090
29+
if len(text) > MAX_LENGTH {
5230
log.Printf("trim too long string %s", text)
53-
text = text[:4090] + "..."
31+
text = text[:MAX_LENGTH] + "..."
5432
}
5533
msg := tgbotapi.NewMessageToChannel(username, text)
5634
msg.ParseMode = "HTML"
57-
log.Println(msg)
5835
_, err := b.botAPI.Send(msg)
5936
if err != nil {
6037
return err

telegram/messenger.go

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package telegram
22

33
type Messenger interface {
4-
NewMessageToChat(chatID int64, text string) error
54
NewMessageToChannel(username string, text string) error
65
}

0 commit comments

Comments
 (0)