events

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package events provide event handlers for telegram bot and all the high-level event handlers. It parses messages, sends them to the spam detector and handles the results. It can also ban users and send messages to the admin.

In addition to that, it provides support for admin chat handling allowing to unban users via the web service and update the list of spam samples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot interface {
	OnMessage(msg bot.Message) (response bot.Response)
	UpdateSpam(msg string) error
	UpdateHam(msg string) error
}

Bot is an interface for bot events.

type Locator added in v0.2.0

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

Locator stores messages for a given time period. It is used to locate the message in the chat by its hash. Useful to match messages from admin chat (only text available) to the original message. Note: it is not thread-safe, use it from a single goroutine only.

func NewLocator added in v0.2.0

func NewLocator(ttl time.Duration, minSize int) *Locator

NewLocator creates new Locator. ttl defines how long to keep messages, minSize defines the minimum number of messages to keep

func (*Locator) Add added in v0.2.0

func (l *Locator) Add(msg string, chatID, userID int64, msgID int)

Add adds messages to the locator and removes old messages. Messages are removed the total number of messages exceeds minSize and the last cleanup was performed more than cleanupDuration ago. The reason for minSize is to avoid removing messages on low-traffic chats where admin visits are rare. Note: removes old messages only once per cleanupDuration and only if a new message is added

func (*Locator) Get added in v0.2.0

func (l *Locator) Get(msg string) (MsgMeta, bool)

Get returns message MsgMeta for given msg this allows to match messages from admin chat (only text available) to the original message

func (*Locator) MsgHash added in v0.2.0

func (l *Locator) MsgHash(msg string) string

MsgHash returns sha256 hash of a message

type MsgMeta added in v0.2.0

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

MsgMeta stores message metadata

func (MsgMeta) String added in v0.2.0

func (m MsgMeta) String() string

type SpamLogger

type SpamLogger interface {
	Save(msg *bot.Message, response *bot.Response)
}

SpamLogger is an interface for spam logger

type SpamLoggerFunc

type SpamLoggerFunc func(msg *bot.Message, response *bot.Response)

SpamLoggerFunc is a function that implements SpamLogger interface

func (SpamLoggerFunc) Save

func (f SpamLoggerFunc) Save(msg *bot.Message, response *bot.Response)

Save is a function that implements SpamLogger interface

type SpamWeb

type SpamWeb interface {
	UnbanURL(userID int64, msg string) string
}

SpamWeb is an interface for the web component

type SuperUser

type SuperUser []string

SuperUser for moderators

func (SuperUser) IsSuper

func (s SuperUser) IsSuper(userName string) bool

IsSuper checks if username in the list of super users

type TbAPI

type TbAPI interface {
	GetUpdatesChan(config tbapi.UpdateConfig) tbapi.UpdatesChannel
	Send(c tbapi.Chattable) (tbapi.Message, error)
	Request(c tbapi.Chattable) (*tbapi.APIResponse, error)
	GetChat(config tbapi.ChatInfoConfig) (tbapi.Chat, error)
}

TbAPI is an interface for telegram bot API, only subset of methods used

type TelegramListener

type TelegramListener struct {
	TbAPI        TbAPI
	SpamLogger   SpamLogger
	Bot          Bot
	Group        string // can be int64 or public group username (without "@" prefix)
	AdminGroup   string // can be int64 or public group username (without "@" prefix)
	IdleDuration time.Duration
	SuperUsers   SuperUser
	TestingIDs   []int64
	StartupMsg   string
	NoSpamReply  bool
	Dry          bool
	SpamWeb      SpamWeb
	Locator      *Locator
	// contains filtered or unexported fields
}

TelegramListener listens to tg update, forward to bots and send back responses Not thread safe

func (*TelegramListener) Do

Do process all events, blocked call

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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