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 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 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 Plugin
- func (p *Plugin) AddCommands()
- func (p *Plugin) BotInit()
- func (p *Plugin) InitWeb()
- func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
- func (p *Plugin) MessageLimits(cs *dstate.ChannelState) (maxMessages int, maxMessageAge time.Duration)
- func (p *Plugin) PluginInfo() *common.PluginInfo
- func (p *Plugin) RunBackgroundWorker()
- func (p *Plugin) ServerHomeWidgetOrder() int
- func (p *Plugin) StopBackgroundWorker(wg *sync.WaitGroup)
- type PremiumSource
- type UpdateData
Constants ¶
const ( NormalStateMaxMessages = 1000 NormalStateMaxMessageAge = time.Hour 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 DBSchema = `` /* 825-byte string literal not displayed */
Variables ¶
var ( ErrCodeExpired = errors.New("Code expired") ErrCodeNotFound = errors.New("Code not found") )
var ( PremiumSources []PremiumSource ErrSlotNotFound = errors.New("premium slot not found") ErrGuildAlreadyPremium = errors.New("guild already assigned premium from another slot") )
var (
ErrCodeCollision = errors.New("Code collision")
)
Functions ¶
func AllGuildsOncePremium ¶ added in v1.16.0
AllGuildsOncePremium returns all the guilds that have has premium once, and the last time that was active
func AttachSlotToGuild ¶
func ContextPremium ¶
func CreatePremiumSlot ¶
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 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 provided to it by a user
func LookupCode ¶
func PremiumGuildMW ¶
Add in a template var wether the guild is premium or not
func PremiumProvidedBy ¶ added in v1.17.0
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 Plugin ¶
type Plugin struct { }
func (*Plugin) AddCommands ¶
func (p *Plugin) AddCommands()
func (*Plugin) LoadServerHomeWidget ¶ added in v1.17.0
func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)
func (*Plugin) MessageLimits ¶
func (*Plugin) PluginInfo ¶ added in v1.17.0
func (p *Plugin) PluginInfo() *common.PluginInfo
func (*Plugin) RunBackgroundWorker ¶ added in v1.15.3
func (p *Plugin) RunBackgroundWorker()
func (*Plugin) ServerHomeWidgetOrder ¶ added in v1.17.0
func (*Plugin) StopBackgroundWorker ¶ added in v1.15.3
type PremiumSource ¶
func FindSource ¶
func FindSource(sourceID string) PremiumSource
type UpdateData ¶
type UpdateData struct {
GuildID int64
}