events

package
v1.11.6 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 16 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
	AddApprovedUser(id int64, name string) error
	RemoveApprovedUser(id int64) error
	IsApprovedUser(userID int64) bool
}

Bot is an interface for bot events.

type Locator added in v0.2.0

type Locator interface {
	AddMessage(msg string, chatID, userID int64, userName string, msgID int) error
	AddSpam(userID int64, checks []spamcheck.Response) error
	Message(msg string) (storage.MsgMeta, bool)
	Spam(userID int64) (storage.SpamData, bool)
	MsgHash(msg string) string
	UserNameByID(userID int64) string
}

Locator is an interface for message locator

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 SuperUsers added in v1.3.0

type SuperUsers []string

SuperUsers for moderators

func (SuperUsers) IsSuper added in v1.3.0

func (s SuperUsers) 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)
	GetChatAdministrators(config tbapi.ChatAdministratorsConfig) ([]tbapi.ChatMember, error)
}

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

type TelegramListener

type TelegramListener struct {
	TbAPI                   TbAPI         // telegram bot API
	SpamLogger              SpamLogger    // logger to save spam to files and db
	Bot                     Bot           // bot to handle messages
	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 // idle timeout to send "idle" message to bots
	SuperUsers              SuperUsers    // list of superusers, can ban and report spam, can't be banned
	TestingIDs              []int64       // list of chat IDs to test the bot
	StartupMsg              string        // message to send on startup to the primary chat
	WarnMsg                 string        // message to send on warning
	NoSpamReply             bool          // do not reply on spam messages in the primary chat
	TrainingMode            bool          // do not ban users, just report and train spam detector
	Locator                 Locator       // message locator to get info about messages
	DisableAdminSpamForward bool          // disable forwarding spam reports to admin chat support
	Dry                     bool          // dry run, do not ban or send messages
	// 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