state

package
v0.0.0-...-981a9ea Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package state binds a mongo database and exports functions for interacting with said database.

Index

Constants

This section is empty.

Variables

View Source
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 Channel

type Channel struct {
	Name string

	Joined   bool
	Sleeping bool
	Lurking  bool
}

type Client

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

Client provides functions to interact with the databse.

func NewClient

func NewClient(uri string) (*Client, error)

NewClient connects to the mongo database located at uri and pings it.

func (*Client) AddVoicemail

func (c *Client) AddVoicemail(username, channel, creator, message string, created time.Time) error

AddVoicemail adds a voicemail to a user.

func (*Client) BumpUser

func (c *Client) BumpUser(u twitch.User, t time.Time) (*User, error)

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

func (c *Client) CheckForVoicemails(name string) ([]*Voicemail, error)

CheckForVoicemails pops all voicemails a user has

func (*Client) GetJoinedChannels

func (c *Client) GetJoinedChannels() ([]string, error)

GetJoinedChannels returns all currentyl joined channels.

func (*Client) GetUserByID

func (c *Client) GetUserByID(id string) (User, error)

GetUserByID gets the user with id id.

func (*Client) GetUserByName

func (c *Client) GetUserByName(name string) (User, error)

GetUserByName gets the user with name name.

func (*Client) IsChannelJoined

func (c *Client) IsChannelJoined(channelName string) (bool, error)

IsChannelJoined check if a channel is joined.

func (*Client) IsLurking

func (c *Client) IsLurking(channelName string) (bool, error)

IsLurking return true if the bot is just lurking in a channel.

func (*Client) IsSleeping

func (c *Client) IsSleeping(channelName string) (bool, error)

IsSleeping checks if a channels is sleeping.

func (*Client) IsTimedout

func (c *Client) IsTimedout(id string, now time.Time) (bool, error)

IsTimedout checks if a user is timed out.

func (*Client) JoinChannel

func (c *Client) JoinChannel(channelName string, joined bool) error

JoinChannel sets joined.

func (*Client) Patsch

func (c *Client) Patsch(id string, now time.Time) error

func (*Client) SetLurking

func (c *Client) SetLurking(channelName string, lurking bool) error

SetLurking sets lurking.

func (*Client) SetSleeping

func (c *Client) SetSleeping(channelName string, sleeping bool) error

SetSleeping sets sleeping.

func (*Client) UpdateUser

func (c *Client) UpdateUser(user User) error

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 (u *User) AddVoicemail(voicemail *Voicemail)

func (*User) HasPatschedLately

func (u *User) HasPatschedLately(now time.Time) bool

HasPatschedLately returns true if lastPatsched is no more then 48 hourse before now.

func (*User) HasPatschedToday

func (u *User) HasPatschedToday(now time.Time) bool

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 (u *User) HasVoicemails() bool

func (*User) IsTimedout

func (u *User) IsTimedout(now time.Time) bool

IsTimedout checks if a user is currently timed out.

func (*User) Patsch

func (u *User) Patsch(now time.Time) error

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 (u *User) PopVoicemails() []*Voicemail

func (*User) SetTimeout

func (u *User) SetTimeout(t time.Time)

SetTimeout times out a user until t.

type Voicemail

type Voicemail struct {
	Created time.Time
	Message string
	Channel string
	Creator string
}

func NewVoicemail

func NewVoicemail(channel, creator, message string, created time.Time) *Voicemail

func (*Voicemail) String

func (v *Voicemail) String() string

Jump to

Keyboard shortcuts

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