Documentation ¶
Overview ¶
Package query contains generic pagination helpers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is common struct to create query builders.
Example (DownloadSaved) ¶
package main import ( "context" "os" "os/signal" "github.com/gotd/td/telegram" "github.com/gotd/td/telegram/downloader" "github.com/gotd/td/telegram/query" "github.com/gotd/td/telegram/query/messages" "github.com/gotd/td/tg" ) func main() { ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() client, err := telegram.ClientFromEnvironment(telegram.Options{}) if err != nil { panic(err) } // This example downloads all attachments (photo, video, docs, etc.) // from SavedMessages dialog. if err := client.Run(ctx, func(ctx context.Context) error { raw := tg.NewClient(client) d := downloader.NewDownloader() return query.NewQuery(raw).Messages().GetHistory(&tg.InputPeerSelf{}).ForEach(ctx, func(ctx context.Context, elem messages.Elem) error { f, ok := elem.File() if !ok { return nil } _, err := d.Download(raw, f.Location).ToPath(ctx, f.Name) return err }) }); err != nil { panic(err) } }
Output:
Example (GetAdmins) ¶
package main import ( "context" "fmt" "os" "os/signal" "github.com/gotd/td/telegram" "github.com/gotd/td/telegram/query" "github.com/gotd/td/telegram/query/channels/participants" "github.com/gotd/td/telegram/query/dialogs" "github.com/gotd/td/tg" ) func main() { ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() client, err := telegram.ClientFromEnvironment(telegram.Options{}) if err != nil { panic(err) } // This example iterates over all channels and prints admins. if err := client.Run(ctx, func(ctx context.Context) error { raw := tg.NewClient(client) cb := func(ctx context.Context, dlg dialogs.Elem) error { // Skip deleted dialogs. if _, empty := dlg.Peer.(*tg.InputPeerEmpty); empty { return nil } q, ok := dlg.Participants(raw) if !ok { return nil } return q.ForEach(ctx, func(ctx context.Context, elem participants.Elem) error { user, admin, ok := elem.Admin() if !ok { return nil } fmt.Println(user.Username, "admin") if admin.AdminRights.ChangeInfo { fmt.Println("\t+ ChangeInfo") } if admin.AdminRights.PostMessages { fmt.Println("\t+ PostMessages") } if admin.AdminRights.EditMessages { fmt.Println("\t+ EditMessages") } if admin.AdminRights.DeleteMessages { fmt.Println("\t+ DeleteMessages") } if admin.AdminRights.BanUsers { fmt.Println("\t+ BanUsers") } if admin.AdminRights.InviteUsers { fmt.Println("\t+ InviteUsers") } if admin.AdminRights.PinMessages { fmt.Println("\t+ PinMessages") } if admin.AdminRights.AddAdmins { fmt.Println("\t+ AddAdmins") } if admin.AdminRights.Anonymous { fmt.Println("\t+ Anonymous") } if admin.AdminRights.ManageCall { fmt.Println("\t+ ManageCall") } if admin.AdminRights.Other { fmt.Println("\t+ Other") } return nil }) } return query.NewQuery(raw).Dialogs().GetDialogs().ForEach(ctx, cb) }); err != nil { panic(err) } }
Output:
Example (IterAllMessages) ¶
package main import ( "context" "fmt" "os" "os/signal" "github.com/gotd/td/telegram" "github.com/gotd/td/telegram/query" "github.com/gotd/td/telegram/query/dialogs" "github.com/gotd/td/telegram/query/messages" "github.com/gotd/td/tg" ) func main() { ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() client, err := telegram.ClientFromEnvironment(telegram.Options{}) if err != nil { panic(err) } // This example iterates over all messages of all dialogs of user and prints them. if err := client.Run(ctx, func(ctx context.Context) error { raw := tg.NewClient(client) cb := func(ctx context.Context, dlg dialogs.Elem) error { // Skip deleted dialogs. if _, empty := dlg.Peer.(*tg.InputPeerEmpty); empty { return nil } return dlg.Messages(raw).ForEach(ctx, func(ctx context.Context, elem messages.Elem) error { msg, ok := elem.Msg.(*tg.Message) if !ok { return nil } fmt.Println(msg.Message) return nil }) } return query.NewQuery(raw).Dialogs().GetDialogs().ForEach(ctx, cb) }); err != nil { panic(err) } }
Output:
func (*Query) Blocked ¶
func (q *Query) Blocked() *blocked.QueryBuilder
Blocked creates blocked.QueryBuilder
func (*Query) Dialogs ¶
func (q *Query) Dialogs() *dialogs.QueryBuilder
Dialogs creates dialogs.QueryBuilder
func (*Query) Featured ¶
func (q *Query) Featured() *featured.QueryBuilder
Featured creates featured.QueryBuilder
func (*Query) Messages ¶
func (q *Query) Messages() *messages.QueryBuilder
Messages creates messages.QueryBuilder
func (*Query) Participants ¶
func (q *Query) Participants() *participants.QueryBuilder
Participants creates participants.QueryBuilder
func (*Query) Photos ¶
func (q *Query) Photos() *photos.QueryBuilder
Photos creates photos.QueryBuilder
Directories ¶
Path | Synopsis |
---|---|
Package cached contains cached query helpers.
|
Package cached contains cached query helpers. |
channels
|
|
participants
Package participants contains channel participants iteration helper.
|
Package participants contains channel participants iteration helper. |
contacts
|
|
blocked
Package blocked contains blocked contacts iteration helper.
|
Package blocked contains blocked contacts iteration helper. |
Package dialogs contains dialog iteration helper.
|
Package dialogs contains dialog iteration helper. |
Package hasher contains Telegram pagination hash implementation.
|
Package hasher contains Telegram pagination hash implementation. |
internal
|
|
genutil
Package genutil is a utility package for query helpers codegeneration.
|
Package genutil is a utility package for query helpers codegeneration. |
Package messages contains message iteration helper.
|
Package messages contains message iteration helper. |
stickers/featured
Package featured contains featured stickers iteration helper.
|
Package featured contains featured stickers iteration helper. |
Package photos contains photos iteration helper.
|
Package photos contains photos iteration helper. |
Click to show internal directories.
Click to hide internal directories.