Documentation
¶
Index ¶
- Constants
- Variables
- type Chat
- type ChatDownloadStats
- type ChatID
- type ChatStore
- type ChatStoreQuery
- type ChatType
- type Download
- type DownloadID
- type DownloadRestrictions
- type DownloadStore
- type DownloadStoreQuery
- type File
- type FileDownloadStats
- type FileID
- type FileStore
- type FileStoreQuery
- type Kind
- type Metadata
- type MetadataAudio
- type MetadataSticker
- type User
- type UserID
- type UserRefStats
- type UserRefStatsItem
- type UserSettings
- type UserStore
- type UserStoreQuery
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.
type ChatDownloadStats ¶
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.
func ParseChatType ¶
ParseChatType convert string to chat type, or return error.
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 (*Download) SetNewSubscription ¶
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 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 (*File) HasLinkedPostURI ¶
func (*File) RegenPublicID ¶
func (file *File) RegenPublicID()
func (*File) SetLinkedPostURI ¶
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 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 Metadata ¶
type Metadata struct {
Audio *MetadataAudio `json:"audio,omitempty"`
Stcker *MetadataSticker `json:"stcker,omitempty"`
}
func NewMetadataAudio ¶
type MetadataAudio ¶
type MetadataSticker ¶
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.
type UserRefStats ¶
type UserRefStats []UserRefStatsItem
type UserRefStatsItem ¶
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.
Click to show internal directories.
Click to hide internal directories.