store

package
v0.0.0-...-e4d4a11 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	PREDICTION_RESOLVED = "resolved"
	PREDICTION_CANCELED = "canceled"
)

Variables

This section is empty.

Functions

func StructToMap

func StructToMap(obj interface{}) (newMap map[string]interface{}, err error)

Types

type AppAccessToken

type AppAccessToken struct {
	AccessToken  string `gorm:"primaryKey"`
	RefreshToken string
	Scopes       string
	ExpiresIn    int
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

type Asset

type Asset struct {
	ID       string `gorm:"primarykey"`
	MimeType string
	Blob     []byte
}

type BotConfig

type BotConfig struct {
	OwnerTwitchID string `gorm:"primaryKey"`
	JoinBot       bool   `gorm:"index"`
	MediaCommands bool
}

type ChannelPointReward

type ChannelPointReward struct {
	OwnerTwitchID                     string         `gorm:"primaryKey"`
	Type                              dto.RewardType `gorm:"primaryKey"`
	RewardID                          string         `gorm:"index"`
	ApproveOnly                       bool           `gorm:"default:false"`
	CreatedAt                         time.Time
	UpdatedAt                         time.Time
	Title                             string
	Prompt                            string
	Cost                              int
	BackgroundColor                   string
	IsMaxPerStreamEnabled             bool
	MaxPerStream                      int
	IsUserInputRequired               bool
	IsMaxPerUserPerStreamEnabled      bool
	MaxPerUserPerStream               int
	IsGlobalCooldownEnabled           bool
	GlobalCooldownSeconds             int
	ShouldRedemptionsSkipRequestQueue bool
	Enabled                           bool
	AdditionalOptions                 string
}

type Database

type Database struct {
	Client     *gorm.DB
	PsqlClient *gorm.DB
}

func NewDatabase

func NewDatabase(cfg *config.Config) *Database

func (*Database) AddEventSubSubscription

func (db *Database) AddEventSubSubscription(targetTwitchID, subscriptionID, version, subType, foreignID string)

func (*Database) BlockEmoteAdd

func (db *Database) BlockEmoteAdd(channelTwitchID string, emoteID string)

func (*Database) BlockEmotes

func (db *Database) BlockEmotes(channelTwitchID string, emoteIds []string, emoteType string) error

func (*Database) ClearNominationEmote

func (s *Database) ClearNominationEmote(ctx context.Context, channelTwitchID string, emoteID string) error

func (*Database) ClearNominations

func (db *Database) ClearNominations(ctx context.Context, channelTwitchID string) error

func (*Database) CountNominationDownvotes

func (db *Database) CountNominationDownvotes(ctx context.Context, channelTwitchID string, votedBy string) (int, error)

func (*Database) CountNominationVotes

func (db *Database) CountNominationVotes(ctx context.Context, channelTwitchID string, voteBy string) (int, error)

func (*Database) CountNominations

func (s *Database) CountNominations(ctx context.Context, channelTwitchID string, userID string) (int, error)

func (*Database) CreateAsset

func (db *Database) CreateAsset(ID string, mimeType string, blob []byte)

func (*Database) CreateEmoteAdd

func (db *Database) CreateEmoteAdd(channelTwitchID string, addType dto.RewardType, emoteID string, emoteChangeType dto.EmoteChangeType)

func (*Database) CreateEventSubMessage

func (db *Database) CreateEventSubMessage(message EventSubMessage)

func (*Database) CreateNominationDownvote

func (db *Database) CreateNominationDownvote(ctx context.Context, downvote NominationDownvote) error

func (*Database) CreateNominationVote

func (db *Database) CreateNominationVote(ctx context.Context, vote NominationVote) error

func (*Database) CreateOrIncrementNomination

func (db *Database) CreateOrIncrementNomination(ctx context.Context, nomination Nomination) error

func (*Database) DeleteChannelPointReward

func (db *Database) DeleteChannelPointReward(userID string, rewardType dto.RewardType)

func (*Database) DeleteChannelPointRewardById

func (db *Database) DeleteChannelPointRewardById(userID string, rewardID string)

func (*Database) DeleteEmoteBlock

func (db *Database) DeleteEmoteBlock(channelTwitchID string, emoteId string, emoteType dto.RewardType) error

func (*Database) DeleteOverlay

func (db *Database) DeleteOverlay(ID string)

func (*Database) DeletePermission

func (db *Database) DeletePermission(channelID string, userID string)

func (*Database) GetActivePrediction

func (db *Database) GetActivePrediction(ownerTwitchID string) (PredictionLog, error)

func (*Database) GetAllJoinBotConfigs

func (db *Database) GetAllJoinBotConfigs() []BotConfig

func (*Database) GetAllMediaCommandsBotConfig

func (db *Database) GetAllMediaCommandsBotConfig() []BotConfig

func (*Database) GetAllPredictionSubscriptions

func (db *Database) GetAllPredictionSubscriptions(userID string) []EventSubSubscription

func (*Database) GetAllSubscriptions

func (db *Database) GetAllSubscriptions() []EventSubSubscription

func (*Database) GetAllUserAccessToken

func (db *Database) GetAllUserAccessToken() []UserAccessToken

func (*Database) GetAppAccessToken

func (db *Database) GetAppAccessToken() (AppAccessToken, error)

func (*Database) GetAsset

func (db *Database) GetAsset(ID string) *Asset

func (*Database) GetBotConfig

func (db *Database) GetBotConfig(userID string) (BotConfig, error)

func (*Database) GetBttvToken

func (db *Database) GetBttvToken(ctx context.Context) string

func (*Database) GetChannelPermissions

func (db *Database) GetChannelPermissions(channelID string) []Permission

func (*Database) GetChannelPointReward

func (db *Database) GetChannelPointReward(userID string, rewardType dto.RewardType) (ChannelPointReward, error)

func (*Database) GetChannelPointRewards

func (db *Database) GetChannelPointRewards(userID string) []ChannelPointReward

func (*Database) GetChannelUserPermissions

func (db *Database) GetChannelUserPermissions(userID string, channelID string) Permission

func (*Database) GetConfigValue

func (db *Database) GetConfigValue(ctx context.Context, configKey string) string

func (*Database) GetDistinctRewardsPerUser

func (db *Database) GetDistinctRewardsPerUser() []ChannelPointReward

func (*Database) GetEmoteAdd

func (db *Database) GetEmoteAdd(channelTwitchID string, emoteID string) *EmoteAdd

func (*Database) GetEmoteAdded

func (db *Database) GetEmoteAdded(channelTwitchID string, addType dto.RewardType, limit int) []EmoteAdd

func (*Database) GetEmoteBlocks

func (db *Database) GetEmoteBlocks(channelTwitchID string, page int, pageSize int) []EmoteBlock

func (*Database) GetEmoteHistory

func (db *Database) GetEmoteHistory(ctx context.Context, ownerTwitchID string, page int, pageSize int, added bool) []EmoteAdd

func (*Database) GetEnabledChannelPointRewardByID

func (db *Database) GetEnabledChannelPointRewardByID(rewardID string) (ChannelPointReward, error)

func (*Database) GetEventSubMessage

func (db *Database) GetEventSubMessage(id string) (EventSubMessage, error)

func (*Database) GetNomination

func (db *Database) GetNomination(ctx context.Context, channelTwitchID string, emoteID string) (Nomination, error)

func (*Database) GetNominations

func (db *Database) GetNominations(ctx context.Context, channelTwitchID string) ([]Nomination, error)

func (*Database) GetOutcomes

func (db *Database) GetOutcomes(predictionID string) []PredictionLogOutcome

func (*Database) GetOverlay

func (db *Database) GetOverlay(ID string, userID string) Overlay

func (*Database) GetOverlayByRoomId

func (db *Database) GetOverlayByRoomId(roomID string) Overlay

func (*Database) GetOverlays

func (db *Database) GetOverlays(userID string) []Overlay

func (*Database) GetPredictions

func (db *Database) GetPredictions(ctx context.Context, ownerTwitchID string, page int, pageSize int) []PredictionLog

func (*Database) GetSevenTvToken

func (db *Database) GetSevenTvToken(ctx context.Context) string

func (*Database) GetUserAccessToken

func (db *Database) GetUserAccessToken(userID string) (UserAccessToken, error)

func (*Database) GetUserPermissions

func (db *Database) GetUserPermissions(userID string) []Permission

func (*Database) HasEventSubSubscription

func (db *Database) HasEventSubSubscription(subscriptionID string) bool

func (*Database) IsAlreadyNominated

func (s *Database) IsAlreadyNominated(ctx context.Context, channelTwitchID string, emoteID string) (bool, error)

func (*Database) IsEmoteBlocked

func (db *Database) IsEmoteBlocked(channelTwitchID string, emoteID string, emoteType dto.RewardType) bool

func (*Database) Migrate

func (db *Database) Migrate()

func (*Database) RemoveEmoteAdd

func (db *Database) RemoveEmoteAdd(channelTwitchID string, emoteID string)

func (*Database) RemoveEventSubSubscription

func (db *Database) RemoveEventSubSubscription(subscriptionID string)

func (*Database) RemoveNomination

func (s *Database) RemoveNomination(ctx context.Context, channelTwitchID string, emoteID string) error

func (*Database) RemoveNominationDownvote

func (db *Database) RemoveNominationDownvote(ctx context.Context, downvote NominationDownvote) error

func (*Database) RemoveNominationVote

func (db *Database) RemoveNominationVote(ctx context.Context, vote NominationVote) error

func (*Database) Save

func (db *Database) Save(ctx context.Context, configKey string, configValue string) error

func (*Database) SaveAppAccessToken

func (db *Database) SaveAppAccessToken(ctx context.Context, accessToken string, refreshToken string, scopes string, expiresIn int) error

func (*Database) SaveBotConfig

func (db *Database) SaveBotConfig(ctx context.Context, botCfg BotConfig) error

func (*Database) SaveOutcome

func (db *Database) SaveOutcome(log PredictionLogOutcome) error

func (*Database) SaveOverlay

func (db *Database) SaveOverlay(overlay Overlay) error

func (*Database) SavePermission

func (db *Database) SavePermission(permission Permission) error

func (*Database) SavePrediction

func (db *Database) SavePrediction(log PredictionLog) error

func (*Database) SaveReward

func (db *Database) SaveReward(reward ChannelPointReward) error

func (*Database) SaveUserAccessToken

func (db *Database) SaveUserAccessToken(ctx context.Context, ownerId string, accessToken string, refreshToken string, scopes string) error

type EmoteAdd

type EmoteAdd struct {
	gorm.Model
	ID              uint                `gorm:"primarykey,autoIncrement"`
	ChannelTwitchID string              `gorm:"index"`
	Type            dto.RewardType      `gorm:"index"`
	ChangeType      dto.EmoteChangeType `gorm:"index"`
	Blocked         bool                `gorm:"index"`
	EmoteID         string
}

type EmoteBlock

type EmoteBlock struct {
	ChannelTwitchID string         `gorm:"primarykey"`
	Type            dto.RewardType `gorm:"primarykey"`
	EmoteID         string         `gorm:"primarykey"`
	CreatedAt       time.Time
}

type EventSubMessage

type EventSubMessage struct {
	ID        string    `gorm:"primaryKey"`
	CreatedAt time.Time `gorm:"index"`
}

type EventSubSubscription

type EventSubSubscription struct {
	TargetTwitchID string `gorm:"primary_key"`
	SubscriptionID string `gorm:"primary_key;index"`
	Type           string
	ForeignID      string `gorm:"index"`
	Version        string
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

type MockStore

type MockStore struct {
}

func NewMockStore

func NewMockStore() *MockStore

func (*MockStore) ClearNominationEmote

func (s *MockStore) ClearNominationEmote(ctx context.Context, channelTwitchID string, emoteID string) error

func (*MockStore) ClearNominations

func (s *MockStore) ClearNominations(ctx context.Context, channelTwitchID string) error

func (*MockStore) CountNominationDownvotes

func (s *MockStore) CountNominationDownvotes(ctx context.Context, channelTwitchID string, voteBy string) (int, error)

func (*MockStore) CountNominationVotes

func (s *MockStore) CountNominationVotes(ctx context.Context, channelTwitchID string, voteBy string) (int, error)

func (*MockStore) CountNominations

func (s *MockStore) CountNominations(ctx context.Context, channelTwitchID string, userID string) (int, error)

func (*MockStore) CreateEmoteAdd

func (s *MockStore) CreateEmoteAdd(channelUserId string, rewardType dto.RewardType, emoteID string, changeType dto.EmoteChangeType)

func (*MockStore) CreateNominationDownvote

func (s *MockStore) CreateNominationDownvote(ctx context.Context, downvote NominationDownvote) error

func (*MockStore) CreateNominationVote

func (s *MockStore) CreateNominationVote(ctx context.Context, vote NominationVote) error

func (*MockStore) CreateOrIncrementNomination

func (s *MockStore) CreateOrIncrementNomination(ctx context.Context, nomination Nomination) error

func (*MockStore) DeleteChannelPointRewardById

func (s *MockStore) DeleteChannelPointRewardById(userID string, rewardID string)

func (*MockStore) DeleteOverlay

func (s *MockStore) DeleteOverlay(ID string)

func (*MockStore) GetAllMediaCommandsBotConfig

func (s *MockStore) GetAllMediaCommandsBotConfig() []BotConfig

func (*MockStore) GetAllUserAccessToken

func (s *MockStore) GetAllUserAccessToken() []UserAccessToken

func (*MockStore) GetAppAccessToken

func (s *MockStore) GetAppAccessToken() (AppAccessToken, error)

func (*MockStore) GetBttvToken

func (s *MockStore) GetBttvToken(ctx context.Context) string

func (*MockStore) GetChannelPointReward

func (s *MockStore) GetChannelPointReward(userID string, rewardType dto.RewardType) (ChannelPointReward, error)

func (*MockStore) GetEmoteAdded

func (s *MockStore) GetEmoteAdded(channelUserID string, rewardType dto.RewardType, slots int) []EmoteAdd

func (*MockStore) GetNomination

func (s *MockStore) GetNomination(ctx context.Context, channelTwitchID string, emoteID string) (Nomination, error)

func (*MockStore) GetNominations

func (s *MockStore) GetNominations(ctx context.Context, channelTwitchID string) ([]Nomination, error)

func (*MockStore) GetOverlay

func (s *MockStore) GetOverlay(ID string, userID string) Overlay

func (*MockStore) GetOverlayByRoomId

func (s *MockStore) GetOverlayByRoomId(roomID string) Overlay

func (*MockStore) GetOverlays

func (s *MockStore) GetOverlays(userID string) []Overlay

func (*MockStore) GetSevenTvToken

func (s *MockStore) GetSevenTvToken(ctx context.Context) string

func (*MockStore) GetUserAccessToken

func (s *MockStore) GetUserAccessToken(userID string) (UserAccessToken, error)

func (*MockStore) IsAlreadyNominated

func (s *MockStore) IsAlreadyNominated(ctx context.Context, channelTwitchID string, emoteID string) (bool, error)

func (*MockStore) IsEmoteBlocked

func (s *MockStore) IsEmoteBlocked(channelUserID string, emoteID string, rewardType dto.RewardType) bool

func (*MockStore) RemoveNomination

func (s *MockStore) RemoveNomination(ctx context.Context, channelTwitchID string, emoteID string) error

func (*MockStore) RemoveNominationDownvote

func (s *MockStore) RemoveNominationDownvote(ctx context.Context, downvote NominationDownvote) error

func (*MockStore) RemoveNominationVote

func (s *MockStore) RemoveNominationVote(ctx context.Context, vote NominationVote) error

func (*MockStore) SaveAppAccessToken

func (s *MockStore) SaveAppAccessToken(ctx context.Context, accessToken string, refreshToken string, scopes string, expiresIn int) error

func (*MockStore) SaveOverlay

func (s *MockStore) SaveOverlay(overlay Overlay) error

func (*MockStore) SaveReward

func (s *MockStore) SaveReward(reward ChannelPointReward) error

func (*MockStore) SaveUserAccessToken

func (s *MockStore) SaveUserAccessToken(ctx context.Context, ownerId string, accessToken string, refreshToken string, scopes string) error

type Nomination

type Nomination struct {
	EmoteID         string `gorm:"primarykey"`
	ChannelTwitchID string `gorm:"primarykey"`
	EmoteCode       string
	NominatedBy     string
	CreatedAt       time.Time
	UpdatedAt       time.Time
	Votes           []NominationVote     `gorm:"foreignKey:EmoteID,ChannelTwitchID;references:EmoteID,ChannelTwitchID"`
	Downvotes       []NominationDownvote `gorm:"foreignKey:EmoteID,ChannelTwitchID;references:EmoteID,ChannelTwitchID"`
}

type NominationDownvote

type NominationDownvote struct {
	EmoteID         string `gorm:"primarykey"`
	ChannelTwitchID string `gorm:"primarykey"`
	VoteBy          string `gorm:"primarykey"`
}

type NominationVote

type NominationVote struct {
	EmoteID         string `gorm:"primarykey"`
	ChannelTwitchID string `gorm:"primarykey"`
	VoteBy          string `gorm:"primarykey"`
}

type Overlay

type Overlay struct {
	ID            string `gorm:"primaryKey"`
	OwnerTwitchID string `gorm:"index"`
	RoomID        string `gorm:"index"`
}

type Permission

type Permission struct {
	ChannelTwitchId string `gorm:"primaryKey"`
	TwitchID        string `gorm:"primaryKey"`
	Editor          bool   `gorm:"default:false"`
	Prediction      bool   `gorm:"default:false"`
}

type PredictionLog

type PredictionLog struct {
	ID               string `gorm:"primaryKey"`
	OwnerTwitchID    string `gorm:"index"`
	Title            string
	WinningOutcomeID string
	Status           string
	StartedAt        time.Time
	LockedAt         *time.Time
	EndedAt          *time.Time
	Outcomes         []PredictionLogOutcome `gorm:"foreignKey:PredictionID;references:ID"`
}

type PredictionLogOutcome

type PredictionLogOutcome struct {
	ID            string `gorm:"primaryKey"`
	PredictionID  string `gorm:"index"`
	Title         string
	Color         string
	Users         int
	ChannelPoints int
}

func (*PredictionLogOutcome) GetColorEmoji

func (o *PredictionLogOutcome) GetColorEmoji() string

type Store

type Store interface {
	IsEmoteBlocked(channelUserID string, emoteID string, rewardType dto.RewardType) bool
	GetEmoteAdded(channelUserID string, rewardType dto.RewardType, slots int) []EmoteAdd
	CreateEmoteAdd(channelUserId string, rewardType dto.RewardType, emoteID string, changeType dto.EmoteChangeType)
	GetUserAccessToken(userID string) (UserAccessToken, error)
	GetAppAccessToken() (AppAccessToken, error)
	SaveAppAccessToken(ctx context.Context, accessToken string, refreshToken string, scopes string, expiresIn int) error
	SaveUserAccessToken(ctx context.Context, ownerId string, accessToken string, refreshToken string, scopes string) error
	GetAllUserAccessToken() []UserAccessToken
	GetSevenTvToken(ctx context.Context) string
	GetBttvToken(ctx context.Context) string
	SaveReward(reward ChannelPointReward) error
	CreateOrIncrementNomination(ctx context.Context, nomination Nomination) error
	GetNominations(ctx context.Context, channelTwitchID string) ([]Nomination, error)
	ClearNominations(ctx context.Context, channelTwitchID string) error
	ClearNominationEmote(ctx context.Context, channelTwitchID string, emoteID string) error
	DeleteChannelPointRewardById(userID string, rewardID string)
	GetChannelPointReward(userID string, rewardType dto.RewardType) (ChannelPointReward, error)
	CreateNominationVote(ctx context.Context, vote NominationVote) error
	RemoveNominationVote(ctx context.Context, vote NominationVote) error
	GetNomination(ctx context.Context, channelTwitchID string, emoteID string) (Nomination, error)
	RemoveNomination(ctx context.Context, channelTwitchID string, emoteID string) error
	CountNominations(ctx context.Context, channelTwitchID string, userID string) (int, error)
	CreateNominationDownvote(ctx context.Context, downvote NominationDownvote) error
	RemoveNominationDownvote(ctx context.Context, downvote NominationDownvote) error
	CountNominationDownvotes(ctx context.Context, channelTwitchID string, voteBy string) (int, error)
	CountNominationVotes(ctx context.Context, channelTwitchID string, voteBy string) (int, error)
	IsAlreadyNominated(ctx context.Context, channelTwitchID string, emoteID string) (bool, error)
	GetOverlays(userID string) []Overlay
	GetOverlay(ID string, userID string) Overlay
	GetOverlayByRoomId(roomID string) Overlay
	DeleteOverlay(ID string)
	SaveOverlay(overlay Overlay) error
}

type SystemConfig

type SystemConfig struct {
	ConfigKey   string `gorm:"primaryKey"`
	ConfigValue string
}

type UserAccessToken

type UserAccessToken struct {
	OwnerTwitchID string `gorm:"primaryKey"`
	AccessToken   string
	RefreshToken  string
	Scopes        string
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

Jump to

Keyboard shortcuts

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