discorb 0.17.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +1 -3
  3. data/.github/workflows/validate.yml +21 -0
  4. data/Changelog.md +25 -0
  5. data/Gemfile +6 -0
  6. data/README.md +2 -1
  7. data/Rakefile +205 -98
  8. data/Steepfile +30 -0
  9. data/docs/application_command.md +1 -0
  10. data/docs/events.md +44 -8
  11. data/docs/tutorial.md +7 -7
  12. data/docs/voice_events.md +8 -8
  13. data/examples/commands/message.rb +12 -7
  14. data/examples/commands/permission.rb +2 -1
  15. data/examples/commands/slash.rb +23 -19
  16. data/examples/commands/user.rb +15 -12
  17. data/examples/components/authorization_button.rb +2 -1
  18. data/examples/components/select_menu.rb +4 -1
  19. data/examples/extension/main.rb +1 -0
  20. data/examples/extension/message_expander.rb +1 -0
  21. data/examples/sig/commands/message.rbs +5 -0
  22. data/examples/simple/eval.rb +1 -0
  23. data/examples/simple/ping_pong.rb +1 -0
  24. data/examples/simple/rolepanel.rb +16 -5
  25. data/examples/simple/shard.rb +2 -1
  26. data/examples/simple/wait_for_message.rb +3 -0
  27. data/exe/discorb +3 -3
  28. data/lib/discorb/allowed_mentions.rb +1 -1
  29. data/lib/discorb/app_command/command.rb +16 -13
  30. data/lib/discorb/app_command/handler.rb +21 -6
  31. data/lib/discorb/audit_logs.rb +6 -2
  32. data/lib/discorb/automod.rb +269 -0
  33. data/lib/discorb/channel/guild.rb +5 -4
  34. data/lib/discorb/channel/stage.rb +1 -1
  35. data/lib/discorb/channel/text.rb +14 -23
  36. data/lib/discorb/channel/thread.rb +15 -11
  37. data/lib/discorb/client.rb +15 -15
  38. data/lib/discorb/color.rb +37 -60
  39. data/lib/discorb/common.rb +1 -1
  40. data/lib/discorb/dictionary.rb +1 -1
  41. data/lib/discorb/embed.rb +5 -4
  42. data/lib/discorb/emoji.rb +4 -4
  43. data/lib/discorb/event.rb +2 -2
  44. data/lib/discorb/exe/about.rb +1 -1
  45. data/lib/discorb/exe/new.rb +1 -5
  46. data/lib/discorb/extension.rb +0 -4
  47. data/lib/discorb/flag.rb +2 -2
  48. data/lib/discorb/gateway.rb +38 -589
  49. data/lib/discorb/gateway_events.rb +638 -0
  50. data/lib/discorb/guild.rb +138 -19
  51. data/lib/discorb/guild_template.rb +3 -3
  52. data/lib/discorb/http.rb +47 -25
  53. data/lib/discorb/integration.rb +2 -2
  54. data/lib/discorb/intents.rb +27 -18
  55. data/lib/discorb/interaction/command.rb +14 -10
  56. data/lib/discorb/interaction/response.rb +150 -84
  57. data/lib/discorb/interaction/root.rb +139 -0
  58. data/lib/discorb/invite.rb +1 -1
  59. data/lib/discorb/member.rb +3 -3
  60. data/lib/discorb/message.rb +17 -15
  61. data/lib/discorb/message_meta.rb +2 -3
  62. data/lib/discorb/modules.rb +5 -4
  63. data/lib/discorb/permission.rb +3 -1
  64. data/lib/discorb/presence.rb +4 -2
  65. data/lib/discorb/reaction.rb +2 -2
  66. data/lib/discorb/role.rb +3 -3
  67. data/lib/discorb/shard.rb +1 -1
  68. data/lib/discorb/sticker.rb +5 -5
  69. data/lib/discorb/user.rb +2 -2
  70. data/lib/discorb/voice_state.rb +8 -8
  71. data/lib/discorb/webhook.rb +20 -11
  72. data/lib/discorb.rb +2 -2
  73. data/rbs_collection.lock.yaml +88 -96
  74. data/rbs_collection.yaml +21 -17
  75. data/sig/async.rbs +11 -5
  76. data/sig/discorb/activity.rbs +24 -0
  77. data/sig/discorb/allowed_mentions.rbs +45 -0
  78. data/sig/discorb/app_command/base.rbs +288 -0
  79. data/sig/discorb/app_command/handler.rbs +171 -0
  80. data/sig/discorb/application.rbs +146 -0
  81. data/sig/discorb/asset.rbs +34 -0
  82. data/sig/discorb/attachment.rbs +99 -0
  83. data/sig/discorb/audit_log.rbs +238 -0
  84. data/sig/discorb/automod.rbs +145 -0
  85. data/sig/discorb/avatar.rbs +27 -0
  86. data/sig/discorb/channel/base.rbs +186 -0
  87. data/sig/discorb/channel/category.rbs +57 -0
  88. data/sig/discorb/channel/container.rbs +33 -0
  89. data/sig/discorb/channel/dm.rbs +14 -0
  90. data/sig/discorb/channel/news.rbs +20 -0
  91. data/sig/discorb/channel/stage.rbs +81 -0
  92. data/sig/discorb/channel/text.rbs +158 -0
  93. data/sig/discorb/channel/thread.rbs +196 -0
  94. data/sig/discorb/channel/voice.rbs +43 -0
  95. data/sig/discorb/client.rbs +2496 -0
  96. data/sig/discorb/color.rbs +148 -0
  97. data/sig/discorb/component/base.rbs +29 -0
  98. data/sig/discorb/component/button.rbs +67 -0
  99. data/sig/discorb/component/select_menu.rbs +111 -0
  100. data/sig/discorb/component/text_input.rbs +70 -0
  101. data/sig/discorb/connectable.rbs +8 -0
  102. data/sig/discorb/custom_emoji.rbs +94 -0
  103. data/sig/discorb/dictionary.rbs +87 -0
  104. data/sig/discorb/discord_model.rbs +17 -0
  105. data/sig/discorb/embed.rbs +286 -0
  106. data/sig/discorb/emoji.rbs +14 -0
  107. data/sig/discorb/error.rbs +73 -0
  108. data/sig/discorb/event_handler.rbs +28 -0
  109. data/sig/discorb/extension.rbs +1735 -0
  110. data/sig/discorb/flag.rbs +74 -0
  111. data/sig/discorb/gateway.rbs +486 -0
  112. data/sig/discorb/guild.rbs +872 -0
  113. data/sig/discorb/guild_template.rbs +174 -0
  114. data/sig/discorb/http.rbs +150 -0
  115. data/sig/discorb/image.rbs +22 -0
  116. data/sig/discorb/integration.rbs +118 -0
  117. data/sig/discorb/intents.rbs +98 -0
  118. data/sig/discorb/interaction/autocomplete.rbs +9 -0
  119. data/sig/discorb/interaction/base.rbs +102 -0
  120. data/sig/discorb/interaction/command.rbs +66 -0
  121. data/sig/discorb/interaction/message_component.rbs +139 -0
  122. data/sig/discorb/interaction/modal.rbs +49 -0
  123. data/sig/discorb/interaction/responder.rbs +157 -0
  124. data/sig/discorb/invite.rbs +86 -0
  125. data/sig/discorb/member.rbs +189 -0
  126. data/sig/discorb/message.rbs +474 -0
  127. data/sig/discorb/messageable.rbs +150 -0
  128. data/sig/discorb/partial_emoji.rbs +38 -0
  129. data/sig/discorb/permissions.rbs +156 -0
  130. data/sig/discorb/presence.rbs +239 -0
  131. data/sig/discorb/reaction.rbs +37 -0
  132. data/sig/discorb/role.rbs +151 -0
  133. data/sig/discorb/scheduled_event.rbs +149 -0
  134. data/sig/discorb/shard.rbs +63 -0
  135. data/sig/discorb/snowflake.rbs +58 -0
  136. data/sig/discorb/stage_instance.rbs +69 -0
  137. data/sig/discorb/sticker.rbs +116 -0
  138. data/sig/discorb/system_channel_flag.rbs +17 -0
  139. data/sig/discorb/unicode_emoji.rbs +53 -0
  140. data/sig/discorb/user.rbs +95 -0
  141. data/sig/discorb/utils.rbs +8 -0
  142. data/sig/discorb/voice_region.rbs +30 -0
  143. data/sig/discorb/voice_state.rbs +71 -0
  144. data/sig/discorb/webhook.rbs +338 -0
  145. data/sig/discorb/welcome_screen.rbs +79 -0
  146. data/sig/discorb.rbs +5 -8661
  147. data/sig/manifest.yaml +3 -0
  148. data/sig/override.rbs +21 -0
  149. metadata +80 -3
@@ -0,0 +1,286 @@
1
+ module Discorb
2
+ #
3
+ # Represents an embed of discord.
4
+ class Embed
5
+ #
6
+ # Initialize a new Embed object.
7
+ #
8
+ # @param [String] title The title of embed.
9
+ # @param [String] description The description of embed.
10
+ # @param [Discorb::Color, Integer] color The color of embed.
11
+ # @param [String] url The url of embed.
12
+ # @param [Time] timestamp The timestamp of embed.
13
+ # @param [Discorb::Embed::Author] author The author field of embed.
14
+ # @param [Array<Discorb::Embed::Field>] fields The fields of embed.
15
+ # @param [Discorb::Embed::Footer] footer The footer of embed.
16
+ # @param [Discorb::Embed::Image, String] image The image of embed.
17
+ # @param [Discorb::Embed::Thumbnail, String] thumbnail The thumbnail of embed.
18
+ def initialize: (
19
+ ?String? title,
20
+ ?String? description,
21
+ ?color: (Discorb::Color | Integer)?,
22
+ ?url: String?,
23
+ ?timestamp: Time?,
24
+ ?author: Discorb::Embed::Author?,
25
+ ?fields: ::Array[Discorb::Embed::Field]?,
26
+ ?footer: Discorb::Embed::Footer?,
27
+ ?image: (Discorb::Embed::Image | String)?,
28
+ ?thumbnail: (Discorb::Embed::Thumbnail | String)?
29
+ ) -> void
30
+
31
+ #
32
+ # Initialize embed from hash.
33
+ # @private
34
+ #
35
+ # @param [Hash] data The hash data to initialize embed.
36
+ def initialize_hash: (Discorb::json data) -> untyped
37
+
38
+ %a{pure}
39
+ def inspect: -> String
40
+
41
+ #
42
+ # Convert embed to hash.
43
+ #
44
+ # @see https://discord.com/developers/docs/resources/channel#embed-object-embed-structure Offical Discord API Docs
45
+ # @return [Hash] Converted embed.
46
+ %a{pure}
47
+ def to_hash: -> Discorb::json
48
+
49
+ def self.from_hash: (untyped data) -> untyped
50
+
51
+ # @return [String, nil] The title of embed.
52
+ attr_accessor title: String?
53
+
54
+ # @return [String, nil] The description of embed.
55
+ attr_accessor description: String?
56
+
57
+ # @return [String, nil] The url of embed.
58
+ attr_accessor url: String?
59
+
60
+ # @return [Time, nil] The timestamp of embed.
61
+ attr_accessor timestamp: Time?
62
+
63
+ # @return [Discorb::Color, nil] The color of embed.
64
+ attr_accessor color: Discorb::Color?
65
+
66
+ # @return [Discorb::Embed::Author, nil] The author of embed.
67
+ attr_accessor author: Discorb::Embed::Author?
68
+
69
+ # @return [Array<Discorb::Embed::Field>] The fields of embed.
70
+ attr_accessor fields: ::Array[Discorb::Embed::Field]
71
+
72
+ # @return [Discorb::Embed::Footer, nil] The footer of embed.
73
+ attr_accessor footer: Discorb::Embed::Footer?
74
+
75
+ # @return [Symbol] The type of embed.
76
+ attr_reader type: Symbol
77
+
78
+ # @return [Discorb::Embed::Image] The image of embed.
79
+ attr_accessor image: Discorb::Embed::Image?
80
+
81
+ # @return [Discorb::Embed::Thumbnail] The thumbnail of embed.
82
+ attr_accessor thumbnail: Discorb::Embed::Thumbnail?
83
+
84
+ #
85
+ # Represents an entry in embed.
86
+ # @abstract
87
+ # @private
88
+ class Entry
89
+ %a{pure}
90
+ def inspect: -> String
91
+ end
92
+
93
+ #
94
+ # Represents an author of embed.
95
+ class Author < Discorb::Embed::Entry
96
+ #
97
+ # Initialize a new Author object.
98
+ #
99
+ # @param [String] name The name of author.
100
+ # @param [String] url The url of author.
101
+ # @param [String] icon The icon url of author.
102
+ def initialize: (String name, ?url: String?, ?icon: String?) -> void
103
+
104
+ #
105
+ # Convert author to hash.
106
+ #
107
+ # @see https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
108
+ # Offical Discord API Docs
109
+ # @return [Hash] Converted author.
110
+ def to_hash: -> Discorb::json
111
+
112
+ # @return [String] The name of author.
113
+ attr_accessor name: String
114
+
115
+ # @return [String, nil] The url of author.
116
+ attr_accessor url: String?
117
+
118
+ # @return [String, nil] The icon url of author.
119
+ attr_accessor icon: String?
120
+ end
121
+
122
+ #
123
+ # Represemts a footer of embed.
124
+ class Footer < Discorb::Embed::Entry
125
+ #
126
+ # Initialize a new Footer object.
127
+ #
128
+ # @param [String] text The text of footer.
129
+ # @param [String] icon The icon url of footer.
130
+ def initialize: (String text, ?icon: String?) -> void
131
+
132
+ #
133
+ # Convert footer to hash.
134
+ #
135
+ # @see https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
136
+ # Offical Discord API Docs
137
+ # @return [Hash] Converted footer.
138
+ %a{pure}
139
+ def to_hash: -> Discorb::json
140
+
141
+ # Returns the value of attribute text.
142
+ attr_accessor text: untyped
143
+
144
+ # Returns the value of attribute icon.
145
+ attr_accessor icon: untyped
146
+ end
147
+
148
+ #
149
+ # Represents a field of embed.
150
+ class Field < Discorb::Embed::Entry
151
+ #
152
+ # Initialize a new Field object.
153
+ #
154
+ # @param [String] name The name of field.
155
+ # @param [String] value The value of field.
156
+ # @param [Boolean] inline Whether the field is inline.
157
+ def initialize: (String name, String value, ?inline: bool) -> void
158
+
159
+ #
160
+ # Convert field to hash.
161
+ #
162
+ # @see https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
163
+ # Offical Discord API Docs
164
+ # @return [Hash] Converted field.
165
+ %a{pure}
166
+ def to_hash: -> Discorb::json
167
+
168
+ # @return [String] The name of field.
169
+ attr_accessor name: String
170
+
171
+ # @return [String] The value of field.
172
+ attr_accessor value: String
173
+
174
+ # @return [Boolean] Whether the field is inline.
175
+ attr_accessor inline: bool
176
+ end
177
+
178
+ #
179
+ # Represents an image of embed.
180
+ class Image < Discorb::Embed::Entry
181
+ #
182
+ # Initialize a new Image object.
183
+ #
184
+ # @param [String] url URL of image.
185
+ def initialize: (String url) -> void
186
+
187
+ #
188
+ # Convert image to hash for sending.
189
+ #
190
+ # @see https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
191
+ # Offical Discord API Docs
192
+ # @return [Hash] Converted image.
193
+ %a{pure}
194
+ def to_hash: -> Discorb::json
195
+
196
+ # @return [String] The url of image.
197
+ attr_accessor url: String
198
+
199
+ # @return [String] The proxy url of image.
200
+ # @return [nil] The Image object wasn't created from gateway.
201
+ attr_reader proxy_url: String?
202
+
203
+ # @return [Integer] The height of image.
204
+ # @return [nil] The Image object wasn't created from gateway.
205
+ attr_reader height: Integer?
206
+
207
+ # @return [Integer] The width of image.
208
+ # @return [nil] The Image object wasn't created from gateway.
209
+ attr_reader width: Integer?
210
+ end
211
+
212
+ #
213
+ # Represents a thumbnail of embed.
214
+ class Thumbnail < Discorb::Embed::Entry
215
+ #
216
+ # Initialize a new Thumbnail object.
217
+ #
218
+ # @param [String] url URL of thumbnail.
219
+ def initialize: (String url) -> void
220
+
221
+ #
222
+ # Convert thumbnail to hash for sending.
223
+ #
224
+ # @see https://discord.com/developers/docs/resources/channel#embed-object-embed-thumbnail-structure
225
+ # Offical Discord API Docs
226
+ # @return [Hash] Converted thumbnail.
227
+ %a{pure}
228
+ def to_hash: -> Discorb::json
229
+
230
+ # @return [String] The url of thumbnail.
231
+ attr_accessor url: String
232
+
233
+ # @return [String] The proxy url of thumbnail.
234
+ # @return [nil] The Thumbnail object wasn't created from gateway.
235
+ attr_reader proxy_url: String?
236
+
237
+ # @return [Integer] The height of thumbnail.
238
+ # @return [nil] The Thumbnail object wasn't created from gateway.
239
+ attr_reader height: Integer?
240
+
241
+ # @return [Integer] The width of thumbnail.
242
+ # @return [nil] The Thumbnail object wasn't created from gateway.
243
+ attr_reader width: Integer?
244
+ end
245
+
246
+ #
247
+ # Represents a video of embed.
248
+ class Video < Discorb::Embed::Entry
249
+ #
250
+ # Initialize a new Video object.
251
+ # @private
252
+ #
253
+ # @param [Hash] data The data of video.
254
+ def initialize: (Discorb::json data) -> void
255
+
256
+ # @return [String] The url of video.
257
+ attr_reader url: String
258
+
259
+ # @return [String] The proxy url of video.
260
+ attr_reader proxy_url: String
261
+
262
+ # @return [Integer] The height of video.
263
+ attr_reader height: Integer
264
+
265
+ # @return [Integer] The width of video.
266
+ attr_reader width: Integer
267
+ end
268
+
269
+ #
270
+ # Represents a provider of embed.
271
+ class Provider < Discorb::Embed::Entry
272
+ #
273
+ # Initialize a new Provider object.
274
+ # @private
275
+ #
276
+ # @param [Hash] data The data of provider.
277
+ def initialize: (Discorb::json data) -> void
278
+
279
+ # @return [String] The name of provider.
280
+ attr_reader name: String
281
+
282
+ # @return [String] The url of provider.
283
+ attr_reader url: String
284
+ end
285
+ end
286
+ end
@@ -0,0 +1,14 @@
1
+ module Discorb
2
+ type emoji = Discorb::Emoji | Discorb::PartialEmoji
3
+
4
+ # Represents a Discord emoji.
5
+ # @abstract
6
+ class Emoji
7
+ def eql?: (untyped other) -> bool
8
+
9
+ def ==: (untyped other) -> untyped
10
+
11
+ %a{pure}
12
+ def inspect: -> String
13
+ end
14
+ end
@@ -0,0 +1,73 @@
1
+ module Discorb
2
+ #
3
+ # Error class for Discorb.
4
+ # @abstract
5
+ class DiscorbError < StandardError
6
+ def enumerate_errors: (untyped hash) -> untyped
7
+
8
+ def _recr_items: (untyped key, untyped item, untyped res) -> untyped
9
+ end
10
+
11
+ #
12
+ # Represents a HTTP error.
13
+ # @abstract
14
+ class HTTPError < Discorb::DiscorbError
15
+ #
16
+ # Initialize a new instance of the HTTPError class.
17
+ # @private
18
+ def initialize: (untyped resp, untyped data) -> void
19
+
20
+ # @return [String] the JSON response code.
21
+ # @see https://discord.com/developers/docs/topics/opcodes-and-status-codes#json-json-error-codes
22
+ attr_reader code: String
23
+
24
+ # @return [Net::HTTPResponse] the HTTP response.
25
+ attr_reader response: Net::HTTPResponse
26
+ end
27
+
28
+ #
29
+ # Represents a 400 error.
30
+ class BadRequestError < Discorb::HTTPError
31
+ #
32
+ # Initialize a new instance of the BadRequestError class.
33
+ # @private
34
+ def initialize: (untyped resp, untyped data) -> void
35
+ end
36
+
37
+ #
38
+ # Represents a 401 error.
39
+ class UnauthorizedError < Discorb::HTTPError
40
+ end
41
+
42
+ #
43
+ # Represents a 403 error.
44
+ class ForbiddenError < Discorb::HTTPError
45
+ end
46
+
47
+ #
48
+ # Represents a 404 error.
49
+ class NotFoundError < Discorb::HTTPError
50
+ end
51
+
52
+ #
53
+ # Represents a error because of a cloudflare ban.
54
+ class CloudFlareBanError < Discorb::HTTPError
55
+ def initialize: (untyped _resp, untyped client) -> void
56
+ end
57
+
58
+ #
59
+ # Represents a error in client-side.
60
+ class ClientError < Discorb::DiscorbError
61
+ end
62
+
63
+ #
64
+ # Represents a timeout error.
65
+ class TimeoutError < Discorb::DiscorbError
66
+ end
67
+
68
+ #
69
+ # Represents a warning.
70
+ class NotSupportedWarning < Discorb::DiscorbError
71
+ def initialize: (untyped message) -> void
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ module Discorb
2
+ #
3
+ # Represents a event handler.
4
+ # This class shouldn't be instantiated directly.
5
+ # Use {Client#on} instead.
6
+ class EventHandler
7
+ def initialize: (untyped block, Symbol? id, untyped metadata) -> void
8
+
9
+ %a{pure}
10
+ def inspect: -> String
11
+
12
+ #
13
+ # Calls the block associated with the event.
14
+ def call: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
15
+
16
+ # @return [Proc] the block to be called.
17
+ attr_reader block: ^(*untyped) -> void
18
+
19
+ # @return [Symbol] the event id.
20
+ attr_reader id: Symbol?
21
+
22
+ # @return [Hash] the event metadata.
23
+ attr_reader metadata: ::Hash[untyped, untyped]
24
+
25
+ # @return [Boolean] whether the event is once or not.
26
+ attr_reader once: bool
27
+ end
28
+ end