database

package
v0.0.0-...-66cef22 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatSettings

type ChatSettings struct {
	// Stopped Global Filters
	Stopped []string
}

type Database

type Database struct {
	// Mongo Client
	Client *mongo.Client
	// Database
	DB *mongo.Database
	// Users Collection
	Ucol *mongo.Collection
	// Main Collection
	Col *mongo.Collection
	// Manual Filters Collection
	Mcol *mongo.Collection
}

func NewDatabase

func NewDatabase() *Database

func (*Database) AddUser

func (db *Database) AddUser(userid int64) error

func (*Database) ConnectUser

func (db *Database) ConnectUser(userID, chatID int64)

func (*Database) DeleteConnection

func (db *Database) DeleteConnection(userID int64)

func (*Database) DeleteMfilter

func (db *Database) DeleteMfilter(chatID int64, key string)

func (*Database) GetAlert

func (db *Database) GetAlert(uniqueID string, index int) string

func (*Database) GetCachedSetting

func (db *Database) GetCachedSetting(chatID int64) *ChatSettings

func (*Database) GetConnection

func (db *Database) GetConnection(userID int64) (int64, bool)

func (*Database) GetMfilter

func (db *Database) GetMfilter(chatID int64, key string) (bson.M, bool)

func (*Database) GetMfilters

func (db *Database) GetMfilters(chatID int64) (*mongo.Cursor, error)

Returns all manual filters for a chat.

func (*Database) RecacheSettings

func (db *Database) RecacheSettings(chatID int64)

A Function To Update Cached Settings With Latest From DB

func (*Database) SaveMfilter

func (db *Database) SaveMfilter(data *Filter)

func (*Database) SearchMfilterClassic

func (db *Database) SearchMfilterClassic(chatID int64, input string) (results []*Filter)

SearchMfilterClassic uses the traditional way of fetching mfilters by fetching all mfilters of a chat and doing regex queries individually. This method is more resource intensive but could be faster for large scale bots with several hundred/thousand groups.

func (*Database) SearchMfilterNew

func (db *Database) SearchMfilterNew(chatID int64, fields []string, multiFilter bool) (results []*Filter)

SearchMfilterNew does a regex query on the database shifting some load to mongodb.

func (*Database) SetChatSetting

func (db *Database) SetChatSetting(chatID int64, key string, value any)

func (*Database) SetDefaultSettings

func (db *Database) SetDefaultSettings(chatID int64)

func (*Database) StartGfilter

func (db *Database) StartGfilter(chatID int64, key string)

func (*Database) Stats

func (db *Database) Stats() string

func (*Database) StopGfilter

func (db *Database) StopGfilter(chatID int64, key string)

func (*Database) StringMfilter

func (db *Database) StringMfilter(chatID int64) string

type Filter

type Filter struct {
	// Unique id of the filter
	ID string `bson:"_id"`
	// Chat where the filter is in effect
	ChatID int64 `bson:"group_id"`
	// The key/text which is filtered
	Text string `bson:"text"`
	// The text content/caption saved
	Content string `bson:"content,omitempty"`
	// The id of a media saved for the filter if any
	FileID string `bson:"file,omitempty"`
	// Buttons/markup saved for a filter if any
	Markup [][]map[string]string `bson:"button,omitempty"`
	// Alerts saved for a filter if any
	Alerts []string `bson:"alert,omitempty"`
	// Length of the text according to which filters are sorted
	Length int `bson:"length"`
	// Type of media saved if any
	MediaType string `bson:"mediaType,omitempty"`
}

A filter object stored in the database

type User

type User struct {
	// Unique telegram id of the user.
	ID int64 `bson:"_id"`
	// ID of the chat to which the user is connected.
	ConnectedChat int64 `bson:"connected,omitempty"`
}

A User Saved in the database.

Jump to

Keyboard shortcuts

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