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,281 +1,305 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a state of user in voice channel.
6
- #
7
- class VoiceState < DiscordModel
8
- # @return [Discorb::Member] The member associated with this voice state.
9
- attr_reader :member
10
- # @return [Discorb::Snowflake] The ID of the guild this voice state is for.
11
- attr_reader :session_id
12
- # @return [Time] The time at which the user requested to speak.
13
- attr_reader :request_to_speak_timestamp
14
- # @return [Boolean] Whether the user is deafened.
15
- attr_reader :self_deaf
16
- alias self_deaf? self_deaf
17
- # @return [Boolean] Whether the user is muted.
18
- attr_reader :self_mute
19
- alias self_mute? self_mute
20
- # @return [Boolean] Whether the user is streaming.
21
- attr_reader :self_stream
22
- alias stream? self_stream
23
- alias live? stream?
24
- # @return [Boolean] Whether the user is video-enabled.
25
- attr_reader :self_video
26
- alias video? self_video
27
- # @return [Boolean] Whether the user is suppressed. (Is at audience)
28
- attr_reader :suppress
29
- alias suppress? suppress
30
-
31
- # @!attribute [r] deaf?
32
- # @return [Boolean] Whether the user is deafened.
33
- # @!attribute [r] mute?
34
- # @return [Boolean] Whether the user is muted.
35
- # @!attribute [r] server_deaf?
36
- # @return [Boolean] Whether the user is deafened on the server.
37
- # @!attribute [r] server_mute?
38
- # @return [Boolean] Whether the user is muted on the server.
39
- # @!attribute [r] guild
40
- # @macro client_cache
41
- # @return [Discorb::Guild] The guild this voice state is for.
42
- # @!attribute [r] channel
43
- # @macro client_cache
44
- # @return [Discorb::Channel] The channel this voice state is for.
45
- # @!attribute [r] user
46
- # @macro client_cache
47
- # @return [Discorb::User] The user this voice state is for.
48
-
49
- #
50
- # Initialize a new voice state.
51
- # @private
52
- #
53
- # @param [Discorb::Client] client The client this voice state belongs to.
54
- # @param [Hash] data The data of the voice state.
55
- #
56
- def initialize(client, data)
57
- @client = client
58
- _set_data(data)
59
- end
60
-
61
- def deaf?
62
- @deaf || @self_deaf
63
- end
64
-
65
- def mute?
66
- @mute || @self_mute
67
- end
68
-
69
- def server_deaf?
70
- @deaf
71
- end
72
-
73
- def server_mute?
74
- @mute
75
- end
76
-
77
- def guild
78
- @guild_id && @client.guilds[@guild_id]
79
- end
80
-
81
- def channel
82
- @channel_id && @client.channels[@channel_id]
83
- end
84
-
85
- def user
86
- @client.users[@user_id]
87
- end
88
-
89
- private
90
-
91
- def _set_data(data)
92
- @data = data
93
- @guild_id = data[:guild_id]
94
- @channel_id = data[:channel_id]
95
- @user_id = data[:user_id]
96
- unless guild.nil?
97
- @member = if data.key?(:member)
98
- guild.members[data[:user_id]] || Member.new(@client, @guild_id, data[:member][:user], data[:member])
99
- else
100
- guild.members[data[:user_id]]
101
- end
102
- end
103
- @session_id = data[:session_id]
104
- @deaf = data[:deaf]
105
- @mute = data[:mute]
106
- @self_deaf = data[:self_deaf]
107
- @self_mute = data[:self_mute]
108
- @self_stream = data[:self_stream]
109
- @self_video = data[:self_video]
110
- @suppress = data[:suppress]
111
- @request_to_speak_timestamp = data[:request_to_speak_timestamp] && Time.iso8601(data[:request_to_speak_timestamp])
112
- end
113
- end
114
-
115
- #
116
- # Represents a stage instance of a voice state.
117
- #
118
- class StageInstance < DiscordModel
119
- # @return [Discorb::Snowflake] The ID of the guild this voice state is for.
120
- attr_reader :id
121
- # @return [String] The topic of the stage instance.
122
- attr_reader :topic
123
- # @return [:public, :guild_only] The privacy level of the stage instance.
124
- attr_reader :privacy_level
125
-
126
- # @!attribute [r] guild
127
- # @macro client_cache
128
- # @return [Discorb::Guild] The guild this voice state is for.
129
- # @!attribute [r] channel
130
- # @macro client_cache
131
- # @return [Discorb::Channel] The channel this voice state is for.
132
- # @!attribute [r] discoverable?
133
- # @return [Boolean] Whether the stage instance is discoverable.
134
- # @!attribute [r] public?
135
- # @return [Boolean] Whether the stage instance is public.
136
- # @!attribute [r] guild_only?
137
- # @return [Boolean] Whether the stage instance is guild-only.
138
-
139
- @privacy_level = {
140
- 1 => :public,
141
- 2 => :guild_only,
142
- }
143
-
144
- #
145
- # Initialize a new instance of the StageInstance class.
146
- # @private
147
- #
148
- # @param [Discorb::Client] client The client.
149
- # @param [Hash] data The data of the stage instance.
150
- # @param [Boolean] no_cache Whether to disable caching.
151
- #
152
- def initialize(client, data, no_cache: false)
153
- @client = client
154
- @data = data
155
- _set_data(data)
156
- channel.stage_instances[@id] = self unless no_cache
157
- end
158
-
159
- def guild
160
- @client.guilds[@data[:guild_id]]
161
- end
162
-
163
- def channel
164
- @client.channels[@data[:channel_id]]
165
- end
166
-
167
- def discoverable?
168
- !@discoverable_disabled
169
- end
170
-
171
- def public?
172
- @privacy_level == :public
173
- end
174
-
175
- def guild_only?
176
- @privacy_level == :guild_only
177
- end
178
-
179
- def inspect
180
- "#<#{self.class} topic=#{@topic.inspect}>"
181
- end
182
-
183
- #
184
- # Edits the stage instance.
185
- # @async
186
- # @macro edit
187
- #
188
- # @param [String] topic The new topic of the stage instance.
189
- # @param [:public, :guild_only] privacy_level The new privacy level of the stage instance.
190
- # @param [String] reason The reason for editing the stage instance.
191
- #
192
- # @return [Async::Task<void>] The task.
193
- #
194
- def edit(topic: Discorb::Unset, privacy_level: Discorb::Unset, reason: nil)
195
- Async do
196
- payload = {}
197
- payload[:topic] = topic if topic != Discorb::Unset
198
- payload[:privacy_level] = PRIVACY_LEVEL.key(privacy_level) if privacy_level != Discorb::Unset
199
- @client.http.request(
200
- Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:channel_id",
201
- :patch), payload, audit_log_reason: reason,
202
- ).wait
203
- self
204
- end
205
- end
206
-
207
- alias modify edit
208
-
209
- #
210
- # Deletes the stage instance.
211
- #
212
- # @param [String] reason The reason for deleting the stage instance.
213
- #
214
- # @return [Async::Task<void>] The task.
215
- #
216
- def delete(reason: nil)
217
- Async do
218
- @client.http.request(
219
- Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:stage_instance_id",
220
- :delete), {}, audit_log_reason: reason,
221
- ).wait
222
- self
223
- end
224
- end
225
-
226
- alias destroy delete
227
- alias end delete
228
-
229
- private
230
-
231
- def _set_data(data)
232
- @id = Snowflake.new(data[:id])
233
- @guild_id = Snowflake.new(data[:guild_id])
234
- @channel_id = Snowflake.new(data[:channel_id])
235
- @topic = data[:topic]
236
- @privacy_level = PRIVACY_LEVEL[data[:privacy_level]]
237
- @discoverable_disabled = data[:discoverable_disabled]
238
- end
239
-
240
- class << self
241
- attr_reader :privacy_level
242
- end
243
- end
244
-
245
- #
246
- # Represents a voice region.
247
- #
248
- class VoiceRegion < DiscordModel
249
- # @return [Discorb::Snowflake] The ID of the voice region.
250
- attr_reader :id
251
- # @return [String] The name of the voice region.
252
- attr_reader :name
253
- # @return [Boolean] Whether the voice region is VIP.
254
- attr_reader :vip
255
- alias vip? vip
256
- # @return [Boolean] Whether the voice region is optimal.
257
- attr_reader :optimal
258
- alias optimal? optimal
259
- # @return [Boolean] Whether the voice region is deprecated.
260
- attr_reader :deprecated
261
- alias deprecated? deprecated
262
- # @return [Boolean] Whether the voice region is custom.
263
- attr_reader :custom
264
- alias custom? custom
265
-
266
- #
267
- # Initialize a new instance of the VoiceRegion class.
268
- # @private
269
- #
270
- # @param [Hash] data The data of the voice region.
271
- #
272
- def initialize(data)
273
- @id = data[:id]
274
- @name = data[:name]
275
- @vip = data[:vip]
276
- @optimal = data[:optimal]
277
- @deprecated = data[:deprecated]
278
- @custom = data[:custom]
279
- end
280
- end
281
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a state of user in voice channel.
6
+ #
7
+ class VoiceState < DiscordModel
8
+ # @return [Discorb::Member] The member associated with this voice state.
9
+ attr_reader :member
10
+ # @return [Discorb::Snowflake] The ID of the guild this voice state is for.
11
+ attr_reader :session_id
12
+ # @return [Time] The time at which the user requested to speak.
13
+ attr_reader :request_to_speak_timestamp
14
+ # @return [Boolean] Whether the user is deafened.
15
+ attr_reader :self_deaf
16
+ alias self_deaf? self_deaf
17
+ # @return [Boolean] Whether the user is muted.
18
+ attr_reader :self_mute
19
+ alias self_mute? self_mute
20
+ # @return [Boolean] Whether the user is streaming.
21
+ attr_reader :self_stream
22
+ alias stream? self_stream
23
+ alias live? stream?
24
+ # @return [Boolean] Whether the user is video-enabled.
25
+ attr_reader :self_video
26
+ alias video? self_video
27
+ # @return [Boolean] Whether the user is suppressed. (Is at audience)
28
+ attr_reader :suppress
29
+ alias suppress? suppress
30
+
31
+ # @!attribute [r] deaf?
32
+ # @return [Boolean] Whether the user is deafened.
33
+ # @!attribute [r] mute?
34
+ # @return [Boolean] Whether the user is muted.
35
+ # @!attribute [r] server_deaf?
36
+ # @return [Boolean] Whether the user is deafened on the server.
37
+ # @!attribute [r] server_mute?
38
+ # @return [Boolean] Whether the user is muted on the server.
39
+ # @!attribute [r] guild
40
+ # @macro client_cache
41
+ # @return [Discorb::Guild] The guild this voice state is for.
42
+ # @!attribute [r] channel
43
+ # @macro client_cache
44
+ # @return [Discorb::Channel] The channel this voice state is for.
45
+ # @!attribute [r] user
46
+ # @macro client_cache
47
+ # @return [Discorb::User] The user this voice state is for.
48
+
49
+ #
50
+ # Initialize a new voice state.
51
+ # @private
52
+ #
53
+ # @param [Discorb::Client] client The client this voice state belongs to.
54
+ # @param [Hash] data The data of the voice state.
55
+ #
56
+ def initialize(client, data)
57
+ @client = client
58
+ _set_data(data)
59
+ end
60
+
61
+ def deaf?
62
+ @deaf || @self_deaf
63
+ end
64
+
65
+ def mute?
66
+ @mute || @self_mute
67
+ end
68
+
69
+ def server_deaf?
70
+ @deaf
71
+ end
72
+
73
+ def server_mute?
74
+ @mute
75
+ end
76
+
77
+ def guild
78
+ @guild_id && @client.guilds[@guild_id]
79
+ end
80
+
81
+ def channel
82
+ @channel_id && @client.channels[@channel_id]
83
+ end
84
+
85
+ def user
86
+ @client.users[@user_id]
87
+ end
88
+
89
+ private
90
+
91
+ def _set_data(data)
92
+ @data = data
93
+ @guild_id = data[:guild_id]
94
+ @channel_id = data[:channel_id]
95
+ @user_id = data[:user_id]
96
+ unless guild.nil?
97
+ @member =
98
+ if data.key?(:member)
99
+ guild.members[data[:user_id]] ||
100
+ Member.new(
101
+ @client,
102
+ @guild_id,
103
+ data[:member][:user],
104
+ data[:member]
105
+ )
106
+ else
107
+ guild.members[data[:user_id]]
108
+ end
109
+ end
110
+ @session_id = data[:session_id]
111
+ @deaf = data[:deaf]
112
+ @mute = data[:mute]
113
+ @self_deaf = data[:self_deaf]
114
+ @self_mute = data[:self_mute]
115
+ @self_stream = data[:self_stream]
116
+ @self_video = data[:self_video]
117
+ @suppress = data[:suppress]
118
+ @request_to_speak_timestamp =
119
+ data[:request_to_speak_timestamp] &&
120
+ Time.iso8601(data[:request_to_speak_timestamp])
121
+ end
122
+ end
123
+
124
+ #
125
+ # Represents a stage instance of a voice state.
126
+ #
127
+ class StageInstance < DiscordModel
128
+ # @return [Discorb::Snowflake] The ID of the guild this voice state is for.
129
+ attr_reader :id
130
+ # @return [String] The topic of the stage instance.
131
+ attr_reader :topic
132
+ # @return [:public, :guild_only] The privacy level of the stage instance.
133
+ attr_reader :privacy_level
134
+
135
+ # @!attribute [r] guild
136
+ # @macro client_cache
137
+ # @return [Discorb::Guild] The guild this voice state is for.
138
+ # @!attribute [r] channel
139
+ # @macro client_cache
140
+ # @return [Discorb::Channel] The channel this voice state is for.
141
+ # @!attribute [r] discoverable?
142
+ # @return [Boolean] Whether the stage instance is discoverable.
143
+ # @!attribute [r] public?
144
+ # @return [Boolean] Whether the stage instance is public.
145
+ # @!attribute [r] guild_only?
146
+ # @return [Boolean] Whether the stage instance is guild-only.
147
+
148
+ @privacy_level = { 1 => :public, 2 => :guild_only }
149
+
150
+ #
151
+ # Initialize a new instance of the StageInstance class.
152
+ # @private
153
+ #
154
+ # @param [Discorb::Client] client The client.
155
+ # @param [Hash] data The data of the stage instance.
156
+ # @param [Boolean] no_cache Whether to disable caching.
157
+ #
158
+ def initialize(client, data, no_cache: false)
159
+ @client = client
160
+ @data = data
161
+ _set_data(data)
162
+ channel.stage_instances[@id] = self unless no_cache
163
+ end
164
+
165
+ def guild
166
+ @client.guilds[@data[:guild_id]]
167
+ end
168
+
169
+ def channel
170
+ @client.channels[@data[:channel_id]]
171
+ end
172
+
173
+ def discoverable?
174
+ !@discoverable_disabled
175
+ end
176
+
177
+ def public?
178
+ @privacy_level == :public
179
+ end
180
+
181
+ def guild_only?
182
+ @privacy_level == :guild_only
183
+ end
184
+
185
+ def inspect
186
+ "#<#{self.class} topic=#{@topic.inspect}>"
187
+ end
188
+
189
+ #
190
+ # Edits the stage instance.
191
+ # @async
192
+ # @macro edit
193
+ #
194
+ # @param [String] topic The new topic of the stage instance.
195
+ # @param [:public, :guild_only] privacy_level The new privacy level of the stage instance.
196
+ # @param [String] reason The reason for editing the stage instance.
197
+ #
198
+ # @return [Async::Task<void>] The task.
199
+ #
200
+ def edit(topic: Discorb::Unset, privacy_level: Discorb::Unset, reason: nil)
201
+ Async do
202
+ payload = {}
203
+ payload[:topic] = topic if topic != Discorb::Unset
204
+ payload[:privacy_level] = PRIVACY_LEVEL.key(
205
+ privacy_level
206
+ ) if privacy_level != Discorb::Unset
207
+ @client
208
+ .http
209
+ .request(
210
+ Route.new(
211
+ "/stage-instances/#{@channel_id}",
212
+ "//stage-instances/:channel_id",
213
+ :patch
214
+ ),
215
+ payload,
216
+ audit_log_reason: reason
217
+ )
218
+ .wait
219
+ self
220
+ end
221
+ end
222
+
223
+ alias modify edit
224
+
225
+ #
226
+ # Deletes the stage instance.
227
+ #
228
+ # @param [String] reason The reason for deleting the stage instance.
229
+ #
230
+ # @return [Async::Task<void>] The task.
231
+ #
232
+ def delete(reason: nil)
233
+ Async do
234
+ @client
235
+ .http
236
+ .request(
237
+ Route.new(
238
+ "/stage-instances/#{@channel_id}",
239
+ "//stage-instances/:stage_instance_id",
240
+ :delete
241
+ ),
242
+ {},
243
+ audit_log_reason: reason
244
+ )
245
+ .wait
246
+ self
247
+ end
248
+ end
249
+
250
+ alias destroy delete
251
+ alias end delete
252
+
253
+ private
254
+
255
+ def _set_data(data)
256
+ @id = Snowflake.new(data[:id])
257
+ @guild_id = Snowflake.new(data[:guild_id])
258
+ @channel_id = Snowflake.new(data[:channel_id])
259
+ @topic = data[:topic]
260
+ @privacy_level = PRIVACY_LEVEL[data[:privacy_level]]
261
+ @discoverable_disabled = data[:discoverable_disabled]
262
+ end
263
+
264
+ class << self
265
+ attr_reader :privacy_level
266
+ end
267
+ end
268
+
269
+ #
270
+ # Represents a voice region.
271
+ #
272
+ class VoiceRegion < DiscordModel
273
+ # @return [Discorb::Snowflake] The ID of the voice region.
274
+ attr_reader :id
275
+ # @return [String] The name of the voice region.
276
+ attr_reader :name
277
+ # @return [Boolean] Whether the voice region is VIP.
278
+ attr_reader :vip
279
+ alias vip? vip
280
+ # @return [Boolean] Whether the voice region is optimal.
281
+ attr_reader :optimal
282
+ alias optimal? optimal
283
+ # @return [Boolean] Whether the voice region is deprecated.
284
+ attr_reader :deprecated
285
+ alias deprecated? deprecated
286
+ # @return [Boolean] Whether the voice region is custom.
287
+ attr_reader :custom
288
+ alias custom? custom
289
+
290
+ #
291
+ # Initialize a new instance of the VoiceRegion class.
292
+ # @private
293
+ #
294
+ # @param [Hash] data The data of the voice region.
295
+ #
296
+ def initialize(data)
297
+ @id = data[:id]
298
+ @name = data[:name]
299
+ @vip = data[:vip]
300
+ @optimal = data[:optimal]
301
+ @deprecated = data[:deprecated]
302
+ @custom = data[:custom]
303
+ end
304
+ end
305
+ end