Skip to content

Commit b797401

Browse files
committed
Fix: username and avatar for RSS
1 parent 02ac07c commit b797401

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require (
4444
golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect
4545
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
4646
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
47-
golang.org/x/text v0.3.7 // indirect
47+
golang.org/x/text v0.4.0 // indirect
4848
google.golang.org/appengine v1.6.7 // indirect
4949
google.golang.org/protobuf v1.28.1 // indirect
5050
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
552552
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
553553
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
554554
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
555+
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
556+
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
555557
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
556558
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
557559
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

rss.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import (
44
"context"
55
"encoding/json"
66
"github.com/mitchellh/hashstructure/v2"
7+
"golang.org/x/text/cases"
8+
"golang.org/x/text/language"
79
"log"
810
"net/http"
911
"regexp"
12+
"strings"
1013
"time"
1114

1215
md "github.com/JohannesKaufmann/html-to-markdown"
@@ -134,12 +137,25 @@ func HandleTimeRss(socialFeed IFeed, state *RssState, _ time.Time, _ time.Durati
134137
rssSends = append(rssSends, RssSend{
135138
Item: item,
136139
Webhooks: webhooksToSend,
140+
Feed: socialFeed,
137141
})
138142
}
139143

140144
return rssSends, nil
141145
}
142146

147+
func generateUsernameRss(feed IFeed) string {
148+
name := feed.GetFeedName()
149+
nameParts := strings.Split(name, "-")
150+
if len(nameParts) < 2 {
151+
return "Ankama"
152+
}
153+
caser := cases.Title(language.English)
154+
game := caser.String(nameParts[0])
155+
newsType := caser.String(nameParts[len(nameParts)-1])
156+
return game + " " + newsType
157+
}
158+
143159
func BuildDiscordHookRss(rssHookBuild RssSend) ([]PreparedHook, error) {
144160
var discordWebhook DiscordWebhook
145161
var res []PreparedHook
@@ -151,6 +167,8 @@ func BuildDiscordHookRss(rssHookBuild RssSend) ([]PreparedHook, error) {
151167
return nil, err
152168
}
153169

170+
discordWebhook.AvatarUrl = "https://discord.dofusdude.com/ankama_rss_logo.jpg"
171+
discordWebhook.Username = generateUsernameRss(rssHookBuild.Feed)
154172
discordWebhook.Embeds = []DiscordEmbed{
155173
{
156174
Title: &rssHookBuild.Item.Title,

types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type RssState struct {
2020
type RssSend struct {
2121
Item gofeed.Item
2222
Webhooks []IHook
23+
Feed IFeed
2324
}
2425

2526
type AlmanaxState struct {

0 commit comments

Comments
 (0)