Skip to content

Commit 318658f

Browse files
committed
bring back old link type with title
1 parent 4dfdd6f commit 318658f

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

redditbot/database.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,29 @@ var (
1515
ErrSubscriptionNotFound = errors.New("subscription not found")
1616
)
1717

18-
type FormatType string
19-
2018
const (
21-
FormatTypeEmbed FormatType = "embed"
22-
FormatTypeText FormatType = "text"
23-
FormatTypeLink FormatType = "link"
19+
FormatTypeEmbed FormatType = "embed"
20+
FormatTypeText FormatType = "text"
21+
FormatTypeLink FormatType = "link"
22+
FormatTypeLinkWithTitle FormatType = "link_with_title"
2423
)
2524

25+
type FormatType string
26+
27+
func (f FormatType) String() string {
28+
switch f {
29+
case FormatTypeEmbed:
30+
return "Embed"
31+
case FormatTypeText:
32+
return "Text"
33+
case FormatTypeLink:
34+
return "Link"
35+
case FormatTypeLinkWithTitle:
36+
return "Link with Title"
37+
}
38+
return "Unknown"
39+
}
40+
2641
type Subscription struct {
2742
Subreddit string `db:"subreddit"`
2843
Type string `db:"type"`

redditbot/discord.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ var typeChoices = []discord.ApplicationCommandOptionChoiceString{
3434

3535
var formatTypeChoices = []discord.ApplicationCommandOptionChoiceString{
3636
{
37-
Name: strings.Title(string(FormatTypeEmbed)),
37+
Name: FormatTypeEmbed.String(),
3838
Value: string(FormatTypeEmbed),
3939
},
4040
{
41-
Name: strings.Title(string(FormatTypeText)),
41+
Name: FormatTypeText.String(),
4242
Value: string(FormatTypeText),
4343
},
4444
{
45-
Name: strings.Title(string(FormatTypeLink)),
45+
Name: FormatTypeLink.String(),
4646
Value: string(FormatTypeLink),
4747
},
48+
{
49+
Name: FormatTypeLinkWithTitle.String(),
50+
Value: string(FormatTypeLinkWithTitle),
51+
},
4852
}
4953

5054
var Commands = []discord.ApplicationCommandCreate{
@@ -400,7 +404,7 @@ func (b *Bot) OnSubredditList(data discord.SlashCommandInteractionData, event *e
400404
if !sub.LinkButton {
401405
linkButton = "disabled"
402406
}
403-
content += fmt.Sprintf("- %s - type: `%s` - format: `%s` - role: %s - proxy: %s - link-button: `%s`\n", formatSubreddit(sub.Subreddit, true), strings.Title(sub.Type), strings.Title(string(sub.FormatType)), role, proxy, linkButton)
407+
content += fmt.Sprintf("- %s - type: `%s` - format: `%s` - role: %s - proxy: %s - link-button: `%s`\n", formatSubreddit(sub.Subreddit, true), strings.Title(sub.Type), sub.FormatType.String(), role, proxy, linkButton)
404408
}
405409

406410
_ = event.CreateMessage(discord.MessageCreate{

redditbot/subscriptions.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ func (b *Bot) checkSubscription(sub Subscription) {
170170
}
171171

172172
func (b *Bot) sendPost(sub Subscription, post RedditPost) bool {
173+
proxy := defaultRedditProxy
174+
if sub.RedditProxy != "" {
175+
proxy = sub.RedditProxy
176+
}
177+
173178
var webhookMessageCreate discord.WebhookMessageCreate
174179
switch sub.FormatType {
175180
case FormatTypeEmbed:
@@ -198,21 +203,17 @@ func (b *Bot) sendPost(sub Subscription, post RedditPost) bool {
198203
Embeds: []discord.Embed{embed},
199204
}
200205
case FormatTypeText:
201-
proxy := defaultRedditProxy
202-
if sub.RedditProxy != "" {
203-
proxy = sub.RedditProxy
204-
}
205206
webhookMessageCreate = discord.WebhookMessageCreate{
206207
Content: fmt.Sprintf("## [%s](%s%s)\n%s", post.Title, proxy, post.Permalink, cutString(quoteString(html.UnescapeString(post.Selftext)), 4000)),
207208
}
208209
case FormatTypeLink:
209-
proxy := defaultRedditProxy
210-
if sub.RedditProxy != "" {
211-
proxy = sub.RedditProxy
212-
}
213210
webhookMessageCreate = discord.WebhookMessageCreate{
214211
Content: fmt.Sprintf("New [post](%s%s) in [`%s`](<%s>)", proxy, post.Permalink, post.SubredditNamePrefixed, "https://reddit.com/"+post.SubredditNamePrefixed),
215212
}
213+
case FormatTypeLinkWithTitle:
214+
webhookMessageCreate = discord.WebhookMessageCreate{
215+
Content: fmt.Sprintf("[%s](%s%s)", post.Title, proxy, post.Permalink),
216+
}
216217
}
217218

218219
if sub.RoleID != 0 {
@@ -243,7 +244,7 @@ func (b *Bot) sendPost(sub Subscription, post RedditPost) bool {
243244
},
244245
}
245246
}
246-
247+
247248
postsSent.With(prometheus.Labels{
248249
"subreddit": sub.Subreddit,
249250
"type": sub.Type,

0 commit comments

Comments
 (0)