activities

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActivityImmersionTypeReading   = "reading"
	ActivityImmersionTypeListening = "listening"
)
View Source
const (
	ActivityMediaTypeManga       = "manga"
	ActivityMediaTypeAnime       = "anime"
	ActivityMediaTypeVideo       = "video"
	ActivityMediaTypeBook        = "book"
	ActivityMediaTypeVisualNovel = "visual_novel"
)

Variables

View Source
var (
	ErrInvalidNameLength  = errors.New("name must be of length <100")
	ErrInvalidMediaType   = errors.New("invalid media type")
	ErrInvalidPrimaryType = errors.New("invalid primary type")
	ErrInvalidGuildID     = errors.New("guild id should be a valid discord snowflake")
	ErrInvalidUserID      = errors.New("user id should be a valid discord snowflake")
)

Functions

func ValidateExternalActivity added in v0.2.1

func ValidateExternalActivity(a *Activity) error

Types

type Activity

type Activity struct {
	ID          uint64        `json:"id"`
	UserID      string        `json:"user_id"`
	GuildID     *string       `json:"guild_id"`
	Name        string        `json:"name"`
	PrimaryType string        `json:"primary_type"`
	MediaType   *string       `json:"media_type"`
	Duration    time.Duration `json:"duration"`
	Date        time.Time     `json:"date"`
	Meta        interface{}   `json:"meta"`
	CreatedAt   time.Time     `json:"created_at"`
	DeletedAt   *time.Time    `json:"deleted_at"`
	ImportedAt  *time.Time    `json:"imported_at"`
}

func NewActivity

func NewActivity() *Activity

func (*Activity) SetMeta

func (a *Activity) SetMeta(key string, value any)

type ActivityRepository

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

func NewActivityRepository

func NewActivityRepository(pool *pgxpool.Pool) *ActivityRepository

func (*ActivityRepository) Create

func (r *ActivityRepository) Create(ctx context.Context, activity *Activity) error

func (*ActivityRepository) DeleteByID added in v0.2.1

func (r *ActivityRepository) DeleteByID(ctx context.Context, id uint64) error

func (*ActivityRepository) GetAllByUserID

func (r *ActivityRepository) GetAllByUserID(ctx context.Context, userID, guildID string) ([]*Activity, error)

func (*ActivityRepository) GetAvgSpeedByMediaTypeAndUserID

func (r *ActivityRepository) GetAvgSpeedByMediaTypeAndUserID(ctx context.Context, mediaType, userID string, start, end time.Time) (float32, error)

func (*ActivityRepository) GetByID

func (r *ActivityRepository) GetByID(ctx context.Context, id uint64, guildID string) (*Activity, error)

func (*ActivityRepository) GetLatestByUserID

func (r *ActivityRepository) GetLatestByUserID(ctx context.Context, userID, guildID string) (*Activity, error)

func (*ActivityRepository) GetRecentImportsByUserID added in v0.2.0

func (r *ActivityRepository) GetRecentImportsByUserID(
	ctx context.Context,
	userID string,
	limit int,
) ([]ImportInfo, error)

func (*ActivityRepository) GetTopMembers

func (r *ActivityRepository) GetTopMembers(ctx context.Context, guildID string, limit int, start, end time.Time) ([]*MemberStats, error)

func (*ActivityRepository) GetTotalByUserIDGroupByVideoChannel

func (r *ActivityRepository) GetTotalByUserIDGroupByVideoChannel(
	ctx context.Context,
	userID string,
	start, end time.Time,
) (orderedmap.Map[time.Duration], error)

func (*ActivityRepository) GetTotalByUserIDGroupedByDay

func (r *ActivityRepository) GetTotalByUserIDGroupedByDay(
	ctx context.Context,
	userID, guildID string,
	start, end time.Time,
) (orderedmap.Map[time.Duration], error)

Returns map of day (YYYY-MM-DD) to total duration filling in missing days with 0 (string formatted according to user's timezone)

func (*ActivityRepository) GetTotalByUserIDGroupedByMonth

func (r *ActivityRepository) GetTotalByUserIDGroupedByMonth(
	ctx context.Context,
	userID, guildID string,
	start, end time.Time,
) (orderedmap.Map[time.Duration], error)

func (*ActivityRepository) GetTotalWatchTimeOfVideoByUserID added in v0.2.4

func (r *ActivityRepository) GetTotalWatchTimeOfVideoByUserID(ctx context.Context, userID, videoPlatform, videoID string) (total time.Duration, err error)

func (*ActivityRepository) ImportMany added in v0.2.0

func (r *ActivityRepository) ImportMany(ctx context.Context, as []*Activity) error

func (*ActivityRepository) PageByUserID

func (r *ActivityRepository) PageByUserID(
	ctx context.Context,
	userID, guildID string,
	limit, offset int,
) (*UserActivityPage, error)

func (*ActivityRepository) UndoImportByUserIDAndTimestamp added in v0.2.0

func (r *ActivityRepository) UndoImportByUserIDAndTimestamp(
	ctx context.Context,
	userID string,
	timestamp time.Time,
) (int64, error)

type ImportInfo added in v0.2.0

type ImportInfo struct {
	Timestamp time.Time
	Count     int
}

type MemberStats

type MemberStats struct {
	UserID        string
	TotalDuration time.Duration
}

type UserActivityPage

type UserActivityPage struct {
	Activities []*Activity
	PageCount  int
	Page       int
}

type VideoInfo

type VideoInfo struct {
	URL            string        `json:"url"`
	Platform       string        `json:"platform"`
	ID             string        `json:"video_id"`
	Title          string        `json:"video_title"`
	Duration       time.Duration `json:"video_duration"`
	ChannelID      string        `json:"channel_id"`
	ChannelName    string        `json:"channel_name"`
	ChannelHandle  string        `json:"channel_handle"`
	Thumbnail      string        `json:"thumbnail"`
	LinkedChannels []string      `json:"linked_channels,omitempty"`
	LinkedVideos   []string      `json:"linked_videos,omitempty"`
	HashTags       []string      `json:"hashtags,omitempty"`
}

func GetVideoInfo

func GetVideoInfo(ctx context.Context, url *nurl.URL, forceYtdlp bool) (v *VideoInfo, err error)

Jump to

Keyboard shortcuts

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