discorb 0.19.0 → 0.20.0

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