rps

package
v0.0.0-...-6853e80 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2018 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Verbose *log.Logger
	Info    *log.Logger
	Warning *log.Logger
	Error   *log.Logger
)

Functions

func ClearRequests

func ClearRequests(walletPath string, testnet bool) error

ClearRequests removes all active requests

func ContainsChar

func ContainsChar(e rune, s string) int

ContainsChar checks if string contains a character.

func ContainsInt64

func ContainsInt64(e int64, s []int64) int

ContainsInt64 checks if slice contains an element.

func CountChar

func CountChar(e rune, s string) uint

CountChar counts number of entries of character in the string.

func CreateRequest

func CreateRequest(amount float64, walletPath string, testnet bool) (string, string, error)

CreateRequest creates payment request

func ExecCMD

func ExecCMD(cmd string) ([]byte, error)

ExecCMD executes commands in shell.

func GetBalance

func GetBalance(walletPath string, testnet bool) (float64, error)

GetBalance returns current balance of specified wallet

func GetCurrentlySoldTickets

func GetCurrentlySoldTickets(stats *LDBMap) (uint64, error)

GetCurrentlySoldTickets shows current game amount of sold tickets.

func GetRequest

func GetRequest(requestID string, walletPath string, testnet bool) (map[string]json.RawMessage, error)

GetRequest returns request's metadata

func GetTotalSoldTickets

func GetTotalSoldTickets(stats *LDBMap) (uint64, error)

GetTotalSoldTickets shows total amount of sold tickets.

func LogsInit

func LogsInit(
	verboseHandle io.Writer,
	infoHandle io.Writer,
	warningHandle io.Writer,
	errorHandle io.Writer,
)

func Max

func Max(a, b int) int

Max determines maximum of two values.

func MaxFloat64

func MaxFloat64(a, b float64) float64

MaxFloat64 determines maximum of two values.

func Min

func Min(a, b int) int

Min determines minumum of two values.

func MinFloat64

func MinFloat64(a, b float64) float64

MinFloat64 determines minumum of two values.

func NameValidate

func NameValidate(name string) bool

NameValidate validates username.

func PayTo

func PayTo(dstAddress string, amount float64, walletPath string, testnet bool) error

PayTo performs pay to specified address

func PayToUser

func PayToUser(user *User, amount float64, walletPath string, testnet bool) error

PayToUser performs pay to the specified user

func RemoveRequest

func RemoveRequest(requestID string, walletPath string, testnet bool) error

RemoveRequest removes payment request

func Reverse

func Reverse(a *[]*User)

Reverse reverses a slice of *Users.

func SetCurrentlySoldTickets

func SetCurrentlySoldTickets(sold uint64, stats *LDBMap) error

SetCurrentlySoldTickets sets current game amount of sold tickets.

func SetTotalSoldTickets

func SetTotalSoldTickets(sold uint64, stats *LDBMap) error

SetTotalSoldTickets sets total amount of sold tickets.

func WalletValidate

func WalletValidate(wallet string) bool

WalletValidate validates wallet address.

Types

type Bot

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

Bot strcture.

func New

func New(
	token string,
	opts *Options,
	crn *cron.Cron,
	users *Users,
	requests *LDBMap,
	stats *LDBMap,
	names *LDBMap,
	players []int64,
	leaderboard *[]*User,
) Bot

New creates an object of Bot structure.

func (*Bot) BuyTicket

func (b *Bot) BuyTicket(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

BuyTicket handles ticket purchase.

func (*Bot) ChangeName

func (b *Bot) ChangeName(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

ChangeName updates username of user.

func (*Bot) ChangeWalletAddress

func (b *Bot) ChangeWalletAddress(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

ChangeWalletAddress updates wallet address of user.

func (*Bot) GamePrepare

func (b *Bot) GamePrepare(botAPI *tgbotapi.BotAPI)

GamePrepare takes all necessary actions to prepare the game. Sort users by last ticket purchase date and align to ^2 number.

func (*Bot) GameReset

func (b *Bot) GameReset(botAPI *tgbotapi.BotAPI)

GameReset resets all users to pregame state and cleans players list.

func (*Bot) GameRestore

func (b *Bot) GameRestore(botAPI *tgbotapi.BotAPI)

GameRestore resurects game if bot crashed.

func (*Bot) Leaderboard

func (b *Bot) Leaderboard(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

Leaderboard shows leaderboard message.

func (*Bot) MakeAMove

func (b *Bot) MakeAMove(move byte, update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

MakeAMove implements user's move.

func (*Bot) NoUnsubscribe

func (b *Bot) NoUnsubscribe(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

NoUnsubscribe dismiss unsubscribe action.

func (*Bot) Play

func (b *Bot) Play(botAPI *tgbotapi.BotAPI)

Play starts the game.

func (*Bot) Reset

func (b *Bot) Reset(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

Reset resets ticket purchase and any active modifying actions.

func (*Bot) ShowStats

func (b *Bot) ShowStats(password string, update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

ShowStats shows metrics

func (*Bot) Start

func (b *Bot) Start()

Start starts the bot.

func (*Bot) StartSale

func (b *Bot) StartSale(
	price float64,
	password string,
	update tgbotapi.Update,
	botAPI *tgbotapi.BotAPI,
)

StartSale starts sale of tickets with specified price.

func (*Bot) Status

func (b *Bot) Status(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

Status shows status message filled up with user's stats.

func (*Bot) StopSale

func (b *Bot) StopSale(
	number uint64,
	password string,
	update tgbotapi.Update,
	botAPI *tgbotapi.BotAPI,
)

StopSale stops sale of tickets after certain threshold.

func (*Bot) Subscribe

func (b *Bot) Subscribe(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

Subscribe enables notifications for user. Without subscription almost any action isn't available

func (*Bot) Unsubscribe

func (b *Bot) Unsubscribe(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

Unsubscribe disables notifications for user.

func (*Bot) Welcome

func (b *Bot) Welcome(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

Welcome to everyone.

func (*Bot) YesUnsubscribe

func (b *Bot) YesUnsubscribe(update tgbotapi.Update, botAPI *tgbotapi.BotAPI)

YesUnsubscribe confirms unsubscribe action. Appear only when user has ticket.

type LDBMap

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

LDBMap structure.

func NewLDBMap

func NewLDBMap(name string, dbPath string) LDBMap

NewLDBMap creates an object of NewLDBMap structure.

func (LDBMap) BatchDelete

func (m LDBMap) BatchDelete(key string)

BatchDelete deletes an object from the vault by batching (leveldb).

func (LDBMap) BatchPut

func (m LDBMap) BatchPut(key string, value string)

BatchPut puts an object into the vault by batching (leveldb).

func (LDBMap) BatchWrite

func (m LDBMap) BatchWrite() error

BatchWrite performs write of the batch to the database.

func (LDBMap) Close

func (m LDBMap) Close()

Close closes the database.

func (LDBMap) Delete

func (m LDBMap) Delete(key string) error

Delete performs non-blocking delete of an object from the vault.

func (LDBMap) Exist

func (m LDBMap) Exist(key string) bool

Exist performs non-blocking check of an object for existence in the vault.

func (LDBMap) Get

func (m LDBMap) Get(key string) string

Get performs non-blocking get of an object from the vault.

func (LDBMap) Iterate

func (m LDBMap) Iterate() map[string]string

Iterate brings possibility to iterate over the vault.

func (LDBMap) Len

func (m LDBMap) Len() int

Len returns length of the vault

func (LDBMap) Put

func (m LDBMap) Put(key string, value string) error

Put performs non-blocking put of an object into the vault.

type Options

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

Options structure.

func NewOptions

func NewOptions(
	capacity uint,
	timeout uint,
	opTimeout uint,
	modifyTime uint,
	roundTime uint,
	payTime uint,
	schedule string,
	ticketPrice float64,
	testnet bool,
	donationAddress string,
	dbPath string,
	cashboxWalletPath string,
	bankWalletPath string,
	password string,
) Options

NewOptions creates an object of NewOptions structure.

type SynMap

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

SynMap structure. Implements map of interfaces with adaptation to multithreading.

func NewSynMap

func NewSynMap() SynMap

NewSynMap creates an object of SynMap structure.

func (SynMap) Delete

func (m SynMap) Delete(key interface{})

Delete an object from the vault.

func (SynMap) Exist

func (m SynMap) Exist(key interface{}) bool

Exist checks if an object in the vault.

func (SynMap) Get

func (m SynMap) Get(key interface{}) interface{}

Get an object from the vault.

func (SynMap) Iterate

func (m SynMap) Iterate() map[interface{}]interface{}

Iterate brings possibility to iterate over the vault by returning map of interfaces.

func (SynMap) Len

func (m SynMap) Len() int

Len returns length of the vault.

func (SynMap) Put

func (m SynMap) Put(key interface{}, value interface{})

Put an object into the vault.

type UMap

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

UMap structure.

func NewUMap

func NewUMap(name string, dbPath string) UMap

NewUMap creates an object of UMap structure.

func (UMap) BatchDelete

func (m UMap) BatchDelete(uid int64)

BatchDelete deletes an object from the vault by batching (leveldb).

func (UMap) BatchPut

func (m UMap) BatchPut(uid int64, user *User)

BatchPut puts an object into the vault by batching (leveldb).

func (UMap) BatchWrite

func (m UMap) BatchWrite() error

BatchWrite performs write of the batch to the database.

func (UMap) Close

func (m UMap) Close()

Close closes the database.

func (UMap) Delete

func (m UMap) Delete(uid int64) error

Delete performs non-blocking delete of an object from the vault.

func (UMap) Exist

func (m UMap) Exist(uid int64) bool

Exist performs non-blocking check of an object for existence in the vault.

func (UMap) Get

func (m UMap) Get(uid int64) *User

Get performs non-blocking get of an object from the vault.

func (UMap) Iterate

func (m UMap) Iterate() map[int64]*User

Iterate brings possibility to iterate over the vault.

func (UMap) Len

func (m UMap) Len() int

Len returns length of the vault

func (UMap) Put

func (m UMap) Put(uid int64, user *User) error

Put performs non-blocking put of an object into the vault.

type User

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

User structure.

func Deserialize

func Deserialize(data []byte) (User, error)

Deserialize performs deserialization of the User structure.

func MergesortJoinDate

func MergesortJoinDate(items []*User) []*User

MergesortJoinDate performs merge sort by join date.

func MergesortLastTicketDate

func MergesortLastTicketDate(items []*User) []*User

MergesortLastTicketDate performs merge sort by last buy ticket date.

func MergesortLeaderboardPosition

func MergesortLeaderboardPosition(items []*User) []*User

MergesortLeaderboardPosition performs merge sort by leaderboard position.

func MergesortTotalWonAmount

func MergesortTotalWonAmount(items []*User) []*User

MergesortTotalWonAmount performs merge sort by total won amount.

func NewUser

func NewUser(
	userID int64, name string,
	subscribed, hasTicket, isPlayer bool,
	leaderboardPosition uint32,
) User

NewUser creates an object of User structure.

func (*User) GetHasTicket

func (u *User) GetHasTicket() bool

GetHasTicket performs non-blocking get of user's ticket status.

func (*User) GetIsPlayer

func (u *User) GetIsPlayer() bool

GetIsPlayer performs non-blocking get of user's player status.

func (*User) GetJoinDate

func (u *User) GetJoinDate() time.Time

GetJoinDate performs non-blocking get of user's join date.

func (*User) GetLastTicketDate

func (u *User) GetLastTicketDate() time.Time

GetLastTicketDate performs non-blocking get of user's last ticket purchase date.

func (*User) GetLastWonAmount

func (u *User) GetLastWonAmount() float64

GetLastWonAmount performs non-blocking get of user's last won amount.

func (*User) GetLeaderboardPosition

func (u *User) GetLeaderboardPosition() uint32

GetLeaderboardPosition performs non-blocking get of user's leaderboard position.

func (*User) GetName

func (u *User) GetName() string

GetName performs non-blocking get of user's name.

func (*User) GetPlaySequence

func (u *User) GetPlaySequence() string

GetPlaySequence performs non-blocking get of user's play sequence.

func (*User) GetSubscribed

func (u *User) GetSubscribed() bool

GetSubscribed performs non-blocking get of user's subscription status.

func (*User) GetTotalWonAmount

func (u *User) GetTotalWonAmount() float64

GetTotalWonAmount performs non-blocking get of user's total won amount.

func (*User) GetUserID

func (u *User) GetUserID() int64

GetUserID performs non-blocking get of user's id.

func (*User) GetWalletAddress

func (u *User) GetWalletAddress() string

GetWalletAddress performs non-blocking get of user's wallet address.

func (*User) Serialize

func (u *User) Serialize() []byte

Serialize performs serialization of the User structure.

func (*User) SetHasTicket

func (u *User) SetHasTicket(val bool)

SetHasTicket performs non-blocking set of user's ticket status.

func (*User) SetIsPlayer

func (u *User) SetIsPlayer(val bool)

SetIsPlayer performs non-blocking set of user's player status.

func (*User) SetJoinDate

func (u *User) SetJoinDate(date time.Time)

SetJoinDate performs non-blocking set of user's join date.

func (*User) SetLastTicketDate

func (u *User) SetLastTicketDate(date time.Time)

SetLastTicketDate performs non-blocking set of user's last ticket purchase date.

func (*User) SetLastWonAmount

func (u *User) SetLastWonAmount(val float64)

SetLastWonAmount performs non-blocking set of user's last won amount.

func (*User) SetLeaderboardPosition

func (u *User) SetLeaderboardPosition(val uint32)

SetLeaderboardPosition performs non-blocking set of user's leaderboard position.

func (*User) SetName

func (u *User) SetName(val string)

SetName performs non-blocking set of user's name.

func (*User) SetPlaySequence

func (u *User) SetPlaySequence(val string)

SetPlaySequence performs non-blocking set of user's play sequence.

func (*User) SetSubscribed

func (u *User) SetSubscribed(val bool)

SetSubscribed performs non-blocking set of user's subscription status.

func (*User) SetTotalWonAmount

func (u *User) SetTotalWonAmount(val float64)

SetTotalWonAmount performs non-blocking set of user's total won amount.

func (*User) SetUserID

func (u *User) SetUserID(id int64)

SetUserID performs non-blocking set of user's ID.

func (*User) SetWalletAddress

func (u *User) SetWalletAddress(val string)

SetWalletAddress performs non-blocking set of user's wallet address.

type Users

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

Users structure.

func NewUsers

func NewUsers(name string, dbPath string) Users

NewUsers creates an object of Users structure.

func (Users) Apply

func (u Users) Apply(uid int64, fn func(u *User) error) error

Apply performs an action on Users structure object.

func (Users) BatchDelete

func (u Users) BatchDelete(uid int64)

BatchDelete deletes an object from the vault by batching (leveldb).

func (Users) BatchPut

func (u Users) BatchPut(uid int64, user *User)

BatchPut puts an object into the vault by batching (leveldb).

func (Users) BatchWrite

func (u Users) BatchWrite() error

BatchWrite performs write of the batch to the database.

func (Users) Close

func (u Users) Close()

Close closes the database.

func (Users) Delete

func (u Users) Delete(uid int64) error

Delete an object from the vault.

func (Users) Exist

func (u Users) Exist(uid int64) bool

Exist checks if an object in the vault.

func (Users) FormJoinDateList

func (u Users) FormJoinDateList() []*User

FormJoinDateList forms list of *User sorted by join date.

func (Users) FormLastTicketDateList

func (u Users) FormLastTicketDateList() []*User

FormLastTicketDateList forms list of *User sorted by last ticket purchase date.

func (Users) FormLeaderboardPositionList

func (u Users) FormLeaderboardPositionList() []*User

FormLeaderboardPositionList forms list of *User sorted by position in the leaderboard.

func (Users) FormTotalWonAmountList

func (u Users) FormTotalWonAmountList() []*User

FormTotalWonAmountList forms list of *User sorted by total won amount.

func (Users) Get

func (u Users) Get(uid int64) *User

Get an objecto from the vault.

func (Users) Iterate

func (u Users) Iterate() map[int64]*User

Iterate brings possibility to iterate over the vault.

func (Users) Len

func (u Users) Len() int

Len returns length of the vault

func (Users) Put

func (u Users) Put(uid int64, user *User) error

Put an object to the vault.

Jump to

Keyboard shortcuts

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