match

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateKindWaiting uint8 = iota + 1
	StateKindPlaying
	StateKindProcessing
	StateKindFinished
)

Variables

View Source
var (
	ErrContextFatalClosed = fmt.Errorf("context closed")
	ErrValidation         = fmt.Errorf("validation errors")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	AuthorID   int64             `json:"authorId"`
	AuthorName string            `json:"authorName"`
	RoundsNum  int               `json:"roundsNum"`
	RoundTime  int               `json:"roundTime"`
	Categories []string          `json:"categories"`
	Letters    []string          `json:"letters"`
	Bloopses   []resource.Bloops `json:"bloopses"`
	Vote       bool              `json:"vote"`
	Code       int64             `json:"code"`

	State        uint8 `json:"state"`
	CurrRoundIdx int   `json:"currRoundIdx"`

	Tg      *tgbotapi.BotAPI             `json:"-"`
	DoneFn  func(session *Session) error `json:"-"`
	WarnFn  func(session *Session) error `json:"-"`
	Timeout time.Duration                `json:"-"`
}

func (Config) IsBloops

func (c Config) IsBloops() bool

type PlayerScore

type PlayerScore struct {
	Player        model.Player
	Points        int
	TotalDuration time.Duration
	MinDuration   time.Duration
	Completed     int
	Rounds        int
}

type QueryCallbackHandlerFn

type QueryCallbackHandlerFn func(query *tgbotapi.CallbackQuery) error

type Session

type Session struct {
	Config Config

	Code      int64
	CreatedAt time.Time

	Players      []*model.Player
	CurrRoundIdx int
	State        uint8
	// contains filtered or unexported fields
}

func NewSession

func NewSession(config Config) *Session

func (*Session) AddPlayer

func (r *Session) AddPlayer(player *model.Player) error

register new player and send asyncBroadcast message about it

func (*Session) AlivePlayersLen

func (r *Session) AlivePlayersLen() int

func (*Session) ChangeState

func (r *Session) ChangeState(kind uint8)

func (*Session) Execute

func (r *Session) Execute(userID int64, upd tgbotapi.Update) error

func (*Session) Favorites

func (r *Session) Favorites() []PlayerScore

func (*Session) MoveState

func (r *Session) MoveState(kind uint8)

func (*Session) RemovePlayer

func (r *Session) RemovePlayer(userID int64)

remove player from game and send asyncBroadcast message about it

func (*Session) Run

func (r *Session) Run(ctx context.Context)

func (*Session) Scores

func (r *Session) Scores() []PlayerScore

Calculating the player rating

func (*Session) Stop

func (r *Session) Stop()

Jump to

Keyboard shortcuts

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