Documentation ¶
Index ¶
- Constants
- Variables
- func AllGuildsOncePremium() (map[int64]time.Time, error)
- func AttachSlotToGuild(ctx context.Context, slotID int64, userID int64, guildID int64) error
- func ContextPremium(ctx context.Context) bool
- func CreatePremiumSlot(ctx context.Context, exec boil.ContextExecutor, userID int64, ...) (*models.PremiumSlot, error)
- func DetachSlotFromGuild(ctx context.Context, slotID int64, userID int64) error
- func GenerateCode(ctx context.Context, message string, duration time.Duration) (*models.PremiumCode, error)
- func HandleGetPremiumMainPage(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
- func HandlePostDetachGuildSlot(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
- func HandlePostLookupCode(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
- func HandlePostRedeemCode(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
- func HandlePostUpdateSlot(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
- func IsGuildPremium(guildID int64) (bool, error)
- func LookupCode(ctx context.Context, code string) (*models.PremiumCode, error)
- func PremiumGuildMW(inner http.Handler) http.Handler
- func PremiumProvidedBy(guildID int64) (int64, error)
- func RedeemCode(ctx context.Context, code string, userID int64) error
- func RegisterGuildPremiumSource(source GuildPremiumSource)
- func RegisterPlugin()
- func RegisterPremiumSource(source PremiumSource)
- func RemovePremiumSlots(ctx context.Context, exec boil.ContextExecutor, userID int64, ...) error
- func SlotDurationLeft(slot *models.PremiumSlot) (duration time.Duration)
- func SlotExpired(ctx context.Context, slot *models.PremiumSlot) error
- func TryRetryGenerateCode(ctx context.Context, message string, duration time.Duration) (*models.PremiumCode, error)
- func UserPremiumSlots(ctx context.Context, userID int64) (slots []*models.PremiumSlot, err error)
- type CodePremiumSource
- type CtxKey
- type GuildPremiumSource
- type NewPremiumGuildListener
- type Plugin
- func (p *Plugin) AddCommands()
- func (p *Plugin) AllFeatureFlags() []string
- func (p *Plugin) BotInit()
- func (p *Plugin) InitWeb()
- func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func (p *Plugin) PluginInfo() *common.PluginInfo
- func (p *Plugin) RunBackgroundWorker()
- func (p *Plugin) ServerHomeWidgetOrder() int
- func (p *Plugin) StopBackgroundWorker(wg *sync.WaitGroup)
- func (p *Plugin) UpdateFeatureFlags(guildID int64) ([]string, error)
- func (p *Plugin) UpdateFeatureFlagsBatch() (map[int64][]string, error)
- type PremiumSource
- type PremiumTier
- type RemovedPremiumGuildListener
- type SlotGuildPremiumSource
- func (s *SlotGuildPremiumSource) AllGuildsPremiumTiers() (map[int64]PremiumTier, error)
- func (s *SlotGuildPremiumSource) GuildPremiumDetails(guildID int64) (tier PremiumTier, humanDetails []string, err error)
- func (s *SlotGuildPremiumSource) GuildPremiumTier(guildID int64) (PremiumTier, error)
- func (s *SlotGuildPremiumSource) Name() string
- type UpdateData
Constants ¶
const ( PremiumStateMaxMessags = 10000 PremiumStateMaxMessageAge = time.Hour * 12 )
const ( // Hash // Key: guild id's // Value: the user id's providing the premium status RedisKeyPremiumGuilds = "premium_activated_guilds" RedisKeyPremiumGuildsTmp = "premium_activated_guilds_tmp" RedisKeyPremiumGuildLastActive = "premium_guild_last_active" )
const ( FeatureFlagPremiumPlus = "premium_plus" FeatureFlagPremiumFull = "premium_full" )
Variables ¶
var ( ErrCodeExpired = errors.New("Code expired") ErrCodeNotFound = errors.New("Code not found") )
var ( PremiumSources []PremiumSource GuildPremiumSources []GuildPremiumSource )
var ( ErrSlotNotFound = errors.New("premium slot not found") ErrGuildAlreadyPremium = errors.New("guild already assigned premium from another slot") )
var DBSchemas = []string{`
CREATE TABLE IF NOT EXISTS premium_slots (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
attached_at TIMESTAMP WITH TIME ZONE,
user_id BIGINT NOT NULL,
guild_id BIGINT,
title TEXT NOT NULL,
message TEXT NOT NULL,
source TEXT NOT NULL,
source_id BIGINT NOT NULL,
full_duration BIGINT NOT NULL,
permanent BOOLEAN NOT NULL,
duration_remaining BIGINT NOT NULL
);
`, `
ALTER TABLE premium_slots ADD COLUMN IF NOT EXISTS tier INT NOT NULL DEFAULT 1;
`, `
CREATE TABLE IF NOT EXISTS premium_codes (
id BIGSERIAL PRIMARY KEY,
code TEXT UNIQUE NOT NULL,
message TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
used_at TIMESTAMP WITH TIME ZONE,
slot_id BIGINT references premium_slots(id),
user_id BIGINT,
guild_id BIGINT,
permanent BOOLEAN NOT NULL,
duration BIGINT NOT NULL
);
`, `
CREATE INDEX IF NOT EXISTS premium_codes_code_idx ON premium_codes(code);
`}
var (
ErrCodeCollision = errors.New("Code collision")
)
var PremiumHTML string
var PremiumPerksHTML string
Functions ¶
func AllGuildsOncePremium ¶
AllGuildsOncePremium returns all the guilds that have has premium once, and the last time that was active
func AttachSlotToGuild ¶
func ContextPremium ¶
func CreatePremiumSlot ¶
func CreatePremiumSlot(ctx context.Context, exec boil.ContextExecutor, userID int64, source, title, message string, sourceSlotID int64, duration time.Duration, tier PremiumTier) (*models.PremiumSlot, error)
func DetachSlotFromGuild ¶
func GenerateCode ¶
func GenerateCode(ctx context.Context, message string, duration time.Duration) (*models.PremiumCode, error)
GenerateCode generates a redeemable premium code with the specified duration (-1 for permanent) and message
func HandleGetPremiumMainPage ¶
func HandleGetPremiumMainPage(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
func HandlePostDetachGuildSlot ¶
func HandlePostDetachGuildSlot(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
func HandlePostLookupCode ¶
func HandlePostLookupCode(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
func HandlePostRedeemCode ¶
func HandlePostRedeemCode(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
func HandlePostUpdateSlot ¶
func HandlePostUpdateSlot(w http.ResponseWriter, r *http.Request) (tmpl web.TemplateData, err error)
func IsGuildPremium ¶
IsGuildPremium return true if the provided guild has the premium status or not This is a legacy function mostly as anything equal to and above plus is counted as premium if you want more granular control use the other functions
func LookupCode ¶
func PremiumGuildMW ¶
PremiumGuildMW adds premium data to context and tmpl vars
func PremiumProvidedBy ¶
func RegisterGuildPremiumSource ¶
func RegisterGuildPremiumSource(source GuildPremiumSource)
func RegisterPlugin ¶
func RegisterPlugin()
func RegisterPremiumSource ¶
func RegisterPremiumSource(source PremiumSource)
func RemovePremiumSlots ¶
func RemovePremiumSlots(ctx context.Context, exec boil.ContextExecutor, userID int64, slotsToRemove []int64) error
RemovePremiumSlots removes the specifues premium slots and attempts to migrate to other permanent available ones THIS SHOULD BE USED INSIDE A TRANSACTION ONLY, AS OTHERWISE RACE CONDITIONS BE UPON THEE
func SlotDurationLeft ¶
func SlotDurationLeft(slot *models.PremiumSlot) (duration time.Duration)
func SlotExpired ¶
func SlotExpired(ctx context.Context, slot *models.PremiumSlot) error
func TryRetryGenerateCode ¶
func TryRetryGenerateCode(ctx context.Context, message string, duration time.Duration) (*models.PremiumCode, error)
TryRetryGenerateCode attempts to generate codes, if it enocunters a key collision it retries, returns on all other cases
func UserPremiumSlots ¶
UserPremiumSlots returns all slots for a user
Types ¶
type CodePremiumSource ¶
type CodePremiumSource struct{}
func (*CodePremiumSource) Init ¶
func (ps *CodePremiumSource) Init()
func (*CodePremiumSource) Names ¶
func (ps *CodePremiumSource) Names() (human string, idname string)
type GuildPremiumSource ¶
type GuildPremiumSource interface { Name() string GuildPremiumDetails(guildID int64) (tier PremiumTier, humanDetails []string, err error) GuildPremiumTier(guildID int64) (PremiumTier, error) AllGuildsPremiumTiers() (map[int64]PremiumTier, error) }
type NewPremiumGuildListener ¶
type Plugin ¶
type Plugin struct { }
func (*Plugin) AddCommands ¶
func (p *Plugin) AddCommands()
func (*Plugin) AllFeatureFlags ¶
func (*Plugin) LoadServerHomeWidget ¶
func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func (*Plugin) PluginInfo ¶
func (p *Plugin) PluginInfo() *common.PluginInfo
func (*Plugin) RunBackgroundWorker ¶
func (p *Plugin) RunBackgroundWorker()
func (*Plugin) ServerHomeWidgetOrder ¶
func (*Plugin) StopBackgroundWorker ¶
func (*Plugin) UpdateFeatureFlags ¶
type PremiumSource ¶
func FindSource ¶
func FindSource(sourceID string) PremiumSource
type PremiumTier ¶
type PremiumTier int
const ( PremiumTierNone PremiumTier = 0 PremiumTierPremium PremiumTier = 1 PremiumTierPlus PremiumTier = 2 )
func ContextPremiumTier ¶
func ContextPremiumTier(ctx context.Context) PremiumTier
func GuildPremiumTier ¶
func GuildPremiumTier(guildID int64) (PremiumTier, error)
func (PremiumTier) String ¶
func (p PremiumTier) String() string
type SlotGuildPremiumSource ¶
type SlotGuildPremiumSource struct{}
func (*SlotGuildPremiumSource) AllGuildsPremiumTiers ¶
func (s *SlotGuildPremiumSource) AllGuildsPremiumTiers() (map[int64]PremiumTier, error)
func (*SlotGuildPremiumSource) GuildPremiumDetails ¶
func (s *SlotGuildPremiumSource) GuildPremiumDetails(guildID int64) (tier PremiumTier, humanDetails []string, err error)
func (*SlotGuildPremiumSource) GuildPremiumTier ¶
func (s *SlotGuildPremiumSource) GuildPremiumTier(guildID int64) (PremiumTier, error)
func (*SlotGuildPremiumSource) Name ¶
func (s *SlotGuildPremiumSource) Name() string
type UpdateData ¶
type UpdateData struct {
GuildID int64
}