mtpwrap

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: BSD-3-Clause Imports: 29 Imported by: 2

README

mtpwrap

MTProto library wrapper.

Documentation

Overview

Package mtpwrap provides some functions for the gotd/td functions

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyRunning is returned if the attempt is made to start the client,
	// while there's another instance running asynchronously.
	ErrAlreadyRunning = errors.New("already running asynchronously, stop the running instance first")
)
View Source
var ErrNoChannelReactions = errors.New("no channel reactions")

Functions

This section is empty.

Types

type Client

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

func New

func New(appID int, appHash string, opts ...Option) (*Client, error)

func (*Client) ChannelReactions added in v0.0.4

func (cl *Client) ChannelReactions(ctx context.Context, channel tg.InputChannelClass) (tg.ChatReactionsClass, error)

ChannelReactions returns available channel reactions.

func (*Client) Client added in v0.0.3

func (c *Client) Client() *telegram.Client

Client returns the underlying telegram client.

func (*Client) CreateChat

func (c *Client) CreateChat(ctx context.Context, title string, userIDs ...int64) error

CreateChat creates a Chat (not a Mega- or Gigagroup).

Example

 if err := cl.CreateChat(ctx, "mtproto-test",123455678, 312849128); err != nil {
		return err
	}

func (*Client) DeleteMessages

func (c *Client) DeleteMessages(ctx context.Context, dlg Entity, messages []messages.Elem) (int, error)

func (*Client) FindChannel added in v0.0.4

func (c *Client) FindChannel(ctx context.Context, id int64) (*tg.Channel, error)

FindChannel returns a channel with ID.

func (*Client) FindChat added in v0.0.4

func (c *Client) FindChat(ctx context.Context, id int64) (*tg.Chat, error)

func (*Client) GetChannels

func (c *Client) GetChannels(ctx context.Context) ([]Entity, error)

GetChannels retrieves the account channels.

func (*Client) GetChats

func (c *Client) GetChats(ctx context.Context) ([]Entity, error)

GetChats retrieves the account chats.

func (*Client) GetEntities

func (c *Client) GetEntities(ctx context.Context, filterFn FilterFunc) ([]Entity, error)

GetEntities ensures that storage is populated, then iterates through storage peers calling filterFn for each peer. The filterFn should return Entity and true, if the peer satisfies the criteria, or nil and false, otherwise.

func (*Client) Run

func (c *Client) Run(ctx context.Context, fn func(context.Context, *telegram.Client) error) error

Run runs an arbitrary telegram session.

func (*Client) SearchAllMessages

func (c *Client) SearchAllMessages(ctx context.Context, dlg Entity, who tg.InputPeerClass, cb func(n int)) ([]messages.Elem, error)

SearchAllMessages search messages in the chat or channel `dlg`. It finds ALL messages from the person `who`. returns a slice of message.Elem. For each API call, the callback function will be invoked, if not nil.

func (*Client) SearchAllMyMessages

func (c *Client) SearchAllMyMessages(ctx context.Context, dlg Entity, cb func(n int)) ([]messages.Elem, error)

SearchAllMyMessages returns the current authorized user messages from chat or channel `dlg`. For each API call, the callback function will be invoked, if not nil.

func (*Client) Start

func (c *Client) Start(ctx context.Context) error

Start starts the telegram session in goroutine

func (*Client) Stop

func (c *Client) Stop() error

type Entity

type Entity interface {
	GetID() int64
	GetTitle() string
	TypeInfo() tdp.Type
	Zero() bool
}

Entity interface is the subset of functions that are commonly defined on most entities in telegram lib. It can be a user, a chat or channel, or any other telegram Entity.

type FilterFunc

type FilterFunc func(storage.Peer) (ent Entity, ok bool)

func FilterAnd added in v0.0.4

func FilterAnd(f1 FilterFunc, f2 FilterFunc) FilterFunc

func FilterChannel

func FilterChannel() FilterFunc

func FilterChat

func FilterChat() FilterFunc

func FilterPeer added in v0.0.4

func FilterPeer(id int64) FilterFunc

type Logger

type Logger interface {
	Print(...any)
	Printf(string, ...any)
	Println(...any)
	Debug(...any)
	Debugf(string, ...any)
	Debugln(...any)
}

Logger is the logger interface that is used throughout the package.

var Log Logger = dlog.New(os.Stderr, "", 0, false)

Log is the global logger, replace it in the downstream, if needed, or go with the default one.

type MemStorage

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

MemStorage is the default peer storage for MTP. It uses a map to store all peers, hence, it's not a persistent store.

func NewMemStorage

func NewMemStorage() *MemStorage

func (*MemStorage) Add

func (ms *MemStorage) Add(_ context.Context, value storage.Peer) error

func (*MemStorage) Assign

func (ms *MemStorage) Assign(_ context.Context, key string, value storage.Peer) error

func (*MemStorage) Close

func (ms *MemStorage) Close() error

func (*MemStorage) Err

func (ms *MemStorage) Err() error

func (*MemStorage) Find

func (ms *MemStorage) Find(ctx context.Context, key storage.PeerKey) (storage.Peer, error)

func (*MemStorage) IsIterating

func (ms *MemStorage) IsIterating() bool

func (*MemStorage) Iterate

func (ms *MemStorage) Iterate(ctx context.Context) (storage.PeerIterator, error)

func (*MemStorage) Next

func (ms *MemStorage) Next(ctx context.Context) bool

func (*MemStorage) Resolve

func (ms *MemStorage) Resolve(_ context.Context, key string) (storage.Peer, error)

func (*MemStorage) Value

func (ms *MemStorage) Value() storage.Peer

type Option

type Option func(c *Client)

func WithApiCredsFile

func WithApiCredsFile(path string) Option

func WithAuth

func WithAuth(flow authflow.FullAuthFlow) Option

WithAuth allows to override the authorization flow

func WithDebug

func WithDebug(enable bool) Option

func WithMTPOptions

func WithMTPOptions(opts telegram.Options) Option

func WithPeerStorage

func WithPeerStorage(s storage.PeerStorage) Option

WithPeerStorage allows to specify a custom storage for peer data.

func WithStorage

func WithStorage(path string) Option

WithStorage allows to specify custom session storage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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