tgbotbase

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: MIT Imports: 12 Imported by: 0

README

tgbot-base

Base for my Telegram bots

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcNextTimeFromMidnight

func CalcNextTimeFromMidnight(now time.Time, fromMidnight time.Duration) time.Time

func GetAllKeys

func GetAllKeys(conn *redis.Client, matchPattern string) ([]string, error)

GetAllKeys returns unique slice of keys matching the pattern

Types

type BackgroundMessageDealer

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

type BackgroundMessageHandler

type BackgroundMessageHandler interface {
	Init(chan<- tgbotapi.Chattable, chan<- ServiceMsg)
	Run()
	Name() string
}

type BaseHandler

type BaseHandler struct {
	OutMsgCh chan<- tgbotapi.Chattable
	SrvCh    chan<- ServiceMsg
}

type Bot

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

func NewBot

func NewBot(cfg Config) *Bot

func (*Bot) AddHandler

func (b *Bot) AddHandler(d MessageDealer)

func (*Bot) Send

func (b *Bot) Send(msg tgbotapi.Chattable)

func (*Bot) Start

func (b *Bot) Start()

type ChatID

type ChatID int64

type Config

type Config struct {
	TGBot struct {
		Token       string
		SkipConnect bool
		Verbose     bool
	}

	Proxy_SOCKS5 struct {
		Server string
		User   string
		Pass   string
	}
}

type Cron

type Cron interface {
	AddJob(when time.Time, job CronJob)
}

Cron interface declares interfaces for communication with some cron daemon

func NewCron

func NewCron() Cron

NewCron creates an instance of cron

type CronJob

type CronJob interface {
	Do(scheduledWhen time.Time, cron Cron)
}

CronJob provides a piece of work which should be done once its time has come

type EngagementHandler added in v0.0.2

type EngagementHandler interface {
	Name() string
	Engaged(chat *tgbotapi.Chat, user *tgbotapi.User)
	Disengaged(chat *tgbotapi.Chat, user *tgbotapi.User)
}

type EngagementMessageDealer added in v0.0.2

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

type HandlerTrigger

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

func NewHandlerTrigger

func NewHandlerTrigger(re *regexp.Regexp, cmds []string) HandlerTrigger

type IncomingMessageDealer

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

type IncomingMessageHandler

type IncomingMessageHandler interface {
	Init(chan<- tgbotapi.Chattable, chan<- ServiceMsg) HandlerTrigger
	HandleOne(tgbotapi.Message)
	Name() string
}

type MessageDealer

type MessageDealer interface {
	// contains filtered or unexported methods
}

func NewBackgroundMessageDealer

func NewBackgroundMessageDealer(h BackgroundMessageHandler) MessageDealer

func NewEngagementMessageDealer added in v0.0.3

func NewEngagementMessageDealer(h EngagementHandler) MessageDealer

type PropertyStorage

type PropertyStorage interface {
	GetProperty(name string, user UserID, chat ChatID) (string, error)
	SetPropertyForUser(name string, user UserID, value interface{}) error
	SetPropertyForChat(name string, chat ChatID, value interface{}) error
	SetPropertyForUserInChat(name string, user UserID, chat ChatID, value interface{}) error
	GetEveryHavingProperty(name string) ([]PropertyValue, error)
}

type PropertyValue

type PropertyValue struct {
	Value string
	User  UserID
	Chat  ChatID
}

type RedisConfig

type RedisConfig struct {
	Server string
	Pass   string
}

type RedisPool

type RedisPool interface {
	GetConnByID(dbID int) *redis.Client
	GetConnByName(dbName string) *redis.Client
}

func NewRedisPool

func NewRedisPool(cfg RedisConfig) RedisPool

type RedisPoolImpl

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

func (*RedisPoolImpl) GetConnByID

func (pool *RedisPoolImpl) GetConnByID(dbID int) *redis.Client

func (*RedisPoolImpl) GetConnByName

func (pool *RedisPoolImpl) GetConnByName(dbName string) *redis.Client

type RedisPropertyStorage

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

func NewRedisPropertyStorage

func NewRedisPropertyStorage(pool RedisPool) *RedisPropertyStorage

func (*RedisPropertyStorage) GetEveryHavingProperty

func (r *RedisPropertyStorage) GetEveryHavingProperty(name string) ([]PropertyValue, error)

func (*RedisPropertyStorage) GetProperty

func (r *RedisPropertyStorage) GetProperty(name string, user UserID, chat ChatID) (string, error)

func (*RedisPropertyStorage) SetPropertyForChat

func (r *RedisPropertyStorage) SetPropertyForChat(name string, chat ChatID, value interface{}) error

func (*RedisPropertyStorage) SetPropertyForUser

func (r *RedisPropertyStorage) SetPropertyForUser(name string, user UserID, value interface{}) error

func (*RedisPropertyStorage) SetPropertyForUserInChat

func (r *RedisPropertyStorage) SetPropertyForUserInChat(name string, user UserID, chat ChatID, value interface{}) error

type ServiceMsg

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

type UserID

type UserID int

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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