Documentation ¶
Index ¶
- Constants
- Variables
- func BaseEditHandler(inner web.ControllerHandlerFunc) web.ControllerHandlerFunc
- func KeyLastVidID(channel string) string
- func KeyLastVidTime(channel string) string
- func MaxFeedsEnabledForContext(ctx context.Context) int
- func RegisterPlugin()
- type ContextKey
- type Link
- type LinkEntry
- type Plugin
- func (p *Plugin) AddFeed(guildID, discordChannelID int64, ytChannel *youtube.Channel, ...) (*models.YoutubeChannelSubscription, error)
- func (p *Plugin) CheckVideo(parsedVideo XMLFeed) error
- func (p *Plugin) DisableChannelFeeds(channelID int64) error
- func (p *Plugin) DisableFeed(elem *mqueue.QueuedElement, err error)
- func (p *Plugin) DisableGuildFeeds(guildID int64) error
- func (p *Plugin) HandleEdit(w http.ResponseWriter, r *http.Request) (templateData web.TemplateData, err error)
- func (p *Plugin) HandleFeedUpdate(w http.ResponseWriter, r *http.Request)
- func (p *Plugin) HandleNew(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func (p *Plugin) HandleRemove(w http.ResponseWriter, r *http.Request) (templateData web.TemplateData, err error)
- func (p *Plugin) HandleYoutube(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func (p *Plugin) HandleYoutubeAnnouncement(w http.ResponseWriter, r *http.Request) (templateData web.TemplateData, err error)
- func (p *Plugin) InitWeb()
- func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func (p *Plugin) MaybeAddChannelWatch(lock bool, channel string) error
- func (p *Plugin) MaybeRemoveChannelWatch(channel string)
- func (p *Plugin) OnRemovedPremiumGuild(guildID int64) error
- func (p *Plugin) PluginInfo() *common.PluginInfo
- func (p *Plugin) SetupClient() error
- func (p *Plugin) StartFeed()
- func (p *Plugin) Status() (string, string)
- func (p *Plugin) StopFeed(wg *sync.WaitGroup)
- func (p *Plugin) ValidateSubscription(w http.ResponseWriter, r *http.Request, query url.Values)
- func (p *Plugin) WebSubSubscribe(ytChannelID string) error
- func (p *Plugin) WebSubUnsubscribe(ytChannelID string) error
- type XMLFeed
- type YoutubeAnnouncementForm
- type YoutubeFeedForm
Constants ¶
View Source
const ( RedisChannelsLockKey = "youtube_subbed_channel_lock" RedisKeyPublishedVideoList = "youtube_published_videos" RedisKeyWebSubChannels = "youtube_registered_websub_channels" GoogleWebsubHub = "https://pubsubhubbub.appspot.com/subscribe" )
View Source
const ( GuildMaxFeeds = 300 GuildMaxEnabledFeeds = 10 GuildMaxEnabledFeedsPremium = 250 )
View Source
const (
WebSubCheckInterval = time.Second * 10
)
Variables ¶
View Source
var ( ErrNoChannel = errors.New("no channel with that id found") ErrMaxCustomMessageLength = errors.New("max length of custom message can be 500 chars") )
View Source
var DBSchemas = []string{`
CREATE TABLE IF NOT EXISTS youtube_channel_subscriptions (
id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
guild_id TEXT NOT NULL,
channel_id TEXT NOT NULL,
youtube_channel_id TEXT NOT NULL,
youtube_channel_name TEXT NOT NULL,
mention_everyone BOOLEAN NOT NULL,
mention_roles BIGINT[],
publish_livestream BOOLEAN NOT NULL DEFAULT TRUE,
publish_shorts BOOLEAN NOT NULL DEFAULT TRUE,
enabled BOOLEAN NOT NULL DEFAULT TRUE
);
`, `
-- Old tables managed with gorm are missing NOT NULL constraints on some columns
-- that are never null in existing records; add them as needed.
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN created_at SET NOT NULL;
`, `
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN updated_at SET NOT NULL;
`, `
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN guild_id SET NOT NULL;
`, `
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN channel_id SET NOT NULL;
`, `
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN youtube_channel_id SET NOT NULL;
`, `
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN youtube_channel_name SET NOT NULL;
`, `
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN mention_everyone SET NOT NULL;
-- Can't add a NOT NULL constraint to mention_roles because too many records in
-- production have it set to null.
`, `
-- The migration for the publish_livestream, publish_shorts, and enabled columns is
-- more involved. These columns were added later and so it is possible that they are
-- null in some older records. Therefore, we first replace these missing values with
-- defaults before adding the NOT NULL constraint.
DO $$
BEGIN
-- only run if we haven't added the NOT NULL constraint yet
IF EXISTS(SELECT 1 FROM information_schema.columns WHERE table_name='youtube_channel_subscriptions' AND column_name='publish_livestream' AND is_nullable='yes') THEN
UPDATE youtube_channel_subscriptions SET publish_livestream = TRUE WHERE publish_livestream IS NULL;
UPDATE youtube_channel_subscriptions SET publish_shorts = TRUE WHERE publish_shorts IS NULL;
UPDATE youtube_channel_subscriptions SET enabled = TRUE WHERE enabled IS NULL;
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN publish_livestream SET NOT NULL;
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN publish_shorts SET NOT NULL;
ALTER TABLE youtube_channel_subscriptions ALTER COLUMN enabled SET NOT NULL;
END IF;
END $$;
`, `
CREATE TABLE IF NOT EXISTS youtube_announcements (
guild_id BIGINT PRIMARY KEY,
message TEXT NOT NULL,
enabled BOOLEAN NOT NULL DEFAULT FALSE
);
`, `
ALTER TABLE youtube_announcements ALTER COLUMN guild_id SET NOT NULL;
`, `
ALTER TABLE youtube_announcements ALTER COLUMN message SET NOT NULL;
`, `
ALTER TABLE youtube_announcements ALTER COLUMN enabled SET NOT NULL;
`}
View Source
var (
ErrIDNotFound = errors.New("ID not found")
)
View Source
var PageHTML string
Functions ¶
func BaseEditHandler ¶
func BaseEditHandler(inner web.ControllerHandlerFunc) web.ControllerHandlerFunc
func KeyLastVidID ¶
func KeyLastVidTime ¶
func RegisterPlugin ¶
func RegisterPlugin()
Types ¶
type Plugin ¶
func (*Plugin) CheckVideo ¶
func (*Plugin) DisableChannelFeeds ¶
func (*Plugin) DisableFeed ¶
func (p *Plugin) DisableFeed(elem *mqueue.QueuedElement, err error)
Remove feeds if they don't point to a proper channel
func (*Plugin) DisableGuildFeeds ¶
func (*Plugin) HandleEdit ¶
func (p *Plugin) HandleEdit(w http.ResponseWriter, r *http.Request) (templateData web.TemplateData, err error)
func (*Plugin) HandleFeedUpdate ¶
func (p *Plugin) HandleFeedUpdate(w http.ResponseWriter, r *http.Request)
func (*Plugin) HandleNew ¶
func (p *Plugin) HandleNew(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func (*Plugin) HandleRemove ¶
func (p *Plugin) HandleRemove(w http.ResponseWriter, r *http.Request) (templateData web.TemplateData, err error)
func (*Plugin) HandleYoutube ¶
func (p *Plugin) HandleYoutube(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func (*Plugin) HandleYoutubeAnnouncement ¶
func (p *Plugin) HandleYoutubeAnnouncement(w http.ResponseWriter, r *http.Request) (templateData web.TemplateData, err error)
func (*Plugin) LoadServerHomeWidget ¶
func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func (*Plugin) MaybeAddChannelWatch ¶
maybeAddChannelWatch adds a channel watch to redis, if there wasn't one before
func (*Plugin) MaybeRemoveChannelWatch ¶
maybeRemoveChannelWatch checks the channel for subs, if it has none then it removes it from the watchlist in redis.
func (*Plugin) OnRemovedPremiumGuild ¶
func (*Plugin) PluginInfo ¶
func (p *Plugin) PluginInfo() *common.PluginInfo
func (*Plugin) SetupClient ¶
func (*Plugin) ValidateSubscription ¶
func (*Plugin) WebSubSubscribe ¶
func (*Plugin) WebSubUnsubscribe ¶
type XMLFeed ¶
type XMLFeed struct { Xmlns string `xml:"xmlns,attr"` Link []Link `xml:"link"` ChannelID string `xml:"entry>channelId"` Published string `xml:"entry>published"` VideoId string `xml:"entry>videoId"` Yt string `xml:"yt,attr"` LinkEntry Link `xml:"entry>link"` AuthorUri string `xml:"entry>author>uri"` AuthorName string `xml:"entry>author>name"` UpdatedEntry string `xml:"entry>updated"` Title string `xml:"title"` TitleEntry string `xml:"entry>title"` Id string `xml:"entry>id"` Updated string `xml:"updated"` }
type YoutubeAnnouncementForm ¶
Click to show internal directories.
Click to hide internal directories.