storage

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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSqliteDB added in v1.3.0

func NewSqliteDB(file string) (*sqlx.DB, error)

NewSqliteDB creates a new sqlite database

Types

type ApprovedUsers

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

ApprovedUsers is a storage for approved users ids

func NewApprovedUsers

func NewApprovedUsers(db *sqlx.DB) (*ApprovedUsers, error)

NewApprovedUsers creates a new ApprovedUsers storage

func (*ApprovedUsers) Delete added in v1.5.1

func (au *ApprovedUsers) Delete(id string) error

Delete deletes the given id from the storage

func (*ApprovedUsers) Read

func (au *ApprovedUsers) Read() ([]approved.UserInfo, error)

Read returns all approved users.

func (*ApprovedUsers) Write added in v1.6.0

func (au *ApprovedUsers) Write(user approved.UserInfo) error

Write writes new user info to the storage

type DetectedSpam added in v1.7.0

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

DetectedSpam is a storage for detected spam entries

func NewDetectedSpam added in v1.7.0

func NewDetectedSpam(db *sqlx.DB) (*DetectedSpam, error)

NewDetectedSpam creates a new DetectedSpam storage

func (*DetectedSpam) Read added in v1.7.0

func (ds *DetectedSpam) Read() ([]DetectedSpamInfo, error)

Read returns all detected spam entries

func (*DetectedSpam) SetAddedToSamplesFlag added in v1.10.0

func (ds *DetectedSpam) SetAddedToSamplesFlag(id int64) error

SetAddedToSamplesFlag sets the added flag to true for the detected spam entry with the given id

func (*DetectedSpam) Write added in v1.7.0

func (ds *DetectedSpam) Write(entry DetectedSpamInfo, checks []spamcheck.Response) error

Write adds a new detected spam entry

type DetectedSpamInfo added in v1.7.0

type DetectedSpamInfo struct {
	ID         int64                `db:"id"`
	Text       string               `db:"text"`
	UserID     int64                `db:"user_id"`
	UserName   string               `db:"user_name"`
	Timestamp  time.Time            `db:"timestamp"`
	Added      bool                 `db:"added"`  // added to samples
	ChecksJSON string               `db:"checks"` // Store as JSON
	Checks     []spamcheck.Response `db:"-"`      // Don't store in DB
}

DetectedSpamInfo represents information about a detected spam entry.

type Locator added in v1.3.0

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

Locator stores messages metadata and spam results for a given ttl period. It is used to locate the message in the chat by its hash and to retrieve spam check results by userID. Useful to match messages from admin chat (only text available) to the original message and to get spam results using UserID.

func NewLocator added in v1.3.0

func NewLocator(ttl time.Duration, minSize int, db *sqlx.DB) (*Locator, error)

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

func (*Locator) AddMessage added in v1.3.0

func (l *Locator) AddMessage(msg string, chatID, userID int64, userName string, msgID int) error

AddMessage adds messages to the locator and also cleans up old messages.

func (*Locator) AddSpam added in v1.3.0

func (l *Locator) AddSpam(userID int64, checks []spamcheck.Response) error

AddSpam adds spam data to the locator and also cleans up old spam data.

func (*Locator) Close added in v1.3.0

func (l *Locator) Close() error

Close closes the database

func (*Locator) Message added in v1.3.0

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

Message 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 v1.3.0

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

MsgHash returns sha256 hash of a message we use hash to avoid storing potentially long messages and all we need is just match

func (*Locator) Spam added in v1.3.0

func (l *Locator) Spam(userID int64) (SpamData, bool)

Spam returns message SpamData for given msg

func (*Locator) UserIDByName added in v1.5.0

func (l *Locator) UserIDByName(userName string) int64

UserIDByName returns user id by username. Returns 0 if not found

func (*Locator) UserNameByID added in v1.5.0

func (l *Locator) UserNameByID(userID int64) string

UserNameByID returns username by user id. Returns empty string if not found

type MsgMeta added in v1.3.0

type MsgMeta struct {
	Time     time.Time `db:"time"`
	ChatID   int64     `db:"chat_id"`
	UserID   int64     `db:"user_id"`
	UserName string    `db:"user_name"`
	MsgID    int       `db:"msg_id"`
}

MsgMeta stores message metadata

func (MsgMeta) String added in v1.3.0

func (m MsgMeta) String() string

type SpamData added in v1.3.0

type SpamData struct {
	Time   time.Time `db:"time"`
	Checks []spamcheck.Response
}

SpamData stores spam data for a given user

func (SpamData) String added in v1.3.0

func (s SpamData) String() string

Jump to

Keyboard shortcuts

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