Documentation
¶
Index ¶
- Constants
- type Logger
- type Machine
- func (m *Machine) CheckWord(word string) bool
- func (m *Machine) CheckWordAndSetWinner(word string, potentialWinner int, winnerName string) (string, bool)
- func (m *Machine) GetGuessedTime() time.Time
- func (m *Machine) GetHost() int
- func (m *Machine) GetStartedTime() time.Time
- func (m *Machine) GetWinner() int
- func (m *Machine) GetWord() string
- func (m *Machine) SetNewRandomWord() (string, error)
- func (m *Machine) StartNewGameAndReturnWord(host int, hostName string, chatTitle string) (string, error)
- func (m *Machine) StopGame() error
- type MachineFabric
- type Storage
- type WordsProvider
- type WordsProviderReader
Constants ¶
const ( // ErrGameAlreadyStarted is error when user tries to start a game in chat, but there is the one already ErrGameAlreadyStarted = "Game already started" // ErrWaitingForWinnerRespond is error when the game have been played, but winner did't start a new one ErrWaitingForWinnerRespond = "Waiting for winner respond" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger interface {
Tracef(format string, args ...interface{})
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Printf(format string, args ...interface{})
Warnf(format string, args ...interface{})
Warningf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
Panicf(format string, args ...interface{})
Trace(args ...interface{})
Debug(args ...interface{})
Info(args ...interface{})
Print(args ...interface{})
Warn(args ...interface{})
Warning(args ...interface{})
Error(args ...interface{})
Fatal(args ...interface{})
Panic(args ...interface{})
Traceln(args ...interface{})
Debugln(args ...interface{})
Infoln(args ...interface{})
Println(args ...interface{})
Warnln(args ...interface{})
Warningln(args ...interface{})
Errorln(args ...interface{})
Fatalln(args ...interface{})
Panicln(args ...interface{})
}
type Machine ¶
type Machine struct {
MesID int
// ChatID where the game is started
ChatID int64
// ChatTitle where the game is started
ChatTitle string
// Word which users should guess
Word string
// UserID of the user that should explain the word
Host int
HostName string
// UserID of user who guessed the word
Winner int
StartedTime time.Time
GuessedTime time.Time
// Technical data
Storage Storage `json:"-"`
WordsProvider WordsProvider `json:"-"`
FSM *fsm.FSM `json:"-"`
Log Logger `json:"-"`
// We have to set this explicitly for saving state in external storage
State string
}
Machine stores state of game in one chat
func NewMachine ¶
NewMachine returns new Machine instance
func (*Machine) CheckWordAndSetWinner ¶
func (m *Machine) CheckWordAndSetWinner(word string, potentialWinner int, winnerName string) (string, bool)
CheckWordAndSetWinner sets m.Winner and returns true if m.CheckWord() returns true, otherwise ret. false
func (*Machine) GetGuessedTime ¶
GetGuessedTime is getter for m.GuessedTime
func (*Machine) GetStartedTime ¶
GetStartedTime is getter for m.StartedTime
func (*Machine) SetNewRandomWord ¶
SetNewRandomWord generates new word
type MachineFabric ¶
type MachineFabric struct {
Storage Storage
WordsProvider WordsProvider
Log Logger
}
MachineFabric aims to produce new machines with freezed Storage and WordsProvider
func NewMachineFabric ¶
func NewMachineFabric(storage Storage, wp WordsProvider, log Logger) *MachineFabric
NewMachineFabric returns MachineFabric
func (*MachineFabric) NewMachine ¶
func (m *MachineFabric) NewMachine(chatID int64, mesID int) *Machine
NewMachine returns Machine with freezed Storage and WordsProvider
type Storage ¶
type Storage interface {
IncrementUserStats(model.Chat, ...model.UserInChat) error
SaveMachineState(Machine) error
LookupForMachine(*Machine) error
}
Storage aims to save FSM state somewhere (e.g. in Redis)
type WordsProvider ¶
WordsProvider should return random word
type WordsProviderReader ¶
type WordsProviderReader struct {
// contains filtered or unexported fields
}
WordsProviderReader takes content from reader, converts to string, splits by "\n" and returns random word
func NewWordsProviderReader ¶
func NewWordsProviderReader(r io.Reader) (*WordsProviderReader, error)
NewWordsProviderReader returns new instance of WordsProviderReader
func (*WordsProviderReader) GetWord ¶
func (w *WordsProviderReader) GetWord() (string, error)
GetWord returns random word