-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmembers.go
More file actions
96 lines (80 loc) · 3.03 KB
/
Copy pathmembers.go
File metadata and controls
96 lines (80 loc) · 3.03 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
package tgot
import (
"github.com/karalef/tgot/api"
"github.com/karalef/tgot/api/tg"
)
// WithChatMember returns ChatMember with provided chat id and user id.
// It copies the context but resets the context parameters.
func WithChatMember(ctx BaseContext, chatID ChatID, userID tg.ID) *ChatMember {
d := api.NewData().SetID("user_id", userID)
chatID.setChatID(d)
return &ChatMember{context: ctx.ctx().with(d), chat: chatID, user: userID}
}
// ChatMember provides methods for working with chat members.
type ChatMember struct {
*context
user tg.ID
chat ChatID
}
// WithName implements Context.
func (m *ChatMember) WithName(name string) *ChatMember {
return &ChatMember{
context: m.context.child(name),
user: m.user,
chat: m.chat,
}
}
// Chat returns the Chat of the ChatMember.
func (m *ChatMember) Chat() *Chat { return WithChatID(m, m.chat) }
// User returns the User of the ChatMember.
func (m *ChatMember) User() *User { return WithUser(m, m.user) }
// GetUserBoosts returns the list of boosts added to a chat by a user.
func (m *ChatMember) GetBoosts() (*tg.UserChatBoosts, error) {
return method[*tg.UserChatBoosts](m, "getUserChatBoosts")
}
// Get returns information about a member of a chat.
func (m *ChatMember) Get() (*tg.ChatMember, error) {
return method[*tg.ChatMember](m, "getChatMember")
}
// ApproveJoinRequest approves a chat join request.
func (m *ChatMember) ApproveJoinRequest() error {
return m.method("approveChatJoinRequest")
}
// DeclineJoinRequest declines a chat join request.
func (m *ChatMember) DeclineJoinRequest() error {
return m.method("declineChatJoinRequest")
}
// SetTitle sets a custom title for an administrator in a supergroup promoted by
// the bot.
func (m *ChatMember) SetTitle(title string) error {
return m.method("setChatAdministratorCustomTitle", api.NewData().
Set("custom_title", title))
}
// RestrictChatMember contains parameters for restrictChatMember method.
type RestrictChatMember struct {
Permissions tg.ChatPermissions `tg:"permissions"`
IndependentPermissions bool `tg:"use_independent_chat_permissions"`
Until int64 `tg:"until_date"`
}
// Restrict restricts a user in a supergroup.
func (m *ChatMember) Restrict(r RestrictChatMember) error {
return m.method("restrictChatMember", api.NewDataFrom(r))
}
// Promote promotes or demotes a user in a supergroup or a channel.
func (m *ChatMember) Promote(rights tg.ChatAdministratorRights) error {
return m.method("promoteChatMember", api.NewData().
AddObject(rights, "json"))
}
// Ban bans a user in a group, a supergroup or a channel.
func (m *ChatMember) Ban(revokeMessages bool, until ...int64) error {
d := api.NewData().SetBool("revoke_messages", revokeMessages)
if len(until) > 0 {
d.SetInt64("until_date", until[0], true)
}
return m.method("banChatMember", d)
}
// Unban unbans a previously banned user in a supergroup or channel.
func (m *ChatMember) Unban(onlyIfBanned bool) error {
return m.method("unbanChatMember", api.NewData().
SetBool("only_if_banned", onlyIfBanned))
}