discorb 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
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,325 +1,374 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a thread.
6
- # @abstract
7
- #
8
- class ThreadChannel < Channel
9
- # @return [Discorb::Snowflake] The ID of the channel.
10
- # @note This ID is same as the starter message's ID
11
- attr_reader :id
12
- # @return [String] The name of the thread.
13
- attr_reader :name
14
- # @return [Integer] The number of messages in the thread.
15
- # @note This will stop counting at 50.
16
- attr_reader :message_count
17
- # @return [Integer] The number of recipients in the thread.
18
- # @note This will stop counting at 50.
19
- attr_reader :member_count
20
- alias recipient_count member_count
21
- # @return [Integer] The rate limit per user (slowmode) in the thread.
22
- attr_reader :rate_limit_per_user
23
- alias slowmode rate_limit_per_user
24
- # @return [Array<Discorb::ThreadChannel::Member>] The members of the thread.
25
- attr_reader :members
26
- # @return [Time] The time the thread was archived.
27
- # @return [nil] If the thread is not archived.
28
- attr_reader :archived_timestamp
29
- alias archived_at archived_timestamp
30
- # @return [Integer] Auto archive duration in seconds.
31
- attr_reader :auto_archive_duration
32
- alias archive_in auto_archive_duration
33
- # @return [Boolean] Whether the thread is archived or not.
34
- attr_reader :archived
35
- alias archived? archived
36
-
37
- # @!attribute [r] parent
38
- # @macro client_cache
39
- # @return [Discorb::GuildChannel] The parent channel of the thread.
40
- # @!attribute [r] me
41
- # @return [Discorb::ThreadChannel::Member] The bot's member in the thread.
42
- # @return [nil] If the bot is not in the thread.
43
- # @!attribute [r] joined?
44
- # @return [Boolean] Whether the bot is in the thread or not.
45
- # @!attribute [r] guild
46
- # @macro client_cache
47
- # @return [Discorb::Guild] The guild of the thread.
48
- # @!attribute [r] owner
49
- # @macro client_cache
50
- # @macro members_intent
51
- # @return [Discorb::Member] The owner of the thread.
52
-
53
- include Messageable
54
- @channel_type = nil
55
-
56
- #
57
- # Initialize a new thread channel.
58
- # @private
59
- #
60
- # @param [Discorb::Client] client The client.
61
- # @param [Hash] data The data of the thread channel.
62
- # @param [Boolean] no_cache Whether to disable the cache.
63
- #
64
- def initialize(client, data, no_cache: false)
65
- @members = Dictionary.new
66
- super
67
- @client.channels[@id] = self unless no_cache
68
- end
69
-
70
- #
71
- # Edit the thread.
72
- # @async
73
- # @macro edit
74
- #
75
- # @param [String] name The name of the thread.
76
- # @param [Boolean] archived Whether the thread is archived or not.
77
- # @param [Integer] auto_archive_duration The auto archive duration in seconds.
78
- # @param [Integer] archive_in Alias of `auto_archive_duration`.
79
- # @param [Boolean] locked Whether the thread is locked or not.
80
- # @param [String] reason The reason of editing the thread.
81
- #
82
- # @return [Async::Task<self>] The edited thread.
83
- #
84
- # @see #archive
85
- # @see #lock
86
- # @see #unarchive
87
- # @see #unlock
88
- #
89
- def edit(
90
- name: Discorb::Unset,
91
- archived: Discorb::Unset,
92
- auto_archive_duration: Discorb::Unset,
93
- archive_in: Discorb::Unset,
94
- locked: Discorb::Unset,
95
- reason: nil
96
- )
97
- Async do
98
- payload = {}
99
- payload[:name] = name if name != Discorb::Unset
100
- payload[:archived] = archived if archived != Discorb::Unset
101
- auto_archive_duration ||= archive_in
102
- payload[:auto_archive_duration] = auto_archive_duration if auto_archive_duration != Discorb::Unset
103
- payload[:locked] = locked if locked != Discorb::Unset
104
- @client.http.request(Route.new("/channels/#{@id}", "//channels/:channel_id", :patch), payload,
105
- audit_log_reason: reason).wait
106
- self
107
- end
108
- end
109
-
110
- #
111
- # Helper method to archive the thread.
112
- #
113
- # @param [String] reason The reason of archiving the thread.
114
- #
115
- # @return [Async::Task<self>] The archived thread.
116
- #
117
- def archive(reason: nil)
118
- edit(archived: true, reason: reason)
119
- end
120
-
121
- #
122
- # Helper method to lock the thread.
123
- #
124
- # @param [String] reason The reason of locking the thread.
125
- #
126
- # @return [Async::Task<self>] The locked thread.
127
- #
128
- def lock(reason: nil)
129
- edit(archived: true, locked: true, reason: reason)
130
- end
131
-
132
- #
133
- # Helper method to unarchive the thread.
134
- #
135
- # @param [String] reason The reason of unarchiving the thread.
136
- #
137
- # @return [Async::Task<self>] The unarchived thread.
138
- #
139
- def unarchive(reason: nil)
140
- edit(archived: false, reason: reason)
141
- end
142
-
143
- #
144
- # Helper method to unlock the thread.
145
- #
146
- # @param [String] reason The reason of unlocking the thread.
147
- #
148
- # @return [Async::Task<self>] The unlocked thread.
149
- #
150
- # @note This method won't unarchive the thread. Use {#unarchive} instead.
151
- #
152
- def unlock(reason: nil)
153
- edit(archived: !unarchive, locked: false, reason: reason)
154
- end
155
-
156
- def parent
157
- return nil unless @parent_id
158
-
159
- @client.channels[@parent_id]
160
- end
161
-
162
- alias channel parent
163
-
164
- def me
165
- @members[@client.user.id]
166
- end
167
-
168
- def joined?
169
- !!me
170
- end
171
-
172
- def guild
173
- @client.guilds[@guild]
174
- end
175
-
176
- def owner
177
- guild.members[@owner_id]
178
- end
179
-
180
- def inspect
181
- "#<#{self.class} \"##{@name}\" id=#{@id}>"
182
- end
183
-
184
- #
185
- # Add a member to the thread.
186
- #
187
- # @param [Discorb::Member, :me] member The member to add. If `:me` is given, the bot will be added.
188
- #
189
- # @return [Async::Task<void>] The task.
190
- #
191
- def add_member(member = :me)
192
- Async do
193
- if member == :me
194
- @client.http.request(Route.new("/channels/#{@id}/thread-members/@me",
195
- "//channels/:channel_id/thread-members/@me", :post)).wait
196
- else
197
- @client.http.request(Route.new("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}",
198
- "//channels/:channel_id/thread-members/:user_id", :post)).wait
199
- end
200
- end
201
- end
202
-
203
- alias join add_member
204
-
205
- #
206
- # Remove a member from the thread.
207
- #
208
- # @param [Discorb::Member, :me] member The member to remove. If `:me` is given, the bot will be removed.
209
- #
210
- # @return [Async::Task<void>] The task.
211
- #
212
- def remove_member(member = :me)
213
- Async do
214
- if member == :me
215
- @client.http.request(Route.new("/channels/#{@id}/thread-members/@me",
216
- "//channels/:channel_id/thread-members/@me", :delete)).wait
217
- else
218
- @client.http.request(Route.new("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}",
219
- "//channels/:channel_id/thread-members/:user_id", :delete)).wait
220
- end
221
- end
222
- end
223
-
224
- alias leave remove_member
225
-
226
- #
227
- # Fetch members in the thread.
228
- #
229
- # @return [Array<Discorb::ThreadChannel::Member>] The members in the thread.
230
- #
231
- def fetch_members
232
- Async do
233
- _resp, data = @client.http.request(Route.new("/channels/#{@id}/thread-members",
234
- "//channels/:channel_id/thread-members", :get)).wait
235
- data.map { |d| @members[d[:id]] = Member.new(@client, d, @guild_id) }
236
- end
237
- end
238
-
239
- #
240
- # Represents a thread in news channel(aka announcement channel).
241
- #
242
- class News < ThreadChannel
243
- @channel_type = 10
244
- end
245
-
246
- #
247
- # Represents a public thread in text channel.
248
- #
249
- class Public < ThreadChannel
250
- @channel_type = 11
251
- end
252
-
253
- #
254
- # Represents a private thread in text channel.
255
- #
256
- class Private < ThreadChannel
257
- @channel_type = 12
258
- end
259
-
260
- class << self
261
- attr_reader :channel_type
262
- end
263
-
264
- #
265
- # Represents a member in a thread.
266
- #
267
- class Member < DiscordModel
268
- attr_reader :joined_at
269
-
270
- def initialize(client, data, guild_id)
271
- @client = client
272
- @thread_id = data[:id]
273
- @user_id = data[:user_id]
274
- @joined_at = Time.iso8601(data[:join_timestamp])
275
- @guild_id = guild_id
276
- end
277
-
278
- def thread
279
- @client.channels[@thread_id]
280
- end
281
-
282
- def member
283
- @client.guilds[@guild_id].members[@user_id]
284
- end
285
-
286
- def id
287
- @user_id
288
- end
289
-
290
- def user
291
- @client.users[@user_id]
292
- end
293
-
294
- def inspect
295
- "#<#{self.class} id=#{@id.inspect}>"
296
- end
297
- end
298
-
299
- private
300
-
301
- def _set_data(data)
302
- @id = Snowflake.new(data[:id])
303
- @name = data[:name]
304
- @guild_id = data[:guild_id]
305
- @parent_id = data[:parent_id]
306
- @archived = data[:thread_metadata][:archived]
307
- @owner_id = data[:owner_id]
308
- @archived_timestamp =
309
- data[:thread_metadata][:archived_timestamp] && Time.iso8601(data[:thread_metadata][:archived_timestamp])
310
- @auto_archive_duration = data[:thread_metadata][:auto_archive_duration]
311
- @locked = data[:thread_metadata][:locked]
312
- @member_count = data[:member_count]
313
- @message_count = data[:message_count]
314
- if data[:member]
315
- @members[@client.user.id] =
316
- ThreadChannel::Member.new(
317
- @client,
318
- data[:member].merge({ id: data[:id], user_id: @client.user.id }),
319
- @guild_id
320
- )
321
- end
322
- @data.merge!(data)
323
- end
324
- end
325
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a thread.
6
+ # @abstract
7
+ #
8
+ class ThreadChannel < Channel
9
+ # @return [Discorb::Snowflake] The ID of the channel.
10
+ # @note This ID is same as the starter message's ID
11
+ attr_reader :id
12
+ # @return [String] The name of the thread.
13
+ attr_reader :name
14
+ # @return [Integer] The number of messages in the thread.
15
+ # @note This will stop counting at 50.
16
+ attr_reader :message_count
17
+ # @return [Integer] The number of recipients in the thread.
18
+ # @note This will stop counting at 50.
19
+ attr_reader :member_count
20
+ alias recipient_count member_count
21
+ # @return [Integer] The rate limit per user (slowmode) in the thread.
22
+ attr_reader :rate_limit_per_user
23
+ alias slowmode rate_limit_per_user
24
+ # @return [Array<Discorb::ThreadChannel::Member>] The members of the thread.
25
+ attr_reader :members
26
+ # @return [Time] The time the thread was archived.
27
+ # @return [nil] If the thread is not archived.
28
+ attr_reader :archived_timestamp
29
+ alias archived_at archived_timestamp
30
+ # @return [Integer] Auto archive duration in seconds.
31
+ attr_reader :auto_archive_duration
32
+ alias archive_in auto_archive_duration
33
+ # @return [Boolean] Whether the thread is archived or not.
34
+ attr_reader :archived
35
+ alias archived? archived
36
+
37
+ # @!attribute [r] parent
38
+ # @macro client_cache
39
+ # @return [Discorb::GuildChannel] The parent channel of the thread.
40
+ # @!attribute [r] me
41
+ # @return [Discorb::ThreadChannel::Member] The bot's member in the thread.
42
+ # @return [nil] If the bot is not in the thread.
43
+ # @!attribute [r] joined?
44
+ # @return [Boolean] Whether the bot is in the thread or not.
45
+ # @!attribute [r] guild
46
+ # @macro client_cache
47
+ # @return [Discorb::Guild] The guild of the thread.
48
+ # @!attribute [r] owner
49
+ # @macro client_cache
50
+ # @macro members_intent
51
+ # @return [Discorb::Member] The owner of the thread.
52
+
53
+ include Messageable
54
+ @channel_type = nil
55
+
56
+ #
57
+ # Initialize a new thread channel.
58
+ # @private
59
+ #
60
+ # @param [Discorb::Client] client The client.
61
+ # @param [Hash] data The data of the thread channel.
62
+ # @param [Boolean] no_cache Whether to disable the cache.
63
+ #
64
+ def initialize(client, data, no_cache: false)
65
+ @members = Dictionary.new
66
+ super
67
+ @client.channels[@id] = self unless no_cache
68
+ end
69
+
70
+ #
71
+ # Edit the thread.
72
+ # @async
73
+ # @macro edit
74
+ #
75
+ # @param [String] name The name of the thread.
76
+ # @param [Boolean] archived Whether the thread is archived or not.
77
+ # @param [Integer] auto_archive_duration The auto archive duration in seconds.
78
+ # @param [Integer] archive_in Alias of `auto_archive_duration`.
79
+ # @param [Boolean] locked Whether the thread is locked or not.
80
+ # @param [String] reason The reason of editing the thread.
81
+ #
82
+ # @return [Async::Task<self>] The edited thread.
83
+ #
84
+ # @see #archive
85
+ # @see #lock
86
+ # @see #unarchive
87
+ # @see #unlock
88
+ #
89
+ def edit(
90
+ name: Discorb::Unset,
91
+ archived: Discorb::Unset,
92
+ auto_archive_duration: Discorb::Unset,
93
+ archive_in: Discorb::Unset,
94
+ locked: Discorb::Unset,
95
+ reason: nil
96
+ )
97
+ Async do
98
+ payload = {}
99
+ payload[:name] = name if name != Discorb::Unset
100
+ payload[:archived] = archived if archived != Discorb::Unset
101
+ auto_archive_duration ||= archive_in
102
+ payload[
103
+ :auto_archive_duration
104
+ ] = auto_archive_duration if auto_archive_duration != Discorb::Unset
105
+ payload[:locked] = locked if locked != Discorb::Unset
106
+ @client
107
+ .http
108
+ .request(
109
+ Route.new("/channels/#{@id}", "//channels/:channel_id", :patch),
110
+ payload,
111
+ audit_log_reason: reason
112
+ )
113
+ .wait
114
+ self
115
+ end
116
+ end
117
+
118
+ #
119
+ # Helper method to archive the thread.
120
+ #
121
+ # @param [String] reason The reason of archiving the thread.
122
+ #
123
+ # @return [Async::Task<self>] The archived thread.
124
+ #
125
+ def archive(reason: nil)
126
+ edit(archived: true, reason: reason)
127
+ end
128
+
129
+ #
130
+ # Helper method to lock the thread.
131
+ #
132
+ # @param [String] reason The reason of locking the thread.
133
+ #
134
+ # @return [Async::Task<self>] The locked thread.
135
+ #
136
+ def lock(reason: nil)
137
+ edit(archived: true, locked: true, reason: reason)
138
+ end
139
+
140
+ #
141
+ # Helper method to unarchive the thread.
142
+ #
143
+ # @param [String] reason The reason of unarchiving the thread.
144
+ #
145
+ # @return [Async::Task<self>] The unarchived thread.
146
+ #
147
+ def unarchive(reason: nil)
148
+ edit(archived: false, reason: reason)
149
+ end
150
+
151
+ #
152
+ # Helper method to unlock the thread.
153
+ #
154
+ # @param [String] reason The reason of unlocking the thread.
155
+ #
156
+ # @return [Async::Task<self>] The unlocked thread.
157
+ #
158
+ # @note This method won't unarchive the thread. Use {#unarchive} instead.
159
+ #
160
+ def unlock(reason: nil)
161
+ edit(archived: !unarchive, locked: false, reason: reason)
162
+ end
163
+
164
+ def parent
165
+ return nil unless @parent_id
166
+
167
+ @client.channels[@parent_id]
168
+ end
169
+
170
+ alias channel parent
171
+
172
+ def me
173
+ @members[@client.user.id]
174
+ end
175
+
176
+ def joined?
177
+ !!me
178
+ end
179
+
180
+ def guild
181
+ @client.guilds[@guild]
182
+ end
183
+
184
+ def owner
185
+ guild.members[@owner_id]
186
+ end
187
+
188
+ def inspect
189
+ "#<#{self.class} \"##{@name}\" id=#{@id}>"
190
+ end
191
+
192
+ #
193
+ # Add a member to the thread.
194
+ #
195
+ # @param [Discorb::Member, :me] member The member to add. If `:me` is given, the bot will be added.
196
+ #
197
+ # @return [Async::Task<void>] The task.
198
+ #
199
+ def add_member(member = :me)
200
+ Async do
201
+ if member == :me
202
+ @client
203
+ .http
204
+ .request(
205
+ Route.new(
206
+ "/channels/#{@id}/thread-members/@me",
207
+ "//channels/:channel_id/thread-members/@me",
208
+ :post
209
+ )
210
+ )
211
+ .wait
212
+ else
213
+ @client
214
+ .http
215
+ .request(
216
+ Route.new(
217
+ "/channels/#{@id}/thread-members/#{Utils.try(member, :id)}",
218
+ "//channels/:channel_id/thread-members/:user_id",
219
+ :post
220
+ )
221
+ )
222
+ .wait
223
+ end
224
+ end
225
+ end
226
+
227
+ alias join add_member
228
+
229
+ #
230
+ # Remove a member from the thread.
231
+ #
232
+ # @param [Discorb::Member, :me] member The member to remove. If `:me` is given, the bot will be removed.
233
+ #
234
+ # @return [Async::Task<void>] The task.
235
+ #
236
+ def remove_member(member = :me)
237
+ Async do
238
+ if member == :me
239
+ @client
240
+ .http
241
+ .request(
242
+ Route.new(
243
+ "/channels/#{@id}/thread-members/@me",
244
+ "//channels/:channel_id/thread-members/@me",
245
+ :delete
246
+ )
247
+ )
248
+ .wait
249
+ else
250
+ @client
251
+ .http
252
+ .request(
253
+ Route.new(
254
+ "/channels/#{@id}/thread-members/#{Utils.try(member, :id)}",
255
+ "//channels/:channel_id/thread-members/:user_id",
256
+ :delete
257
+ )
258
+ )
259
+ .wait
260
+ end
261
+ end
262
+ end
263
+
264
+ alias leave remove_member
265
+
266
+ #
267
+ # Fetch members in the thread.
268
+ #
269
+ # @return [Array<Discorb::ThreadChannel::Member>] The members in the thread.
270
+ #
271
+ def fetch_members
272
+ Async do
273
+ _resp, data =
274
+ @client
275
+ .http
276
+ .request(
277
+ Route.new(
278
+ "/channels/#{@id}/thread-members",
279
+ "//channels/:channel_id/thread-members",
280
+ :get
281
+ )
282
+ )
283
+ .wait
284
+ data.map { |d| @members[d[:id]] = Member.new(@client, d, @guild_id) }
285
+ end
286
+ end
287
+
288
+ #
289
+ # Represents a thread in news channel(aka announcement channel).
290
+ #
291
+ class News < ThreadChannel
292
+ @channel_type = 10
293
+ end
294
+
295
+ #
296
+ # Represents a public thread in text channel.
297
+ #
298
+ class Public < ThreadChannel
299
+ @channel_type = 11
300
+ end
301
+
302
+ #
303
+ # Represents a private thread in text channel.
304
+ #
305
+ class Private < ThreadChannel
306
+ @channel_type = 12
307
+ end
308
+
309
+ class << self
310
+ attr_reader :channel_type
311
+ end
312
+
313
+ #
314
+ # Represents a member in a thread.
315
+ #
316
+ class Member < DiscordModel
317
+ attr_reader :joined_at
318
+
319
+ def initialize(client, data, guild_id)
320
+ @client = client
321
+ @thread_id = data[:id]
322
+ @user_id = data[:user_id]
323
+ @joined_at = Time.iso8601(data[:join_timestamp])
324
+ @guild_id = guild_id
325
+ end
326
+
327
+ def thread
328
+ @client.channels[@thread_id]
329
+ end
330
+
331
+ def member
332
+ @client.guilds[@guild_id].members[@user_id]
333
+ end
334
+
335
+ def id
336
+ @user_id
337
+ end
338
+
339
+ def user
340
+ @client.users[@user_id]
341
+ end
342
+
343
+ def inspect
344
+ "#<#{self.class} id=#{@id.inspect}>"
345
+ end
346
+ end
347
+
348
+ private
349
+
350
+ def _set_data(data)
351
+ @id = Snowflake.new(data[:id])
352
+ @name = data[:name]
353
+ @guild_id = data[:guild_id]
354
+ @parent_id = data[:parent_id]
355
+ @archived = data[:thread_metadata][:archived]
356
+ @owner_id = data[:owner_id]
357
+ @archived_timestamp =
358
+ data[:thread_metadata][:archived_timestamp] &&
359
+ Time.iso8601(data[:thread_metadata][:archived_timestamp])
360
+ @auto_archive_duration = data[:thread_metadata][:auto_archive_duration]
361
+ @locked = data[:thread_metadata][:locked]
362
+ @member_count = data[:member_count]
363
+ @message_count = data[:message_count]
364
+ if data[:member]
365
+ @members[@client.user.id] = ThreadChannel::Member.new(
366
+ @client,
367
+ data[:member].merge({ id: data[:id], user_id: @client.user.id }),
368
+ @guild_id
369
+ )
370
+ end
371
+ @data.merge!(data)
372
+ end
373
+ end
374
+ end