core

package
v0.0.0-...-64046f9 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ZeroChatID = ChatID(0)

Variables

View Source
var ErrChatNotFound = errors.New("chat not found")
View Source
var ErrFileNotFound = errors.New("file not found")
View Source
var (
	// ErrInvalidChatType returns when provided chat type is invalid.
	ErrInvalidChatType = errors.New("invalid chat type")
)
View Source
var (
	ErrInvalidKind = errors.New("kind is invalid")
)
View Source
var ErrUserNotFound = errors.New("user not found")

Functions

This section is empty.

Types

type Chat

type Chat struct {
	// Unique ID of chat
	ID ChatID

	// Unique ID of chat in Telegram
	TelegramID int64

	// Title of chat.
	Title string

	// Type represents type of chat.
	Type ChatType

	// OwnerID represents user who link the chat.
	OwnerID UserID

	// LinkedAt time when chat was linked to Share File Bot.
	LinkedAt time.Time

	// UpdatedAt time when chat was last updated in Share File Bot.
	UpdatedAt null.Time
}

Chat represents chat linked to Share File Bot.

func NewChat

func NewChat(tgID int64, title string, typ ChatType, ownerID UserID) *Chat

NewChat creates a chat by provided info

func (*Chat) Patch

func (chat *Chat) Patch(do func(*Chat)) bool

Patch of chat. Modify chat in do and check if something changed.

type ChatDownloadStats

type ChatDownloadStats struct {
	// Downloads with subscription
	WithSubscription int

	// Downloads with new subscription
	NewSubscription int
}

type ChatID

type ChatID int

ChatID represents unique identifier of Chat in Share File Bot.

type ChatStore

type ChatStore interface {
	// Add chat to store.
	Add(ctx context.Context, chat *Chat) error

	// Update chat in store.
	Update(ctx context.Context, chat *Chat) error

	Query() ChatStoreQuery
}

ChatStore define interface for persistence of chat.

type ChatStoreQuery

type ChatStoreQuery interface {
	// Filter Users by ID's
	ID(ids ...ChatID) ChatStoreQuery

	TelegramID(v int64) ChatStoreQuery

	// UserID filter response by user id
	OwnerID(id UserID) ChatStoreQuery

	// Query only one item from store.
	One(ctx context.Context) (*Chat, error)

	// Query all items from store.
	All(ctx context.Context) ([]*Chat, error)

	// Delete all matched objects
	Delete(ctx context.Context) (int, error)

	// Count items in store.
	Count(ctx context.Context) (int, error)
}

ChatStoreQuery define interface for complex queries.

type ChatType

type ChatType int8

ChatType define types of chat.

const (
	// ChatTypeGroup represents simple group chat in Telegram.
	ChatTypeGroup ChatType = iota + 1
	// ChatTypeSuperGroup represents large group chat in Telegram.
	ChatTypeSuperGroup
	// ChatTypeChannel represents channel in Telegram.
	ChatTypeChannel
)

func ParseChatType

func ParseChatType(v string) (ChatType, error)

ParseChatType convert string to chat type, or return error.

func (ChatType) String

func (i ChatType) String() string

type Download

type Download struct {
	// ID of download.
	ID DownloadID

	// Reference to file. Can be null.
	FileID FileID

	// References to user. Can be null.
	UserID UserID

	// If true, means user was requested to subscription and successefuly subscribed,
	// False means, user was already subscribed,
	// Null means check is disable.
	NewSubscription null.Bool

	// At time when download was happen
	At time.Time
}

func NewDownload

func NewDownload(fileID FileID, userID UserID) *Download

func (*Download) SetNewSubscription

func (dwn *Download) SetNewSubscription(v bool)

type DownloadID

type DownloadID int

DownloadID alias for download.

type DownloadRestrictions

type DownloadRestrictions struct {
	// Request subscription to this chat. Zero means null.
	ChatID ChatID
}

func (*DownloadRestrictions) Any

func (dr *DownloadRestrictions) Any() bool

func (*DownloadRestrictions) HasChatID

func (dr *DownloadRestrictions) HasChatID() bool

type DownloadStore

type DownloadStore interface {
	Add(ctx context.Context, download *Download) error
	GetFileStats(ctx context.Context, id FileID) (*FileDownloadStats, error)
	GetChatStats(ctx context.Context, id ChatID) (*ChatDownloadStats, error)
	Query() DownloadStoreQuery
}

type DownloadStoreQuery

type DownloadStoreQuery interface {
	FileID(id FileID) DownloadStoreQuery

	Count(ctx context.Context) (int, error)
}

type File

type File struct {
	// Unique ID of File.
	ID FileID

	// Telegram File ID
	TelegramID string

	// Public File ID
	PublicID string

	// If true, file violates copyright and is not available
	IsViolatesCopyright null.Bool

	// Caption of file
	Caption null.String

	// Kind of file
	Kind Kind

	// MIMEType of file
	MIMEType null.String

	// File name
	Name string

	// File size in bytes
	Size int

	// Contains restrictions for download
	Restriction DownloadRestrictions

	// Metadata contains metadata of file depends by kind.
	Metadata Metadata

	// It's URI of post with tg:// scheme.
	LinkedPostURI null.String

	// Reference to user who uploads file.
	OwnerID UserID

	// Time when file was created.
	CreatedAt time.Time
}

File represents shared file.

func NewFile

func NewFile(
	fileID string,
	caption string,
	kind Kind,
	mimeType string,
	size int,
	name string,
	ownerID UserID,
	longID bool,
	md Metadata,
) *File

func (*File) HasLinkedPostURI

func (file *File) HasLinkedPostURI() bool

func (*File) RegenPublicID

func (file *File) RegenPublicID()

func (*File) SetLinkedPostURI

func (file *File) SetLinkedPostURI(v string)

type FileDownloadStats

type FileDownloadStats struct {
	// Total downloads count
	Total int

	// Unique downloads count
	Unique int

	// Downloads with subscription
	WithSubscription int

	// Downloads with new subscription
	NewSubscription int
}

FileDownloadStats of file.

type FileID

type FileID int

FileID it's alias for share id.

type FileStore

type FileStore interface {
	// Add File to store. Update ID.
	Add(ctx context.Context, file *File) error

	// Update file in store.
	Update(ctx context.Context, file *File) error

	Query() FileStoreQuery
}

FileStore define persistence interface for File.

type FileStoreQuery

type FileStoreQuery interface {
	ID(id FileID) FileStoreQuery
	OwnerID(id UserID) FileStoreQuery
	PublicID(ids ...string) FileStoreQuery
	RestrictionChatID(id ChatID) FileStoreQuery

	All(ctx context.Context) ([]*File, error)
	One(ctx context.Context) (*File, error)
	Delete(ctx context.Context) error
	Count(ctx context.Context) (int, error)
}

type Kind

type Kind int8

Kind define enum type for kind of files.

const (
	KindUnknown Kind = iota
	KindDocument
	KindAnimation
	KindAudio
	KindPhoto
	KindVideo
	KindVoice
)

func ParseKind

func ParseKind(v string) (Kind, error)

func (Kind) String

func (i Kind) String() string

type Metadata

type Metadata struct {
	Audio  *MetadataAudio   `json:"audio,omitempty"`
	Stcker *MetadataSticker `json:"stcker,omitempty"`
}

func NewMetadataAudio

func NewMetadataAudio(title, performer string) Metadata

type MetadataAudio

type MetadataAudio struct {
	Title     string `json:"title,omitempty"`
	Performer string `json:"performer,omitempty"`
}

type MetadataSticker

type MetadataSticker struct {
	SetName string `json:"set_name,omitempty"`
	Emoji   string `json:"emoji,omitempty"`
}

type User

type User struct {
	// Unique ID of user in bot and Telegram.
	ID UserID

	// First name of user from Telegram
	FirstName string

	// Last name of user from Telegram (optional)
	LastName null.String

	// Username of user from Telegram (optional)
	Username null.String

	// Language code of user from Telegram (optional)
	LanguageCode string

	// True, if user is admin of bot.
	IsAdmin bool

	// Settings of user
	Settings UserSettings

	// Ref is set we user /start with deep-link like ref_*
	Ref null.String

	// Time of first interaction with bot
	JoinedAt time.Time

	// Time when user info was updated
	UpdatedAt null.Time
}

User of bot.

func NewUser

func NewUser(
	id UserID,
	firstName, lastName, username, langCode string,
) *User

func (*User) Patch

func (user *User) Patch(do func(*User)) bool

type UserID

type UserID int

UserID it's alias for user identifier

type UserRefStats

type UserRefStats []UserRefStatsItem

type UserRefStatsItem

type UserRefStatsItem struct {
	Ref   null.String
	Count int
}

type UserSettings

type UserSettings struct {
	// If true, bot generate super long id's for user files.
	LongIDs bool `json:"long_ids"`

	// Timestamp of last update of user settings.
	UpdatedAt null.Time `json:"updated_at"`
}

UserSettings contains user settings.

func (*UserSettings) Patch

func (settings *UserSettings) Patch(do func(*UserSettings)) bool

Patch check if something changed, apply changes and set new updated at.

type UserStore

type UserStore interface {
	Add(ctx context.Context, user *User) error
	Find(ctx context.Context, id UserID) (*User, error)
	Update(ctx context.Context, user *User) error

	RefStats(ctx context.Context) (UserRefStats, error)

	Query() UserStoreQuery
}

UserStore define interface for persistence of bot.

type UserStoreQuery

type UserStoreQuery interface {
	Count(ctx context.Context) (int, error)
}

Jump to

Keyboard shortcuts

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