Documentation ¶
Index ¶
- Constants
- Variables
- 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 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) MessageLimits(cs *dstate.ChannelState) (maxMessages int, maxMessageAge time.Duration)
- func (p *Plugin) Name() string
- func (p *Plugin) RunBackgroundWorker()
- func (p *Plugin) StopBackgroundWorker(wg *sync.WaitGroup)
- type PremiumSource
- type UpdateData
Constants ¶
View Source
const ( NormalStateMaxMessages = 1000 NormalStateMaxMessageAge = time.Hour PremiumStateMaxMessags = 10000 PremiumStateMaxMessageAge = time.Hour * 12 )
View Source
const ( // Hash // Key: guild id's // Value: the user id's providing the premium status RedisKeyPremiumGuilds = "premium_activated_guilds" RedisKeyPremiumGuildsTmp = "premium_activated_guilds_tmp" )
View Source
const DBSchema = `` /* 825-byte string literal not displayed */
Variables ¶
View Source
var ( ErrCodeExpired = errors.New("Code expired") ErrCodeNotFound = errors.New("Code not found") )
View Source
var ( PremiumSources []PremiumSource ErrSlotNotFound = errors.New("premium slot not found") ErrGuildAlreadyPremium = errors.New("guild already assigned premium from another slot") )
View Source
var (
ErrCodeCollision = errors.New("Code collision")
)
Functions ¶
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 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) MessageLimits ¶
func (*Plugin) RunBackgroundWorker ¶ added in v1.15.3
func (p *Plugin) RunBackgroundWorker()
func (*Plugin) StopBackgroundWorker ¶ added in v1.15.3
type PremiumSource ¶
func FindSource ¶
func FindSource(sourceID string) PremiumSource
type UpdateData ¶
type UpdateData struct {
GuildID int64
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.