storage

package
v0.0.0-...-381577c Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GroupStateNone    = "none"
	GroupStateRolling = "rolling"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bet

type Bet struct {
	ID     int    `db:"id" sq:"id,omitempty"`
	UserID int    `sq:"user_id,omitempty"`
	ChatID int    `sq:"chat_id,omitempty"`
	Amount int64  `sq:"amount,omitempty"`
	Sign   string `sq:"sign,omitempty"`
	Won    bool   `sq:"won,omitempty"`
	Done   bool   `sq:"done,omitempty"`
}

type Bets

type Bets struct {
	*sqlx.DB
}

func (*Bets) ByID

func (db *Bets) ByID(id int) (bet Bet, _ error)

func (*Bets) ByUserID

func (db *Bets) ByUserID(chat Chat) (bets []Bet, _ error)

func (*Bets) Count

func (db *Bets) Count(chat Chat) (i int, _ error)

func (*Bets) Create

func (db *Bets) Create(bet *azartio.Bet, chat Chat) error

func (*Bets) MakeDoneByChat

func (db *Bets) MakeDoneByChat(result *azartio.RollResult, user Chat, chat Chat) error

func (*Bets) NotDoneByChat

func (db *Bets) NotDoneByChat(chat Chat) (bets []Bet, _ error)

func (*Bets) NotDoneByUserID

func (db *Bets) NotDoneByUserID(user Chat, chat Chat) (bets []Bet, _ error)

type BetsStorage

type BetsStorage interface {
	ByID(id int) (bet Bet, _ error)
	Create(bet *azartio.Bet, chatID Chat) error
	ByUserID(chat Chat) (bets []Bet, _ error)
	Count(chat Chat) (int, error)
	NotDoneByUserID(user Chat, chat Chat) (bets []Bet, _ error)
	MakeDoneByChat(result *azartio.RollResult, user Chat, chat Chat) error
	NotDoneByChat(chat Chat) (bets []Bet, _ error)
}

type Chat

type Chat interface {
	Recipient() string
}

type DB

type DB struct {
	*sqlx.DB
	Users    UsersStorage
	Groups   GroupsStorage
	Bets     BetsStorage
	Payments PaymentsStorage
}

func Open

func Open(url string) (*DB, error)

type Group

type Group struct {
	ID        int64  `db:"id" sq:"id,omitempty"`
	State     string `sq:"state,omitempty"`
	MessageID int64  `db:"message_id" sq:"message_id,omitempty"`
}

type Groups

type Groups struct {
	*sqlx.DB
}

func (*Groups) ByID

func (db *Groups) ByID(chat Chat) (group Group, _ error)

func (*Groups) Create

func (db *Groups) Create(chat Chat) error

func (*Groups) Exists

func (db *Groups) Exists(chat Chat) (has bool, _ error)

func (*Groups) UpdateMessage

func (db *Groups) UpdateMessage(chat Chat, MessageID int) error

func (*Groups) UpdateState

func (db *Groups) UpdateState(chat Chat, state string) error

type GroupsStorage

type GroupsStorage interface {
	Create(chat Chat) error
	UpdateMessage(chat Chat, MessageID int) error
	UpdateState(chat Chat, state string) error
	ByID(chat Chat) (group Group, _ error)
	Exists(chat Chat) (exists bool, _ error)
}

type Payment

type Payment struct {
	CreatedAt time.Time  `sq:"created_at,omitempty"`
	ID        int        `sq:"id,omitempty"`
	UserID    int        `sq:"user_id,omitempty"`
	Target    string     `sq:"target,omitempty"`
	Amount    string     `sq:"amount,omitempty"`
	Profit    string     `sq:"profit,omitempty"`
	PayAt     *time.Time `sq:"pay_at,omitempty"`
}

func (Payment) Payed

func (p Payment) Payed() bool

func (Payment) Payment

func (p Payment) Payment() store.Payment

type Payments

type Payments struct {
	*sqlx.DB
}

func (*Payments) ByID

func (db *Payments) ByID(id int) (p Payment, _ error)

func (*Payments) Create

func (db *Payments) Create(p Payment) (id int, _ error)

func (*Payments) Pending

func (db *Payments) Pending(userID int, target, amount string) (p Payment, _ error)

func (*Payments) Update

func (db *Payments) Update(id int, profit string, payAt time.Time) error

type PaymentsStorage

type PaymentsStorage interface {
	Create(payment Payment) (int, error)
	ByID(id int) (Payment, error)
	Pending(userID int, target, amount string) (Payment, error)
	Update(id int, profit string, payAt time.Time) error
}

type User

type User struct {
	CreatedAt  time.Time           `sq:"created_at,omitempty"`
	UpdatedAt  time.Time           `sq:"updated_at,omitempty"`
	ID         int                 `sq:"id,omitempty"`
	Ref        string              `sq:"ref,omitempty"`
	Balance    int64               `sq:"balance,omitempty"`
	LastBonus  time.Time           `sq:"last_bonus,omitempty"`
	Subscribed bool                `sq:"subscribed,omitempty"`
	PerksArray pgtype.VarcharArray `db:"perks" sq:"perks,omitempty"`
}

func (User) HasPerk

func (u User) HasPerk(perk string) bool

func (User) Perks

func (u User) Perks() (ps []string)

type Users

type Users struct {
	*sqlx.DB
}

func (*Users) AddPerk

func (db *Users) AddPerk(chat Chat, perk string) error

func (*Users) Balance

func (db *Users) Balance(chat Chat) (a int64, _ error)

func (*Users) ByID

func (db *Users) ByID(chat Chat) (usr User, _ error)

func (*Users) Charge

func (db *Users) Charge(amount int64, chat Chat) error

func (*Users) Create

func (db *Users) Create(chat Chat, ref string) error

func (*Users) Exists

func (db *Users) Exists(chat Chat) (has bool, _ error)

func (*Users) Friends

func (db *Users) Friends(chat Chat) (i int, _ error)

func (*Users) IsLastBonusUsed

func (db *Users) IsLastBonusUsed(chat Chat) (bool, error)

func (*Users) Lang

func (db *Users) Lang(chat Chat) (lang string, _ error)

func (*Users) Leaderboard

func (db *Users) Leaderboard() (users []User, _ error)

func (*Users) SetLang

func (db *Users) SetLang(chat Chat, lang string) error

func (*Users) SetSubscribed

func (db *Users) SetSubscribed(chat Chat, sub bool) error

func (*Users) Subscribed

func (db *Users) Subscribed(chat Chat) (sub bool)

func (*Users) UseBonus

func (db *Users) UseBonus(chat Chat) error

type UsersStorage

type UsersStorage interface {
	Create(chat Chat, ref string) error
	Exists(chat Chat) (bool, error)
	Charge(amount int64, chat Chat) error
	ByID(chat Chat) (usr User, _ error)
	Balance(chat Chat) (a int64, _ error)
	Friends(chat Chat) (int, error)
	IsLastBonusUsed(chat Chat) (bool, error)
	UseBonus(chat Chat) error
	Subscribed(chat Chat) bool
	SetSubscribed(chat Chat, s bool) error
	Leaderboard() (users []User, _ error)
	AddPerk(chat Chat, perk string) error
}

Jump to

Keyboard shortcuts

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