-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathemoji_status.go
More file actions
61 lines (47 loc) · 1.38 KB
/
Copy pathemoji_status.go
File metadata and controls
61 lines (47 loc) · 1.38 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
package botapi
import (
"context"
"strconv"
"github.com/gotd/td/tg"
)
// EmojiStatusOption configures a SetUserEmojiStatus call.
type EmojiStatusOption func(*emojiStatusConfig)
type emojiStatusConfig struct {
until int
}
// WithEmojiStatusExpiration sets the Unix time when the emoji status will
// expire. By default the status does not expire.
func WithEmojiStatusExpiration(unixTime int) EmojiStatusOption {
return func(c *emojiStatusConfig) { c.until = unixTime }
}
// SetUserEmojiStatus sets the emoji status of a user that previously allowed the
// bot to manage it. An empty customEmojiID removes the current emoji status.
func (b *Bot) SetUserEmojiStatus(ctx context.Context, userID int64, customEmojiID string, opts ...EmojiStatusOption) error {
var cfg emojiStatusConfig
for _, o := range opts {
o(&cfg)
}
user, err := b.resolveInputUser(ctx, userID)
if err != nil {
return err
}
var status tg.EmojiStatusClass = &tg.EmojiStatusEmpty{}
if customEmojiID != "" {
id, err := strconv.ParseInt(customEmojiID, 10, 64)
if err != nil {
return errInvalidCustomEmojiID()
}
s := &tg.EmojiStatus{DocumentID: id}
if cfg.until != 0 {
s.SetUntil(cfg.until)
}
status = s
}
if _, err := b.raw.BotsUpdateUserEmojiStatus(ctx, &tg.BotsUpdateUserEmojiStatusRequest{
UserID: user,
EmojiStatus: status,
}); err != nil {
return asAPIError(err)
}
return nil
}