dovewing

package
v0.0.0-...-4d5f9bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUser

func GetUser(ctx context.Context, id string, platform Platform) (*dovetypes.PlatformUser, error)

Fetches a user based on the platform

func InitPlatform

func InitPlatform(platform Platform) error

Common platform init code

func TableName

func TableName(platform Platform) string

Returns the table name of a platform

Types

type BaseState

type BaseState struct {
	Logger            *zap.Logger
	Context           context.Context
	Pool              *pgxpool.Pool
	PlatformUserCache hotcache.HotCache[dovetypes.PlatformUser]
	Middlewares       []func(p Platform, u *dovetypes.PlatformUser) (*dovetypes.PlatformUser, error)
	UserExpiryTime    time.Duration
}

type ClearFrom

type ClearFrom string
const (
	ClearFromInternalUserCache ClearFrom = "iuc"
	ClearFromRedis             ClearFrom = "redis"
)

type ClearUserInfo

type ClearUserInfo struct {
	// The user that was cleared
	ClearedFrom []ClearFrom
}

ClearUserInfo contains information on a clear operation

func ClearUser

func ClearUser(ctx context.Context, id string, platform Platform, req ClearUserReq) (*ClearUserInfo, error)

Clears a user of a platform

type ClearUserReq

type ClearUserReq struct {
	// Where to clear from
	//
	// iuc -> internal user cache (postgres)
	//
	// Redis -> redis cache
	//
	//
	// If not specified, will clear from all
	ClearFrom []ClearFrom
}

type DiscordState

type DiscordState struct {
	// contains filtered or unexported fields
}

func (*DiscordState) GetState

func (d *DiscordState) GetState() *BaseState

func (*DiscordState) GetUser

func (d *DiscordState) GetUser(ctx context.Context, id string) (*dovetypes.PlatformUser, error)

func (*DiscordState) Init

func (d *DiscordState) Init() error

func (*DiscordState) Initted

func (d *DiscordState) Initted() bool

func (*DiscordState) PlatformName

func (d *DiscordState) PlatformName() string

func (*DiscordState) PlatformSpecificCache

func (d *DiscordState) PlatformSpecificCache(ctx context.Context, id string) (*dovetypes.PlatformUser, error)

func (*DiscordState) ValidateId

func (d *DiscordState) ValidateId(id string) (string, error)

type DiscordStateConfig

type DiscordStateConfig struct {
	Session        *discordgo.Session // Discord session
	PreferredGuild string             // Which guilds should be checked first for users, good if theres one guild with the majority of users
	BaseState      *BaseState         // Base state
}

func (DiscordStateConfig) New

type Platform

type Platform interface {
	// initializes a platform, most of the time, needs no implementation
	Init() error
	// returns whether or not the platform is initialized, init() must set this to true if called
	Initted() bool
	// Returns the base state
	GetState() *BaseState
	// returns the name of the platform, used for cache table names
	PlatformName() string
	// validate the id, if feasible
	ValidateId(id string) (string, error)
	// try and find the user in the platform's cache, should only hit cache
	//
	// if user not found, return nil, nil (error should be nil and user obj should be nil)
	//
	// note that returning a error here will cause the user to not be fetched from the platform
	PlatformSpecificCache(ctx context.Context, id string) (*dovetypes.PlatformUser, error)
	// fetch a user from the platform, at this point, assume that cache has been checked
	GetUser(ctx context.Context, id string) (*dovetypes.PlatformUser, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL