service

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChatNotFoundOrBotIsNotAdmin = errors.New("chat not found or bot is not admin")
	ErrChatIsUser                  = errors.New("chat is private (user)")
	ErrBotIsNotChatAdmin           = errors.New("bot is not admin")
	ErrBotNotEnoughRights          = errors.New("bot not has rights")
	ErrUserIsNotChatAdmin          = errors.New("user is not admin")
	ErrChatAlreadyConnected        = errors.New("chat already connected")
)
View Source
var (
	ErrInvalidID           = errors.New("invalid file id")
	ErrCantCheckMembership = errors.New("can't check membership of user")
)
View Source
var ErrFileViolatesCopyright = errors.New("file violates copyright")
View Source
var ErrUserIsNotAdmin = errors.New("user is not admin")
View Source
var (
	ErrUsersCantUploadFiles = errors.New("users can't upload files")
)

Functions

func ExtractDeepLinkPublicID

func ExtractDeepLinkPublicID(botUsername string, uries []string) ([]string, error)

ExtractDeepLinkPublicID extract payload from something like{botUsername}?start={payload}

Types

type Admin

type Admin struct {
	User     core.UserStore
	File     core.FileStore
	Download core.DownloadStore
	Chat     core.ChatStore
}

func (*Admin) SummaryStats

func (srv *Admin) SummaryStats(ctx context.Context, user *core.User) (*AdminSummaryStats, error)

type AdminSummaryStats

type AdminSummaryStats struct {
	Users     int
	Files     int
	Downloads int
	Chats     int

	UsersByRefs core.UserRefStats
}

type Auth

type Auth struct {
	UserStore core.UserStore
}

func (*Auth) Auth

func (srv *Auth) Auth(ctx context.Context, info *UserInfo) (*core.User, error)

func (*Auth) SettingsToggleLongIDs

func (srv *Auth) SettingsToggleLongIDs(ctx context.Context, user *core.User) (bool, error)

type ChannelPostInfo

type ChannelPostInfo struct {
	ChatID       int64
	ChatUsername string
	PostID       int
}
func (info *ChannelPostInfo) Link() string

Link returns tg:// deeplink to post

type Chat

type Chat struct {
	Telegram *tgbotapi.BotAPI
	Txier    store.Txier

	File     core.FileStore
	Chat     core.ChatStore
	Download core.DownloadStore
}

func (*Chat) Add

func (srv *Chat) Add(ctx context.Context, user *core.User, identity ChatIdentity) (*FullChat, error)

Add links chat to Share File Bot.

func (*Chat) DisconnectChat

func (srv *Chat) DisconnectChat(
	ctx context.Context,
	user *core.User,
	id core.ChatID,
	leave bool,
) error

DisconnectChat disconnect user linked chat and optionaly leave it.

func (*Chat) GetChat

func (srv *Chat) GetChat(ctx context.Context, user *core.User, id core.ChatID) (*FullChat, error)

func (*Chat) GetChats

func (srv *Chat) GetChats(ctx context.Context, user *core.User) ([]*core.Chat, error)

GetChats returns chats of user

func (*Chat) ProcessChannelPostURIes

func (srv *Chat) ProcessChannelPostURIes(
	ctx context.Context,
	postInfo *ChannelPostInfo,
	uries []string,
) error

ProcessChannelPostURIes called on each channel post and should scan for backlinks to bot.

Flow:

  • resolve chat, if chat is not found finish without error
  • extract bot /start uries
  • query files by public link and restrction chat id
  • update files

func (*Chat) UpdateTitle

func (srv *Chat) UpdateTitle(ctx context.Context, chatID int64, title string) error

type ChatIdentity

type ChatIdentity struct {
	ID       int64
	Username string
}

func NewChatIdentityFromID

func NewChatIdentityFromID(id int64) ChatIdentity

func NewChatIdentityFromUsername

func NewChatIdentityFromUsername(un string) ChatIdentity

type ChatRestrictionStatus

type ChatRestrictionStatus struct {
	Ok   bool
	Chat *core.Chat
	File *core.File
}

type ChatSubRequest

type ChatSubRequest struct {
	FileID core.FileID

	Title    string
	Username string
	JoinLink string
}
func (sub *ChatSubRequest) Link() string

type DownloadResult

type DownloadResult struct {
	File           *core.File
	OwnedFile      *OwnedFile
	ChatSubRequest *ChatSubRequest
}

type File

type File struct {
	File     core.FileStore
	Chat     core.ChatStore
	Telegram *tgbotapi.BotAPI
	Redis    redis.UniversalClient
	Download core.DownloadStore

	IsUsersCanUploadFiles bool
}

func (*File) AddFile

func (srv *File) AddFile(
	ctx context.Context,
	user *core.User,
	in *InputFile,
) (*OwnedFile, error)

func (*File) CheckFileRestrictionsChat

func (srv *File) CheckFileRestrictionsChat(
	ctx context.Context,
	user *core.User,
	id core.FileID,
) (*ChatRestrictionStatus, error)

func (*File) DeleteFile

func (srv *File) DeleteFile(
	ctx context.Context,
	user *core.User,
	id core.FileID,
) error

func (*File) GetFileByID

func (srv *File) GetFileByID(
	ctx context.Context,
	user *core.User,
	id core.FileID,
) (*DownloadResult, error)

func (*File) GetFileByPublicID

func (srv *File) GetFileByPublicID(
	ctx context.Context,
	user *core.User,
	publicID string,
) (*DownloadResult, error)

func (*File) RegisterDownload

func (srv *File) RegisterDownload(ctx context.Context, user *core.User, file *core.File) (*DownloadResult, error)

func (*File) SetChatRestriction

func (srv *File) SetChatRestriction(
	ctx context.Context,
	user *core.User,
	fileID core.FileID,
	chatID core.ChatID,
) (*SetChatRestrictionResult, error)

SetChatRestriction changes chat restriction to specified chat.

type FullChat

type FullChat struct {
	*core.Chat

	// Count of files
	Files int

	// Stats of downloads
	Stats *core.ChatDownloadStats
}

func (*FullChat) GetStats

func (chat *FullChat) GetStats() *core.ChatDownloadStats

type InputFile

type InputFile struct {
	FileID   string
	Caption  string
	Kind     core.Kind
	MIMEType string
	Name     string
	Size     int

	Metadata core.Metadata
}

type OwnedFile

type OwnedFile struct {
	*core.File
	Stats *core.FileDownloadStats
}

type SetChatRestrictionResult

type SetChatRestrictionResult struct {
	Chat    *core.Chat
	File    *core.File
	Disable bool
}

type UserInfo

type UserInfo struct {
	ID           int
	FirstName    string
	LastName     string
	Username     string
	LanguageCode string
	Ref          string
}

Jump to

Keyboard shortcuts

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