sessions

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sessions implements types for working with telegram sessions.

Index

Constants

View Source
const (
	InMenu state = iota
	InInputDialog
)

Possible states of the user session.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveSessions

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

ActiveSessions represents list of all active telegram sessions.

func NewActiveSessions

func NewActiveSessions(timeout time.Duration, frequency time.Duration, errorLog *log.Logger) *ActiveSessions

NewActiveSessions initializes new instance of ActiveSessions object. The argument 'timeout' specifies the maximum amount of time that a session can be inactive before it is terminated. The argument 'frequency' specifies how often the search for inactive sessions occurs. 'errorLog' argument is used to log error messages that may occur during session termination.

func (*ActiveSessions) Get

func (as *ActiveSessions) Get(userID int64) (Session, bool)

Get returns session of user with specified ID. If the session doesn't exist, second parameter will be equal to false.

func (*ActiveSessions) Set

func (as *ActiveSessions) Set(userID int64, s Session, isNew bool)

Set adds new or replaces existing session. The last boolean parameter specifies if it is a completely new session (with new image) or same session that just need to be updated. This is needed to avoid the memory leaks from the goroutines that may be waiting for the user input.

type Session

type Session struct {
	UserID        int64
	MenuMessageID int64
	State         state
	Input         chan tg.Message
	QuitInput     chan int
	ImgPath       string
	Menu          menu.Menu
	Config        primitive.Config
	// contains filtered or unexported fields
}

Session represents one telegram session.

func NewSession

func NewSession(userID, menuMessageID int64, imgPath string, workers int) Session

NewSession initializes new instance of Session object.

Jump to

Keyboard shortcuts

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