Skip to content

Commit 4dfdd6f

Browse files
committed
add missing sub settings to list command
1 parent 3b6d65d commit 4dfdd6f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

redditbot/discord.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (b *Bot) OnSubredditAdd(data discord.SlashCommandInteractionData, event *ev
257257
}
258258

259259
if _, err = b.Client.Rest().CreateWebhookMessage(webhook.ID(), webhook.Token, discord.WebhookMessageCreate{
260-
Content: fmt.Sprintf("Added subscription for %s", formatSubreddit(subreddit)),
260+
Content: fmt.Sprintf("Added subscription for %s", formatSubreddit(subreddit, false)),
261261
}, true, 0); err != nil {
262262
_ = event.CreateMessage(discord.MessageCreate{
263263
Content: "Failed to send test message to webhook: " + err.Error(),
@@ -284,7 +284,7 @@ func (b *Bot) OnSubredditAdd(data discord.SlashCommandInteractionData, event *ev
284284
}
285285

286286
_ = event.CreateMessage(discord.MessageCreate{
287-
Content: fmt.Sprintf("Subscribed to %s)", formatSubreddit(subreddit)),
287+
Content: fmt.Sprintf("Subscribed to %s)", formatSubreddit(subreddit, false)),
288288
})
289289
}
290290

@@ -337,7 +337,7 @@ func (b *Bot) OnSubredditUpdate(data discord.SlashCommandInteractionData, event
337337
}
338338

339339
_ = event.CreateMessage(discord.MessageCreate{
340-
Content: fmt.Sprintf("Updated subscription for %s", formatSubreddit(subreddit)),
340+
Content: fmt.Sprintf("Updated subscription for %s", formatSubreddit(subreddit, false)),
341341
Flags: discord.MessageFlagEphemeral,
342342
})
343343
}
@@ -396,7 +396,11 @@ func (b *Bot) OnSubredditList(data discord.SlashCommandInteractionData, event *e
396396
if sub.RedditProxy != "" {
397397
proxy = fmt.Sprintf("`%s`", sub.RedditProxy)
398398
}
399-
content += fmt.Sprintf("- `%s` - `%s` - %s - %s- %s\n", strings.Title(sub.Type), strings.Title(string(sub.FormatType)), role, proxy, formatSubreddit(sub.Subreddit))
399+
linkButton := "enabled"
400+
if !sub.LinkButton {
401+
linkButton = "disabled"
402+
}
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)
400404
}
401405

402406
_ = event.CreateMessage(discord.MessageCreate{
@@ -469,7 +473,7 @@ func (b *Bot) OnDiscordCallback(w http.ResponseWriter, r *http.Request) {
469473
}
470474

471475
if _, err = b.Client.Rest().CreateWebhookMessage(webhookID, webhookToken, discord.WebhookMessageCreate{
472-
Content: fmt.Sprintf("Added subscription for %s", formatSubreddit(setupState.Subreddit)),
476+
Content: fmt.Sprintf("Added subscription for %s", formatSubreddit(setupState.Subreddit, false)),
473477
}, true, 0); err != nil {
474478
_, _ = b.Client.Rest().UpdateInteractionResponse(setupState.Interaction.ApplicationID(), setupState.Interaction.Token(), discord.MessageUpdate{
475479
Content: json.Ptr("Failed to send test message to webhook: " + err.Error()),
@@ -480,12 +484,15 @@ func (b *Bot) OnDiscordCallback(w http.ResponseWriter, r *http.Request) {
480484

481485
delete(b.states, state)
482486
_, _ = b.Client.Rest().UpdateInteractionResponse(setupState.Interaction.ApplicationID(), setupState.Interaction.Token(), discord.MessageUpdate{
483-
Content: json.Ptr(fmt.Sprintf("Subscribed to %s)", formatSubreddit(setupState.Subreddit))),
487+
Content: json.Ptr(fmt.Sprintf("Subscribed to %s)", formatSubreddit(setupState.Subreddit, false))),
484488
Components: &[]discord.ContainerComponent{},
485489
})
486490
_, _ = w.Write([]byte("success, you can close this window now"))
487491
}
488492

489-
func formatSubreddit(subreddit string) string {
493+
func formatSubreddit(subreddit string, suppressEmbed bool) string {
494+
if suppressEmbed {
495+
return fmt.Sprintf("[`r/%s`](<https://reddit.com/r/%s>)", subreddit, subreddit)
496+
}
490497
return fmt.Sprintf("[`r/%s`](https://reddit.com/r/%s)", subreddit, subreddit)
491498
}

0 commit comments

Comments
 (0)