Documentation ¶
Overview ¶
Package state binds a mongo database and exports functions for interacting with said database.
Index ¶
- Variables
- type Channel
- type Client
- func (c *Client) AddVoicemail(username, channel, creator, message string, created time.Time) error
- func (c *Client) BumpUser(u twitch.User, t time.Time) (*User, error)
- func (c *Client) CheckForVoicemails(name string) ([]*Voicemail, error)
- func (c *Client) GetJoinedChannels() ([]string, error)
- func (c *Client) GetUserByID(id string) (User, error)
- func (c *Client) GetUserByName(name string) (User, error)
- func (c *Client) IsChannelJoined(channelName string) (bool, error)
- func (c *Client) IsLurking(channelName string) (bool, error)
- func (c *Client) IsSleeping(channelName string) (bool, error)
- func (c *Client) IsTimedout(id string, now time.Time) (bool, error)
- func (c *Client) JoinChannel(channelName string, joined bool) error
- func (c *Client) Patsch(id string, now time.Time) error
- func (c *Client) SetLurking(channelName string, lurking bool) error
- func (c *Client) SetSleeping(channelName string, sleeping bool) error
- func (c *Client) UpdateUser(user User) error
- type User
- func (u *User) AddVoicemail(voicemail *Voicemail)
- func (u *User) HasPatschedLately(now time.Time) bool
- func (u *User) HasPatschedToday(now time.Time) bool
- func (u *User) HasVoicemails() bool
- func (u *User) IsTimedout(now time.Time) bool
- func (u *User) Patsch(now time.Time) error
- func (u *User) PopVoicemails() []*Voicemail
- func (u *User) SetTimeout(t time.Time)
- type Voicemail
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyPatsched = errors.New("already patsched today") ErrForgotToPatsch = errors.New("fish was not patsched lately") )
These errors may occur
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides functions to interact with the databse.
func (*Client) AddVoicemail ¶
AddVoicemail adds a voicemail to a user.
func (*Client) BumpUser ¶
BumpUser makes sure the twitch user u exists in the database and creates it if needed. Either way it sets lastseen to t.
func (*Client) CheckForVoicemails ¶
CheckForVoicemails pops all voicemails a user has
func (*Client) GetJoinedChannels ¶
GetJoinedChannels returns all currentyl joined channels.
func (*Client) GetUserByID ¶
GetUserByID gets the user with id id.
func (*Client) GetUserByName ¶
GetUserByName gets the user with name name.
func (*Client) IsChannelJoined ¶
IsChannelJoined check if a channel is joined.
func (*Client) IsSleeping ¶
IsSleeping checks if a channels is sleeping.
func (*Client) IsTimedout ¶
IsTimedout checks if a user is timed out.
func (*Client) JoinChannel ¶
JoinChannel sets joined.
func (*Client) SetLurking ¶
SetLurking sets lurking.
func (*Client) SetSleeping ¶
SetSleeping sets sleeping.
func (*Client) UpdateUser ¶
UpdateUser updates the user user in the mongo database.
type User ¶
type User struct { ID string Name string DisplayName string IsRegular bool Firstseen time.Time Lastseen time.Time Timeout time.Time LastPatsched time.Time PatschStreak int PatschCount int Voicemails []*Voicemail }
func (*User) AddVoicemail ¶
func (*User) HasPatschedLately ¶
HasPatschedLately returns true if lastPatsched is no more then 48 hourse before now.
func (*User) HasPatschedToday ¶
HasPatschedToday returns true if lastPatsched is on the same day as now. It does this by truncating both lastPatsched and now by a day and then checking for equality.
func (*User) HasVoicemails ¶
func (*User) IsTimedout ¶
IsTimedout checks if a user is currently timed out.
func (*User) Patsch ¶
Patsch sets count as well as streak and lastPatsched if applicable. A user must patsch every day but not more than once or their streak will be broken.
func (*User) PopVoicemails ¶
func (*User) SetTimeout ¶
SetTimeout times out a user until t.