-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.go
More file actions
127 lines (109 loc) · 4.41 KB
/
Copy pathusers.go
File metadata and controls
127 lines (109 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package tgot
import (
"github.com/karalef/tgot/api"
"github.com/karalef/tgot/api/tg"
)
// WithUser creates a new User from context and user id.
// It copies the context but resets the context parameters.
func WithUser(ctx BaseContext, userID tg.ID) *User {
return &User{
context: ctx.ctx().with(api.NewData().SetID("user_id", userID)),
id: userID,
}
}
var _ Context[*User] = &User{}
// Users contains methods for working with user.
type User struct {
*context
id tg.ID
}
// WithName implements Context.
func (u *User) WithName(name string) *User {
return &User{
context: u.context.child(name),
id: u.id,
}
}
// WithChat returns ChatMember with provided chat id.
func (u *User) WithChat(chatID ChatID) *ChatMember {
return WithChatMember(u, chatID, u.id)
}
// GetPhotos returns a list of profile pictures for a user.
func (u *User) GetPhotos() (*tg.UserProfilePhotos, error) {
return method[*tg.UserProfilePhotos](u, "getUserProfilePhotos")
}
// SetEmojiStatus changes the emoji status for a given user that previously
// allowed the bot to manage their emoji status via the Mini App method
// [requestEmojiStatusAccess].
func (u *User) SetEmojiStatus(id string, expires int64) error {
return u.method("setUserEmojiStatus", api.NewData().
Set("emoji_status_custom_emoji_id", id).
SetInt64("emoji_status_expiration_date", expires))
}
// RefundStarPayment refunds a successful payment in Telegram Stars.
func (u *User) RefundStarPayment(chargeID string) error {
return u.method("refundStarPayment", api.NewData().
Set("telegram_payment_charge_id", chargeID))
}
// EditStarSubscription cancels or re-enables extension of a subscription paid
// in Telegram Stars.
func (u *User) EditStarSubscription(chargeID string, isCancelled bool) error {
return u.method("editUserStarSubscription", api.NewData().
Set("telegram_payment_charge_id", chargeID).
SetBool("is_canceled", isCancelled))
}
// UploadStickerFile uploads a .PNG file with a sticker for later use
// in createNewStickerSet and addStickerToSet methods.
func (u *User) UploadStickerFile(
sticker *tg.InputFile,
format tg.StickerFormat,
) (*tg.File, error) {
return method[*tg.File](u, "uploadStickerFile", api.NewData().
SetFile("sticker", sticker).
Set("sticker_format", string(format)))
}
// PreparedInlineMessage is used to save prepared inline message.
type PreparedInlineMessage struct {
Result tg.InlineQueryResulter `tg:"result"`
AllowUserChats bool `tg:"allow_user_chats"`
AllowBotChats bool `tg:"allow_bot_chats"`
AllowGroupChats bool `tg:"allow_group_chats"`
AllowChannelChats bool `tg:"allow_channel_chats"`
}
// SavePreparedInlineMessage stores a message that can be sent by a user of a
// Mini App.
func (u *User) SavePreparedInlineMessage(
p PreparedInlineMessage,
) (*tg.PreparedInlineMessage, error) {
d := api.NewDataFrom(p)
return method[*tg.PreparedInlineMessage](u, "savePreparedInlineMessage", d)
}
// Verify verifies a user on behalf of the organization which is represented by
// the bot.
func (u *User) Verify(desc string) error {
return u.method("verifyUser", api.NewData().Set("custom_description", desc))
}
// RemoveVerification removes verification from a user who is currently
// verified on behalf of the organization represented by the bot.
func (u *User) RemoveVerification() error {
return u.method("removeUserVerification")
}
// Premium is used in [User.GiftPremium] method.
type Premium struct {
MonthCount uint `tg:"month_count"` // 3/6/12
StarCount uint `tg:"star_count"` // 1000/1500/2500
Text string `tg:"text"`
ParseMode tg.ParseMode `tg:"text_parse_mode"`
Entities []tg.MessageEntity `tg:"text_entities"`
}
// GiftPremium gifts a Telegram Premium subscription to the given user.
func (u *User) GiftPremium(p Premium) error {
return u.method("giftPremiumSubscription", api.NewDataFrom(p))
}
// SetPassportDataErrors informs a user that some of the Telegram Passport
// elements they provided contains errors.The user will not be able to re-submit
// their Passport to you until the errors are fixed.
func (u *User) SetPassportDataErrors(errs []tg.PassportElementError) error {
return u.method("setPassportDataErrors", api.NewData().
SetJSON("errors", errs))
}