discorb 0.19.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +10 -0
- data/Rakefile +482 -454
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -398
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -266
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -621
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -804
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -336
- data/lib/discorb/interaction/root.rb +271 -257
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -291
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/application.rbs +2 -0
- data/sig/discorb/automod.rbs +10 -1
- data/sig/discorb/guild.rbs +2 -0
- data/sig/discorb/message.rbs +2 -0
- data/sig/discorb/user.rbs +22 -20
- metadata +2 -2
data/lib/discorb/member.rb
CHANGED
@@ -1,311 +1,344 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a member of a guild.
|
6
|
-
#
|
7
|
-
class Member < User
|
8
|
-
# @return [Time] The time the member boosted the guild.
|
9
|
-
attr_reader :premium_since
|
10
|
-
# @return [String] The nickname of the member.
|
11
|
-
# @return [nil] If the member has no nickname.
|
12
|
-
attr_reader :nick
|
13
|
-
# @return [Time] The time the member joined the guild.
|
14
|
-
attr_reader :joined_at
|
15
|
-
# @return [Discorb::Asset] The custom avatar of the member.
|
16
|
-
# @return [nil] If the member has no custom avatar.
|
17
|
-
attr_reader :custom_avatar
|
18
|
-
# @return [Discorb::Asset] The display avatar of the member.
|
19
|
-
attr_reader :display_avatar
|
20
|
-
# @return [Boolean] Whether the member is muted.
|
21
|
-
attr_reader :mute
|
22
|
-
alias mute? mute
|
23
|
-
# @return [Boolean] Whether the member is deafened.
|
24
|
-
attr_reader :deaf
|
25
|
-
alias deaf? deaf
|
26
|
-
# @return [Boolean] Whether the member is pending (Not passed member screening).
|
27
|
-
attr_reader :pending
|
28
|
-
alias pending? pending
|
29
|
-
|
30
|
-
# @!attribute [r] name
|
31
|
-
# @return [String] The display name of the member.
|
32
|
-
# @!attribute [r] mention
|
33
|
-
# @return [String] The mention of the member.
|
34
|
-
# @!attribute [r] voice_state
|
35
|
-
# @return [Discorb::VoiceState] The voice state of the member.
|
36
|
-
# @!attribute [r] roles
|
37
|
-
# @macro client_cache
|
38
|
-
# @return [Array<Discorb::Role>] The roles of the member.
|
39
|
-
# @!attribute [r] guild
|
40
|
-
# @macro client_cache
|
41
|
-
# @return [Discorb::Guild] The guild the member is in.
|
42
|
-
# @!attribute [r] hoisted_role
|
43
|
-
# @macro client_cache
|
44
|
-
# @return [Discorb::Role] The hoisted role of the member.
|
45
|
-
# @return [nil] If the member has no hoisted role.
|
46
|
-
# @!attribute [r] hoisted?
|
47
|
-
# @return [Boolean] Whether the member has a hoisted role.
|
48
|
-
# @!attribute [r] permissions
|
49
|
-
# @return [Discorb::Permission] The permissions of the member.
|
50
|
-
# @!attribute [r] presence
|
51
|
-
# @macro client_cache
|
52
|
-
# @return [Discorb::Presence] The presence of the member.
|
53
|
-
# @!attribute [r] activity
|
54
|
-
# @macro client_cache
|
55
|
-
# @return [Discorb::Presence::Activity] The activity of the member. It's from the {#presence}.
|
56
|
-
# @!attribute [r] activities
|
57
|
-
# @macro client_cache
|
58
|
-
# @return [Array<Discorb::Presence::Activity>] The activities of the member. It's from the {#presence}.
|
59
|
-
# @!attribute [r] status
|
60
|
-
# @macro client_cache
|
61
|
-
# @return [Symbol] The status of the member. It's from the {#presence}.
|
62
|
-
# @!attribute [r] owner?
|
63
|
-
# @return [Boolean] Whether the member is the owner of the guild.
|
64
|
-
|
65
|
-
#
|
66
|
-
# Initialize a new instance of the member.
|
67
|
-
# @private
|
68
|
-
#
|
69
|
-
# @param [Discorb::Client] client The client.
|
70
|
-
# @param [Discorb::Snowflake] guild_id The ID of the guild.
|
71
|
-
# @param [Hash] user_data The data of the user.
|
72
|
-
# @param [Hash] member_data The data of the member.
|
73
|
-
#
|
74
|
-
def initialize(client, guild_id, user_data, member_data)
|
75
|
-
@guild_id = guild_id
|
76
|
-
@client = client
|
77
|
-
@_member_data = {}
|
78
|
-
@data = {}
|
79
|
-
_set_data(user_data, member_data)
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# Format the member to `Username#Discriminator` style.
|
84
|
-
#
|
85
|
-
# @return [String] The formatted member.
|
86
|
-
#
|
87
|
-
def to_s
|
88
|
-
"#{username}##{discriminator}"
|
89
|
-
end
|
90
|
-
|
91
|
-
def name
|
92
|
-
@nick || @username
|
93
|
-
end
|
94
|
-
|
95
|
-
def mention
|
96
|
-
"<@#{@nick.nil? ? "" : "!"}#{@id}>"
|
97
|
-
end
|
98
|
-
|
99
|
-
def voice_state
|
100
|
-
guild.voice_states[@id]
|
101
|
-
end
|
102
|
-
|
103
|
-
def owner?
|
104
|
-
guild.owner_id == @id
|
105
|
-
end
|
106
|
-
|
107
|
-
def guild
|
108
|
-
@client.guilds[@guild_id]
|
109
|
-
end
|
110
|
-
|
111
|
-
def roles
|
112
|
-
@role_ids.map { |r| guild.roles[r] }.sort_by(&:position).reverse +
|
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
|
-
# @param [
|
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
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
#
|
264
|
-
#
|
265
|
-
# @
|
266
|
-
#
|
267
|
-
#
|
268
|
-
# @
|
269
|
-
#
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
#
|
279
|
-
#
|
280
|
-
#
|
281
|
-
#
|
282
|
-
#
|
283
|
-
#
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a member of a guild.
|
6
|
+
#
|
7
|
+
class Member < User
|
8
|
+
# @return [Time] The time the member boosted the guild.
|
9
|
+
attr_reader :premium_since
|
10
|
+
# @return [String] The nickname of the member.
|
11
|
+
# @return [nil] If the member has no nickname.
|
12
|
+
attr_reader :nick
|
13
|
+
# @return [Time] The time the member joined the guild.
|
14
|
+
attr_reader :joined_at
|
15
|
+
# @return [Discorb::Asset] The custom avatar of the member.
|
16
|
+
# @return [nil] If the member has no custom avatar.
|
17
|
+
attr_reader :custom_avatar
|
18
|
+
# @return [Discorb::Asset] The display avatar of the member.
|
19
|
+
attr_reader :display_avatar
|
20
|
+
# @return [Boolean] Whether the member is muted.
|
21
|
+
attr_reader :mute
|
22
|
+
alias mute? mute
|
23
|
+
# @return [Boolean] Whether the member is deafened.
|
24
|
+
attr_reader :deaf
|
25
|
+
alias deaf? deaf
|
26
|
+
# @return [Boolean] Whether the member is pending (Not passed member screening).
|
27
|
+
attr_reader :pending
|
28
|
+
alias pending? pending
|
29
|
+
|
30
|
+
# @!attribute [r] name
|
31
|
+
# @return [String] The display name of the member.
|
32
|
+
# @!attribute [r] mention
|
33
|
+
# @return [String] The mention of the member.
|
34
|
+
# @!attribute [r] voice_state
|
35
|
+
# @return [Discorb::VoiceState] The voice state of the member.
|
36
|
+
# @!attribute [r] roles
|
37
|
+
# @macro client_cache
|
38
|
+
# @return [Array<Discorb::Role>] The roles of the member.
|
39
|
+
# @!attribute [r] guild
|
40
|
+
# @macro client_cache
|
41
|
+
# @return [Discorb::Guild] The guild the member is in.
|
42
|
+
# @!attribute [r] hoisted_role
|
43
|
+
# @macro client_cache
|
44
|
+
# @return [Discorb::Role] The hoisted role of the member.
|
45
|
+
# @return [nil] If the member has no hoisted role.
|
46
|
+
# @!attribute [r] hoisted?
|
47
|
+
# @return [Boolean] Whether the member has a hoisted role.
|
48
|
+
# @!attribute [r] permissions
|
49
|
+
# @return [Discorb::Permission] The permissions of the member.
|
50
|
+
# @!attribute [r] presence
|
51
|
+
# @macro client_cache
|
52
|
+
# @return [Discorb::Presence] The presence of the member.
|
53
|
+
# @!attribute [r] activity
|
54
|
+
# @macro client_cache
|
55
|
+
# @return [Discorb::Presence::Activity] The activity of the member. It's from the {#presence}.
|
56
|
+
# @!attribute [r] activities
|
57
|
+
# @macro client_cache
|
58
|
+
# @return [Array<Discorb::Presence::Activity>] The activities of the member. It's from the {#presence}.
|
59
|
+
# @!attribute [r] status
|
60
|
+
# @macro client_cache
|
61
|
+
# @return [Symbol] The status of the member. It's from the {#presence}.
|
62
|
+
# @!attribute [r] owner?
|
63
|
+
# @return [Boolean] Whether the member is the owner of the guild.
|
64
|
+
|
65
|
+
#
|
66
|
+
# Initialize a new instance of the member.
|
67
|
+
# @private
|
68
|
+
#
|
69
|
+
# @param [Discorb::Client] client The client.
|
70
|
+
# @param [Discorb::Snowflake] guild_id The ID of the guild.
|
71
|
+
# @param [Hash] user_data The data of the user.
|
72
|
+
# @param [Hash] member_data The data of the member.
|
73
|
+
#
|
74
|
+
def initialize(client, guild_id, user_data, member_data)
|
75
|
+
@guild_id = guild_id
|
76
|
+
@client = client
|
77
|
+
@_member_data = {}
|
78
|
+
@data = {}
|
79
|
+
_set_data(user_data, member_data)
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Format the member to `Username#Discriminator` style.
|
84
|
+
#
|
85
|
+
# @return [String] The formatted member.
|
86
|
+
#
|
87
|
+
def to_s
|
88
|
+
"#{username}##{discriminator}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def name
|
92
|
+
@nick || @username
|
93
|
+
end
|
94
|
+
|
95
|
+
def mention
|
96
|
+
"<@#{@nick.nil? ? "" : "!"}#{@id}>"
|
97
|
+
end
|
98
|
+
|
99
|
+
def voice_state
|
100
|
+
guild.voice_states[@id]
|
101
|
+
end
|
102
|
+
|
103
|
+
def owner?
|
104
|
+
guild.owner_id == @id
|
105
|
+
end
|
106
|
+
|
107
|
+
def guild
|
108
|
+
@client.guilds[@guild_id]
|
109
|
+
end
|
110
|
+
|
111
|
+
def roles
|
112
|
+
@role_ids.map { |r| guild.roles[r] }.sort_by(&:position).reverse +
|
113
|
+
[guild.roles[guild.id]]
|
114
|
+
end
|
115
|
+
|
116
|
+
def permissions
|
117
|
+
return Permission.new((1 << 38) - 1) if owner?
|
118
|
+
|
119
|
+
roles.map(&:permissions).sum(Permission.new(0))
|
120
|
+
end
|
121
|
+
|
122
|
+
alias guild_permissions permissions
|
123
|
+
|
124
|
+
def hoisted_role
|
125
|
+
@hoisted_role_id && guild.roles[@hoisted_role_id]
|
126
|
+
end
|
127
|
+
|
128
|
+
def hoisted?
|
129
|
+
!@hoisted_role_id.nil?
|
130
|
+
end
|
131
|
+
|
132
|
+
def presence
|
133
|
+
guild.presences[@id]
|
134
|
+
end
|
135
|
+
|
136
|
+
def activity
|
137
|
+
presence&.activity
|
138
|
+
end
|
139
|
+
|
140
|
+
def activities
|
141
|
+
presence&.activities
|
142
|
+
end
|
143
|
+
|
144
|
+
def status
|
145
|
+
presence&.status
|
146
|
+
end
|
147
|
+
|
148
|
+
def inspect
|
149
|
+
"#<#{self.class} #{self} id=#{@id}>"
|
150
|
+
end
|
151
|
+
|
152
|
+
#
|
153
|
+
# Add a role to the member.
|
154
|
+
# @async
|
155
|
+
#
|
156
|
+
# @param [Discorb::Role] role The role to add.
|
157
|
+
# @param [String] reason The reason for the action.
|
158
|
+
#
|
159
|
+
# @return [Async::Task<void>] The task.
|
160
|
+
#
|
161
|
+
def add_role(role, reason: nil)
|
162
|
+
Async do
|
163
|
+
@client
|
164
|
+
.http
|
165
|
+
.request(
|
166
|
+
Route.new(
|
167
|
+
"/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}",
|
168
|
+
"//guilds/:guild_id/members/:user_id/roles/:role_id",
|
169
|
+
:put
|
170
|
+
),
|
171
|
+
nil,
|
172
|
+
audit_log_reason: reason
|
173
|
+
)
|
174
|
+
.wait
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# Remove a role to the member.
|
180
|
+
# @async
|
181
|
+
#
|
182
|
+
# @param [Discorb::Role] role The role to add.
|
183
|
+
# @param [String] reason The reason for the action.
|
184
|
+
#
|
185
|
+
# @return [Async::Task<void>] The task.
|
186
|
+
#
|
187
|
+
def remove_role(role, reason: nil)
|
188
|
+
Async do
|
189
|
+
@client
|
190
|
+
.http
|
191
|
+
.request(
|
192
|
+
Route.new(
|
193
|
+
"/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}",
|
194
|
+
"//guilds/:guild_id/members/:user_id/roles/:role_id",
|
195
|
+
:delete
|
196
|
+
),
|
197
|
+
{},
|
198
|
+
audit_log_reason: reason
|
199
|
+
)
|
200
|
+
.wait
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# Edit the member.
|
206
|
+
# @async
|
207
|
+
# @macro edit
|
208
|
+
#
|
209
|
+
# @param [String] nick The nickname of the member.
|
210
|
+
# @param [Discorb::Role] role The roles of the member.
|
211
|
+
# @param [Boolean] mute Whether the member is muted.
|
212
|
+
# @param [Boolean] deaf Whether the member is deafened.
|
213
|
+
# @param [Discorb::StageChannel] channel The channel the member is moved to.
|
214
|
+
# @param [Time, nil] communication_disabled_until The time the member is timed out. Set to `nil` to end the timeout.
|
215
|
+
# @param [Time, nil] timeout_until Alias of `communication_disabled_until`.
|
216
|
+
# @param [String] reason The reason for the action.
|
217
|
+
#
|
218
|
+
# @return [Async::Task<void>] The task.
|
219
|
+
#
|
220
|
+
def edit(
|
221
|
+
nick: Discorb::Unset,
|
222
|
+
role: Discorb::Unset,
|
223
|
+
mute: Discorb::Unset,
|
224
|
+
deaf: Discorb::Unset,
|
225
|
+
channel: Discorb::Unset,
|
226
|
+
communication_disabled_until: Discorb::Unset,
|
227
|
+
timeout_until: Discorb::Unset,
|
228
|
+
reason: nil
|
229
|
+
)
|
230
|
+
Async do
|
231
|
+
payload = {}
|
232
|
+
payload[:nick] = nick if nick != Discorb::Unset
|
233
|
+
payload[:roles] = role if role != Discorb::Unset
|
234
|
+
payload[:mute] = mute if mute != Discorb::Unset
|
235
|
+
payload[:deaf] = deaf if deaf != Discorb::Unset
|
236
|
+
communication_disabled_until = timeout_until if timeout_until !=
|
237
|
+
Discorb::Unset
|
238
|
+
if communication_disabled_until != Discorb::Unset
|
239
|
+
payload[
|
240
|
+
:communication_disabled_until
|
241
|
+
] = communication_disabled_until&.iso8601
|
242
|
+
end
|
243
|
+
payload[:channel_id] = channel&.id if channel != Discorb::Unset
|
244
|
+
@client
|
245
|
+
.http
|
246
|
+
.request(
|
247
|
+
Route.new(
|
248
|
+
"/guilds/#{@guild_id}/members/#{@id}",
|
249
|
+
"//guilds/:guild_id/members/:user_id",
|
250
|
+
:patch
|
251
|
+
),
|
252
|
+
payload,
|
253
|
+
audit_log_reason: reason
|
254
|
+
)
|
255
|
+
.wait
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
alias modify edit
|
260
|
+
|
261
|
+
#
|
262
|
+
# Timeout the member.
|
263
|
+
# @async
|
264
|
+
#
|
265
|
+
# @param [Time] time The time until the member is timeout.
|
266
|
+
# @param [String] reason The reason for the action.
|
267
|
+
#
|
268
|
+
# @return [Async::Task<void>] The task.
|
269
|
+
#
|
270
|
+
def timeout(time, reason: nil)
|
271
|
+
edit(communication_disabled_until: time, reason: reason)
|
272
|
+
end
|
273
|
+
|
274
|
+
alias disable_communication timeout
|
275
|
+
|
276
|
+
#
|
277
|
+
# Kick the member.
|
278
|
+
# @async
|
279
|
+
#
|
280
|
+
# @param [String] reason The reason for the action.
|
281
|
+
#
|
282
|
+
# @return [Async::Task<void>] The task.
|
283
|
+
#
|
284
|
+
def kick(reason: nil)
|
285
|
+
Async { guild.kick_member(self, reason: reason).wait }
|
286
|
+
end
|
287
|
+
|
288
|
+
#
|
289
|
+
# Ban the member.
|
290
|
+
# @async
|
291
|
+
#
|
292
|
+
# @param [Integer] delete_message_days The number of days to delete messages.
|
293
|
+
# @param [String] reason The reason for the action.
|
294
|
+
#
|
295
|
+
# @return [Async::Task<Discorb::Guild::Ban>] The ban.
|
296
|
+
#
|
297
|
+
def ban(delete_message_days: 0, reason: nil)
|
298
|
+
Async do
|
299
|
+
guild.ban_member(
|
300
|
+
self,
|
301
|
+
delete_message_days: delete_message_days,
|
302
|
+
reason: reason
|
303
|
+
).wait
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
#
|
308
|
+
# Checks if the member can manage the given role.
|
309
|
+
#
|
310
|
+
# @param [Discorb::Role] role The role.
|
311
|
+
#
|
312
|
+
# @return [Boolean] `true` if the member can manage the role.
|
313
|
+
#
|
314
|
+
def can_manage?(role)
|
315
|
+
return true if owner?
|
316
|
+
|
317
|
+
top_role = roles.max_by(&:position)
|
318
|
+
top_role.position > role.position
|
319
|
+
end
|
320
|
+
|
321
|
+
private
|
322
|
+
|
323
|
+
def _set_data(user_data, member_data)
|
324
|
+
user_data ||= member_data[:user]
|
325
|
+
@role_ids = member_data[:roles]
|
326
|
+
@premium_since =
|
327
|
+
member_data[:premium_since] && Time.iso8601(member_data[:premium_since])
|
328
|
+
@pending = member_data[:pending]
|
329
|
+
@nick = member_data[:nick]
|
330
|
+
@mute = member_data[:mute]
|
331
|
+
@joined_at =
|
332
|
+
member_data[:joined_at] && Time.iso8601(member_data[:joined_at])
|
333
|
+
@hoisted_role_id = member_data[:hoisted_role]
|
334
|
+
@deaf = member_data[:deaf]
|
335
|
+
@custom_avatar =
|
336
|
+
member_data[:avatar] && Asset.new(self, member_data[:avatar])
|
337
|
+
super(user_data)
|
338
|
+
@display_avatar = @custom_avatar || @avatar
|
339
|
+
@client.guilds[@guild_id].members[@id] = self unless @guild_id.nil? ||
|
340
|
+
@client.guilds[@guild_id].nil?
|
341
|
+
@_member_data.update(member_data)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|