forked from AmarnathCJD/gogram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
participant.go
executable file
·207 lines (174 loc) · 4.43 KB
/
participant.go
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Copyright (c) 2024 RoseLoverX
package telegram
import "errors"
type ParticipantUpdate struct {
Client *Client
OriginalUpdate *UpdateChannelParticipant
Channel *Channel
User *UserObj
Actor *UserObj
Old ChannelParticipant
New ChannelParticipant
Invite ExportedChatInvite
Date int32
}
func (pu *ParticipantUpdate) ChannelID() int64 {
if pu.Channel != nil {
return pu.Channel.ID
}
return 0
}
func (pu *ParticipantUpdate) UserID() int64 {
if pu.User != nil {
return pu.User.ID
}
return 0
}
func (pu *ParticipantUpdate) ActorID() int64 {
if pu.Actor != nil {
return pu.Actor.ID
}
return 0
}
func (pu *ParticipantUpdate) IsAdded() bool {
if pu.Old != nil && pu.New != nil {
if _, ok := pu.Old.(*ChannelParticipantBanned); ok {
if _, ok := pu.New.(*ChannelParticipantObj); ok {
return true
}
}
if _, ok := pu.Old.(*ChannelParticipantLeft); ok {
if _, ok := pu.New.(*ChannelParticipantObj); ok {
return true
}
}
}
return false
}
func (pu *ParticipantUpdate) IsLeft() bool {
return pu.New == nil
}
func (pu *ParticipantUpdate) IsJoined() bool {
if pu.Old != nil && pu.New != nil {
if _, ok := pu.Old.(*ChannelParticipantLeft); ok {
if _, ok := pu.New.(*ChannelParticipantObj); ok {
return true
}
}
if _, ok := pu.Old.(*ChannelParticipantBanned); ok {
if _, ok := pu.New.(*ChannelParticipantObj); ok {
return true
}
}
}
return false
}
func (pu *ParticipantUpdate) IsBanned() bool {
if pu.Old != nil && pu.New != nil {
if _, ok := pu.Old.(*ChannelParticipantObj); ok {
if _, ok := pu.New.(*ChannelParticipantBanned); ok {
return true
}
}
}
return false
}
func (pu *ParticipantUpdate) IsKicked() bool {
if pu.Old != nil && pu.New != nil {
if _, ok := pu.Old.(*ChannelParticipantObj); ok {
if _, ok := pu.New.(*ChannelParticipantLeft); ok {
return true
}
}
}
return false
}
func (pu *ParticipantUpdate) IsPromoted() bool {
if pu.Old != nil && pu.New != nil {
if _, ok := pu.Old.(*ChannelParticipantObj); ok {
if _, ok := pu.New.(*ChannelParticipantAdmin); ok {
return true
}
}
if _, ok := pu.Old.(*ChannelParticipantBanned); ok {
if _, ok := pu.New.(*ChannelParticipantAdmin); ok {
return true
}
}
}
return false
}
func (pu *ParticipantUpdate) IsDemoted() bool {
if pu.Old != nil && pu.New != nil {
if _, ok := pu.Old.(*ChannelParticipantAdmin); ok {
if _, ok := pu.New.(*ChannelParticipantObj); ok {
return true
}
if _, ok := pu.New.(*ChannelParticipantBanned); ok {
return true
}
}
}
return false
}
func (pu *ParticipantUpdate) Marshal(nointent ...bool) string {
return pu.Client.JSON(pu.OriginalUpdate, nointent)
}
func (pu *ParticipantUpdate) Ban() (bool, error) {
if pu.User == nil {
return false, errors.New("ParticipantUpdate.Ban: User is nil")
}
if pu.Channel == nil {
return false, errors.New("ParticipantUpdate.Ban: Channel is nil")
}
_, err := pu.Client.EditBanned(pu.Channel, pu.User, &BannedOptions{
Ban: true,
})
return err == nil, err
}
func (pu *ParticipantUpdate) Unban() (bool, error) {
if pu.User == nil {
return false, errors.New("ParticipantUpdate.Unban: User is nil")
}
if pu.Channel == nil {
return false, errors.New("ParticipantUpdate.Unban: Channel is nil")
}
_, err := pu.Client.EditBanned(pu.Channel, pu.User, &BannedOptions{
Unban: true,
})
return err == nil, err
}
func (pu *ParticipantUpdate) Kick() (bool, error) {
if pu.User == nil {
return false, errors.New("ParticipantUpdate.Kick: User is nil")
}
if pu.Channel == nil {
return false, errors.New("ParticipantUpdate.Kick: Channel is nil")
}
_, err := pu.Client.KickParticipant(pu.Channel, pu.User)
return err == nil, err
}
func (pu *ParticipantUpdate) Promote() (bool, error) {
if pu.User == nil {
return false, errors.New("ParticipantUpdate.Promote: User is nil")
}
if pu.Channel == nil {
return false, errors.New("ParticipantUpdate.Promote: Channel is nil")
}
_, err := pu.Client.EditAdmin(pu.Channel, pu.User, &AdminOptions{
IsAdmin: true,
})
return err == nil, err
}
func (pu *ParticipantUpdate) Demote() (bool, error) {
if pu.User == nil {
return false, errors.New("ParticipantUpdate.Demote: User is nil")
}
if pu.Channel == nil {
return false, errors.New("ParticipantUpdate.Demote: Channel is nil")
}
_, err := pu.Client.EditAdmin(pu.Channel, pu.User, &AdminOptions{
IsAdmin: false,
})
return err == nil, err
}