Documentation
¶
Index ¶
- Variables
- type Bot
- func (b *Bot) AddSubscription(sub Subscription) error
- func (b *Bot) Close()
- func (b *Bot) ListenAndServe()
- func (b *Bot) ListenAndServeMetrics()
- func (b *Bot) ListenSubreddits()
- func (b *Bot) OnApplicationCommand(event *events.ApplicationCommandInteractionCreate)
- func (b *Bot) OnDiscordCallback(w http.ResponseWriter, r *http.Request)
- func (b *Bot) OnInfo(event *events.ApplicationCommandInteractionCreate)
- func (b *Bot) OnSubredditAdd(data discord.SlashCommandInteractionData, ...)
- func (b *Bot) OnSubredditList(data discord.SlashCommandInteractionData, ...)
- func (b *Bot) OnSubredditRemove(data discord.SlashCommandInteractionData, ...)
- func (b *Bot) OnSubredditUpdate(data discord.SlashCommandInteractionData, ...)
- func (b *Bot) RemoveSubscription(webhookID snowflake.ID, webhookToken string, err error) error
- func (b *Bot) RemoveSubscriptionByGuildSubreddit(guildID snowflake.ID, subreddit string, reason string) error
- type Config
- type DB
- func (d *DB) AddSubscription(sub Subscription) error
- func (d *DB) Close() error
- func (d *DB) GetAllSubscriptionIDs() ([]snowflake.ID, error)
- func (d *DB) GetSubscription(webhookID snowflake.ID) (*Subscription, error)
- func (d *DB) GetSubscriptionsByChannel(channelID snowflake.ID) ([]Subscription, error)
- func (d *DB) GetSubscriptionsByGuild(guildID snowflake.ID) ([]Subscription, error)
- func (d *DB) GetSubscriptionsByGuildSubreddit(guildID snowflake.ID, subreddit string) (*Subscription, error)
- func (d *DB) HasSubscription(webhookID snowflake.ID) (bool, error)
- func (d *DB) HasSubscriptionByGuildSubreddit(guildID snowflake.ID, subreddit string) (bool, error)
- func (d *DB) RemoveSubscription(webhookID snowflake.ID) (*Subscription, error)
- func (d *DB) RemoveSubscriptionByGuildSubreddit(guildID snowflake.ID, subreddit string) (*Subscription, error)
- func (d *DB) UpdateSubscription(webhookID snowflake.ID, postType string, formatType FormatType, ...) error
- func (d *DB) UpdateSubscriptionLastPost(webhookID snowflake.ID, lastPost time.Time) error
- type DatabaseConfig
- type DatabaseType
- type DiscordConfig
- type FormatType
- type LogConfig
- type LogFormat
- type MetricsConfig
- type PostgresConfig
- type Reddit
- type RedditConfig
- type RedditListing
- type RedditPost
- type RedditResponse
- type SQLiteConfig
- type ServerConfig
- type SetupState
- type SubredditDetail
- type Subscription
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrSubredditNotFound = errors.New("subreddit not found") ErrSubredditForbidden = errors.New("subreddit forbidden") )
View Source
var Commands = []discord.ApplicationCommandCreate{ discord.SlashCommandCreate{ Name: "reddit", Description: "manage your subscribed subreddits", Options: []discord.ApplicationCommandOption{ discord.ApplicationCommandOptionSubCommand{ Name: "add", Description: "add a subreddit to your subscriptions", Options: []discord.ApplicationCommandOption{ discord.ApplicationCommandOptionString{ Name: "subreddit", Description: "the subreddit to add", Required: true, }, discord.ApplicationCommandOptionString{ Name: "type", Description: "the type of posts to send", Required: false, Choices: typeChoices, }, discord.ApplicationCommandOptionString{ Name: "format-type", Description: "how to format the subreddit posts", Required: false, Choices: formatTypeChoices, }, discord.ApplicationCommandOptionRole{ Name: "role", Description: "the role to ping when a post is sent", Required: false, }, discord.ApplicationCommandOptionString{ Name: "proxy", Description: "the proxy to use for the post links such as: https://rxddit.com or https://vxreddit.com", Required: false, }, discord.ApplicationCommandOptionBool{ Name: "link-button", Description: "whether to include a link button in the post (default: true)", Required: false, }, }, }, discord.ApplicationCommandOptionSubCommand{ Name: "update", Description: "update a subreddit in your subscriptions", Options: []discord.ApplicationCommandOption{ discord.ApplicationCommandOptionString{ Name: "subreddit", Description: "the subreddit to update", Required: true, }, discord.ApplicationCommandOptionString{ Name: "type", Description: "the type of posts to send", Required: false, Choices: typeChoices, }, discord.ApplicationCommandOptionString{ Name: "format-type", Description: "how to format the subreddit posts", Required: false, Choices: formatTypeChoices, }, discord.ApplicationCommandOptionRole{ Name: "role", Description: "the role to ping when a post is sent", Required: false, }, discord.ApplicationCommandOptionString{ Name: "proxy", Description: "the proxy to use for the post links such as: https://rxddit.com", Required: false, }, discord.ApplicationCommandOptionBool{ Name: "link-button", Description: "whether to include a link button in the post (default: true)", Required: false, }, }, }, discord.ApplicationCommandOptionSubCommand{ Name: "remove", Description: "remove a subreddit from your subscriptions", Options: []discord.ApplicationCommandOption{ discord.ApplicationCommandOptionString{ Name: "subreddit", Description: "the subreddit to remove", Required: true, }, }, }, discord.ApplicationCommandOptionSubCommand{ Name: "list", Description: "list your subscribed subreddits", Options: []discord.ApplicationCommandOption{ discord.ApplicationCommandOptionChannel{ Name: "channel", Description: "the channel to list the subreddits for", Required: false, }, }, }, }, DefaultMemberPermissions: json.NewNullablePtr(discord.PermissionManageGuild), }, discord.SlashCommandCreate{ Name: "info", Description: "get info about me", }, }
View Source
var (
ErrSubscriptionNotFound = errors.New("subscription not found")
)
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct { Client bot.Client Server *http.Server MetricsServer *http.Server // contains filtered or unexported fields }
func (*Bot) AddSubscription ¶
func (b *Bot) AddSubscription(sub Subscription) error
func (*Bot) ListenAndServe ¶
func (b *Bot) ListenAndServe()
func (*Bot) ListenAndServeMetrics ¶
func (b *Bot) ListenAndServeMetrics()
func (*Bot) ListenSubreddits ¶
func (b *Bot) ListenSubreddits()
func (*Bot) OnApplicationCommand ¶
func (b *Bot) OnApplicationCommand(event *events.ApplicationCommandInteractionCreate)
func (*Bot) OnDiscordCallback ¶
func (b *Bot) OnDiscordCallback(w http.ResponseWriter, r *http.Request)
func (*Bot) OnInfo ¶
func (b *Bot) OnInfo(event *events.ApplicationCommandInteractionCreate)
func (*Bot) OnSubredditAdd ¶
func (b *Bot) OnSubredditAdd(data discord.SlashCommandInteractionData, event *events.ApplicationCommandInteractionCreate)
func (*Bot) OnSubredditList ¶
func (b *Bot) OnSubredditList(data discord.SlashCommandInteractionData, event *events.ApplicationCommandInteractionCreate)
func (*Bot) OnSubredditRemove ¶
func (b *Bot) OnSubredditRemove(data discord.SlashCommandInteractionData, event *events.ApplicationCommandInteractionCreate)
func (*Bot) OnSubredditUpdate ¶
func (b *Bot) OnSubredditUpdate(data discord.SlashCommandInteractionData, event *events.ApplicationCommandInteractionCreate)
func (*Bot) RemoveSubscription ¶
type Config ¶
type Config struct { TestMode bool `koanf:"test_mode"` Log LogConfig `koanf:"log"` Server ServerConfig `koanf:"server"` Discord DiscordConfig `koanf:"discord"` Reddit RedditConfig `koanf:"reddit"` Database DatabaseConfig `koanf:"database"` Metrics MetricsConfig `koanf:"metrics"` }
func ReadConfig ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) AddSubscription ¶
func (d *DB) AddSubscription(sub Subscription) error
func (*DB) GetAllSubscriptionIDs ¶
func (*DB) GetSubscription ¶
func (d *DB) GetSubscription(webhookID snowflake.ID) (*Subscription, error)
func (*DB) GetSubscriptionsByChannel ¶
func (d *DB) GetSubscriptionsByChannel(channelID snowflake.ID) ([]Subscription, error)
func (*DB) GetSubscriptionsByGuild ¶
func (d *DB) GetSubscriptionsByGuild(guildID snowflake.ID) ([]Subscription, error)
func (*DB) GetSubscriptionsByGuildSubreddit ¶
func (d *DB) GetSubscriptionsByGuildSubreddit(guildID snowflake.ID, subreddit string) (*Subscription, error)
func (*DB) HasSubscription ¶
func (*DB) HasSubscriptionByGuildSubreddit ¶
func (*DB) RemoveSubscription ¶
func (d *DB) RemoveSubscription(webhookID snowflake.ID) (*Subscription, error)
func (*DB) RemoveSubscriptionByGuildSubreddit ¶
func (d *DB) RemoveSubscriptionByGuildSubreddit(guildID snowflake.ID, subreddit string) (*Subscription, error)
func (*DB) UpdateSubscription ¶
type DatabaseConfig ¶
type DatabaseConfig struct { Type DatabaseType `cfg:"type"` PostgresConfig PostgresConfig `koanf:"postgres"` SQLite SQLiteConfig `koanf:"sqlite"` }
func (DatabaseConfig) String ¶
func (c DatabaseConfig) String() string
func (DatabaseConfig) Validate ¶
func (c DatabaseConfig) Validate() error
type DatabaseType ¶
type DatabaseType string
const ( DatabaseTypePostgres DatabaseType = "postgres" DatabaseTypeSQLite DatabaseType = "sqlite" )
type DiscordConfig ¶
type DiscordConfig struct { Token string `koanf:"token"` ClientSecret string `koanf:"client_secret"` SyncCommands bool `koanf:"sync_commands"` }
func (DiscordConfig) String ¶
func (c DiscordConfig) String() string
func (DiscordConfig) Validate ¶
func (c DiscordConfig) Validate() error
type FormatType ¶
type FormatType string
const ( FormatTypeEmbed FormatType = "embed" FormatTypeText FormatType = "text" FormatTypeLink FormatType = "link" FormatTypeLinkWithTitle FormatType = "link_with_title" )
func (FormatType) Name ¶
func (f FormatType) Name() string
type LogConfig ¶
type MetricsConfig ¶
type MetricsConfig struct { Enabled bool `koanf:"enabled"` ListenAddr string `koanf:"listen_addr"` Endpoint string `koanf:"endpoint"` }
func (MetricsConfig) String ¶
func (c MetricsConfig) String() string
func (MetricsConfig) Validate ¶
func (c MetricsConfig) Validate() error
type PostgresConfig ¶
type PostgresConfig struct { Host string `koanf:"host"` Port int `koanf:"port"` Username string `koanf:"username"` Password string `koanf:"password"` Database string `koanf:"database"` SSLMode string `koanf:"ssl_mode"` }
func (PostgresConfig) DataSourceName ¶
func (c PostgresConfig) DataSourceName() string
func (PostgresConfig) String ¶
func (c PostgresConfig) String() string
func (PostgresConfig) Validate ¶
func (c PostgresConfig) Validate() error
type Reddit ¶
type Reddit struct {
// contains filtered or unexported fields
}
func (*Reddit) CheckSubreddit ¶
func (*Reddit) GetPostsUntil ¶
type RedditConfig ¶
type RedditConfig struct { ClientID string `koanf:"client_id"` ClientSecret string `koanf:"client_secret"` RequestsPerMinute int `koanf:"requests_per_minute"` MaxPages int `koanf:"max_pages"` }
func (RedditConfig) String ¶
func (c RedditConfig) String() string
func (RedditConfig) Validate ¶
func (c RedditConfig) Validate() error
type RedditListing ¶
type RedditPost ¶
type RedditPost struct { Selftext string `json:"selftext"` AuthorFullname string `json:"author_fullname"` Title string `json:"title"` SubredditNamePrefixed string `json:"subreddit_name_prefixed"` ID string `json:"id"` Name string `json:"name"` Author string `json:"author"` URL string `json:"url"` Permalink string `json:"permalink"` CreatedUtc float64 `json:"created_utc"` SrDetail SubredditDetail `json:"sr_detail"` }
type RedditResponse ¶
type SQLiteConfig ¶
type SQLiteConfig struct {
Path string `koanf:"path"`
}
func (SQLiteConfig) DataSourceName ¶
func (c SQLiteConfig) DataSourceName() string
func (SQLiteConfig) String ¶
func (c SQLiteConfig) String() string
func (SQLiteConfig) Validate ¶
func (c SQLiteConfig) Validate() error
type ServerConfig ¶
type ServerConfig struct { Enabled bool `koanf:"enabled"` ListenAddr string `koanf:"listen_addr"` Endpoint string `koanf:"endpoint"` RedirectURL string `koanf:"redirect_url"` }
func (ServerConfig) String ¶
func (c ServerConfig) String() string
func (ServerConfig) Validate ¶
func (c ServerConfig) Validate() error
type SetupState ¶
type SetupState struct { Subreddit string PostType string FormatType FormatType RoleID snowflake.ID RedditProxy string LinkButton bool Interaction discord.ApplicationCommandInteraction }
type SubredditDetail ¶
type SubredditDetail struct {
CommunityIcon string `json:"community_icon"`
}
type Subscription ¶
type Subscription struct { Subreddit string `db:"subreddit"` Type string `db:"type"` FormatType FormatType `db:"format_type"` GuildID snowflake.ID `db:"guild_id"` ChannelID snowflake.ID `db:"channel_id"` WebhookID snowflake.ID `db:"webhook_id"` WebhookToken string `db:"webhook_token"` LastPost time.Time `db:"last_post"` RoleID snowflake.ID `db:"role_id"` RedditProxy string `db:"reddit_proxy"` LinkButton bool `db:"link_button"` }
Click to show internal directories.
Click to hide internal directories.