discorb 0.12.3 → 0.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_main.yml +1 -0
  3. data/.github/workflows/build_version.yml +4 -3
  4. data/.github/workflows/crowdin.yml +32 -0
  5. data/.gitignore +3 -1
  6. data/.yardopts +2 -0
  7. data/Changelog.md +407 -372
  8. data/Gemfile +5 -1
  9. data/README.md +1 -1
  10. data/Rakefile +131 -1
  11. data/crowdin.yml +2 -0
  12. data/discorb.gemspec +1 -1
  13. data/docs/Examples.md +2 -0
  14. data/docs/application_command.md +17 -12
  15. data/docs/cli/irb.md +2 -0
  16. data/docs/cli/new.md +2 -0
  17. data/docs/cli/run.md +3 -1
  18. data/docs/cli/setup.md +4 -2
  19. data/docs/cli.md +2 -0
  20. data/docs/events.md +59 -5
  21. data/docs/extension.md +2 -2
  22. data/docs/faq.md +4 -2
  23. data/docs/license.md +2 -0
  24. data/docs/tutorial.md +4 -3
  25. data/docs/voice_events.md +2 -0
  26. data/lib/discorb/app_command.rb +13 -7
  27. data/lib/discorb/application.rb +32 -2
  28. data/lib/discorb/audit_logs.rb +28 -16
  29. data/lib/discorb/channel.rb +140 -81
  30. data/lib/discorb/client.rb +17 -19
  31. data/lib/discorb/common.rb +28 -1
  32. data/lib/discorb/components.rb +12 -0
  33. data/lib/discorb/dictionary.rb +1 -1
  34. data/lib/discorb/embed.rb +4 -0
  35. data/lib/discorb/emoji.rb +9 -7
  36. data/lib/discorb/emoji_table.rb +3774 -3689
  37. data/lib/discorb/event.rb +266 -24
  38. data/lib/discorb/event_handler.rb +39 -0
  39. data/lib/discorb/exe/show.rb +2 -0
  40. data/lib/discorb/extension.rb +5 -5
  41. data/lib/discorb/file.rb +4 -0
  42. data/lib/discorb/flag.rb +5 -1
  43. data/lib/discorb/gateway.rb +67 -15
  44. data/lib/discorb/gateway_requests.rb +4 -0
  45. data/lib/discorb/guild.rb +169 -82
  46. data/lib/discorb/guild_template.rb +12 -9
  47. data/lib/discorb/http.rb +82 -37
  48. data/lib/discorb/image.rb +7 -5
  49. data/lib/discorb/integration.rb +3 -0
  50. data/lib/discorb/intents.rb +8 -3
  51. data/lib/discorb/interaction/response.rb +27 -25
  52. data/lib/discorb/interaction/root.rb +8 -0
  53. data/lib/discorb/invite.rb +3 -2
  54. data/lib/discorb/log.rb +4 -0
  55. data/lib/discorb/member.rb +42 -13
  56. data/lib/discorb/message.rb +32 -17
  57. data/lib/discorb/modules.rb +19 -26
  58. data/lib/discorb/permission.rb +4 -0
  59. data/lib/discorb/rate_limit.rb +6 -2
  60. data/lib/discorb/role.rb +15 -11
  61. data/lib/discorb/sticker.rb +17 -12
  62. data/lib/discorb/user.rb +8 -7
  63. data/lib/discorb/voice_state.rb +8 -5
  64. data/lib/discorb/webhook.rb +38 -47
  65. data/lib/discorb.rb +2 -2
  66. data/po/yard.pot +7775 -5157
  67. data/sig/discorb.rbs +3317 -3820
  68. data/template-replace/scripts/locale_ja.rb +62 -0
  69. data/template-replace/scripts/yard_replace.rb +6 -0
  70. metadata +7 -4
@@ -105,17 +105,17 @@ module Discorb
105
105
 
106
106
  #
107
107
  # Registers an event handler.
108
- # @see file:docs/Events.md
108
+ # @see file:docs/Events.md Events Documentation
109
109
  #
110
110
  # @param [Symbol] event_name The name of the event.
111
111
  # @param [Symbol] id Custom ID of the event.
112
112
  # @param [Hash] metadata The metadata of the event.
113
113
  # @param [Proc] block The block to execute when the event is triggered.
114
114
  #
115
- # @return [Discorb::Event] The event.
115
+ # @return [Discorb::EventHandler] The event.
116
116
  #
117
117
  def on(event_name, id: nil, **metadata, &block)
118
- ne = Event.new(block, id, metadata)
118
+ ne = EventHandler.new(block, id, metadata)
119
119
  @events[event_name] ||= []
120
120
  @events[event_name].delete_if { |e| e.metadata[:override] }
121
121
  @events[event_name] << ne
@@ -127,7 +127,7 @@ module Discorb
127
127
  #
128
128
  # @param (see #on)
129
129
  #
130
- # @return [Discorb::Event] The event.
130
+ # @return [Discorb::EventHandler] The event.
131
131
  #
132
132
  def once(event_name, id: nil, **metadata, &block)
133
133
  metadata[:once] = true
@@ -146,10 +146,13 @@ module Discorb
146
146
 
147
147
  #
148
148
  # Dispatch an event.
149
+ # @async
149
150
  #
150
151
  # @param [Symbol] event_name The name of the event.
151
152
  # @param [Object] args The arguments to pass to the event.
152
153
  #
154
+ # @return [Async::Task<void>] The task.
155
+ #
153
156
  def dispatch(event_name, *args)
154
157
  Async do
155
158
  if (conditions = @conditions[event_name])
@@ -184,7 +187,7 @@ module Discorb
184
187
  events.each do |block|
185
188
  Async do
186
189
  Async(annotation: "Discorb event: #{event_name}") do |task|
187
- if block.is_a?(Discorb::Event)
190
+ if block.is_a?(Discorb::EventHandler)
188
191
  @events[event_name].delete(block) if block.metadata[:once]
189
192
  end
190
193
  block.call(*args)
@@ -199,8 +202,7 @@ module Discorb
199
202
 
200
203
  #
201
204
  # Fetch user from ID.
202
- # @macro async
203
- # @macro http
205
+ # @async
204
206
  #
205
207
  # @param [#to_s] id <description>
206
208
  #
@@ -217,8 +219,7 @@ module Discorb
217
219
 
218
220
  #
219
221
  # Fetch channel from ID.
220
- # @macro async
221
- # @macro http
222
+ # @async
222
223
  #
223
224
  # @param [#to_s] id The ID of the channel.
224
225
  #
@@ -235,8 +236,7 @@ module Discorb
235
236
 
236
237
  #
237
238
  # Fetch guild from ID.
238
- # @macro async
239
- # @macro http
239
+ # @async
240
240
  #
241
241
  # @param [#to_s] id <description>
242
242
  #
@@ -253,8 +253,7 @@ module Discorb
253
253
 
254
254
  #
255
255
  # Fetch invite from code.
256
- # @macro async
257
- # @macro http
256
+ # @async
258
257
  #
259
258
  # @param [String] code The code of the invite.
260
259
  # @param [Boolean] with_count Whether to include the count of the invite.
@@ -272,8 +271,7 @@ module Discorb
272
271
  #
273
272
  # Fetch webhook from ID.
274
273
  # If application was cached, it will be used.
275
- # @macro async
276
- # @macro http
274
+ # @async
277
275
  #
278
276
  # @param [Boolean] force Whether to force the fetch.
279
277
  #
@@ -291,8 +289,7 @@ module Discorb
291
289
 
292
290
  #
293
291
  # Fetch nitro sticker pack from ID.
294
- # @macro async
295
- # @macro http
292
+ # @async
296
293
  #
297
294
  # @return [Async::Task<Array<Discorb::Sticker::Pack>>] The packs.
298
295
  #
@@ -334,12 +331,13 @@ module Discorb
334
331
 
335
332
  #
336
333
  # Method to wait for a event.
334
+ # @async
337
335
  #
338
336
  # @param [Symbol] event The name of the event.
339
337
  # @param [Integer] timeout The timeout in seconds.
340
338
  # @param [Proc] check The check to use.
341
339
  #
342
- # @return [Object] The result of the event.
340
+ # @return [Async::Task<Object>] The result of the event.
343
341
  #
344
342
  # @raise [Discorb::TimeoutError] If the event didn't occur in time.
345
343
  #
@@ -416,7 +414,7 @@ module Discorb
416
414
  #
417
415
  # Starts the client.
418
416
  # @note This method behavior will change by CLI.
419
- # @see file:docs/cli.md
417
+ # @see file:docs/cli.md CLI documentation
420
418
  #
421
419
  # @param [String, nil] token The token to use.
422
420
  #
@@ -4,7 +4,7 @@ module Discorb
4
4
  # @return [String] The API base URL.
5
5
  API_BASE_URL = "https://discord.com/api/v9"
6
6
  # @return [String] The version of discorb.
7
- VERSION = "0.12.3"
7
+ VERSION = "0.13.2"
8
8
  # @return [String] The user agent for the bot.
9
9
  USER_AGENT = "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}"
10
10
 
@@ -110,6 +110,33 @@ module Discorb
110
110
  @value & 0xFFF
111
111
  end
112
112
 
113
+ def inspect
114
+ "#<#{self.class} #{to_s}>"
115
+ end
116
+
113
117
  alias id to_s
114
118
  end
119
+
120
+ # @return [Object] Object that represents nil.
121
+ # This is used as a default value for optional parameters.
122
+ Unset = Object.new
123
+ class << Unset
124
+ def method_missing(*)
125
+ self
126
+ end
127
+
128
+ def or(other)
129
+ other
130
+ end
131
+ end
132
+
133
+ module DefineOr
134
+ refine Object do
135
+ def or(other)
136
+ self
137
+ end
138
+ end
139
+ end
140
+
141
+ using DefineOr
115
142
  end
@@ -6,6 +6,10 @@ module Discorb
6
6
  # Represents a Discord component.
7
7
  #
8
8
  class Component
9
+ def inspect
10
+ "#<#{self.class}>"
11
+ end
12
+
9
13
  class << self
10
14
  #
11
15
  # Create a new component from hash data.
@@ -142,6 +146,10 @@ module Discorb
142
146
  end
143
147
  end
144
148
 
149
+ def inspect
150
+ "#<#{self.class}: #{@custom_id || @url}>"
151
+ end
152
+
145
153
  class << self
146
154
  # @private
147
155
  attr_reader :styles
@@ -218,6 +226,10 @@ module Discorb
218
226
  }
219
227
  end
220
228
 
229
+ def inspect
230
+ "#<#{self.class}: #{@custom_id}>"
231
+ end
232
+
221
233
  #
222
234
  # Represents an option of a select menu.
223
235
  #
@@ -48,7 +48,7 @@ module Discorb
48
48
  # @param [#to_s] id The ID of the item to remove.
49
49
  #
50
50
  def remove(id)
51
- @cache.remove(id.to_s)
51
+ @cache.delete(id.to_s)
52
52
  end
53
53
 
54
54
  #
data/lib/discorb/embed.rb CHANGED
@@ -86,6 +86,10 @@ module Discorb
86
86
  @thumbnail = (value.is_a?(String)) ? Thumbnail.new(value) : value
87
87
  end
88
88
 
89
+ def inspect
90
+ "#<#{self.class} \"#{@title}\">"
91
+ end
92
+
89
93
  #
90
94
  # Convert embed to hash.
91
95
  #
data/lib/discorb/emoji.rb CHANGED
@@ -13,6 +13,10 @@ module Discorb
13
13
  def ==(other)
14
14
  eql?(other)
15
15
  end
16
+
17
+ def inspect
18
+ "#<#{self.class}>"
19
+ end
16
20
  end
17
21
 
18
22
  # Represents a custom emoji in discord.
@@ -78,8 +82,7 @@ module Discorb
78
82
 
79
83
  #
80
84
  # Edit the emoji.
81
- # @macro async
82
- # @macro http
85
+ # @async
83
86
  # @macro edit
84
87
  #
85
88
  # @param [String] name The new name of the emoji.
@@ -88,11 +91,11 @@ module Discorb
88
91
  #
89
92
  # @return [Async::Task<self>] The edited emoji.
90
93
  #
91
- def edit(name: :unset, roles: :unset, reason: nil)
94
+ def edit(name: Discorb::Unset, roles: Discorb::Unset, reason: nil)
92
95
  Async do
93
96
  payload = {}
94
- payload[:name] = name if name != :unset
95
- payload[:roles] = roles.map { |r| Discorb::Utils.try(r, :id) } if roles != :unset
97
+ payload[:name] = name if name != Discorb::Unset
98
+ payload[:roles] = roles.map { |r| Discorb::Utils.try(r, :id) } if roles != Discorb::Unset
96
99
  @client.http.patch("/guilds/#{@guild.id}/emojis/#{@id}", payload, audit_log_reason: reason)
97
100
  self
98
101
  end
@@ -102,8 +105,7 @@ module Discorb
102
105
 
103
106
  #
104
107
  # Delete the emoji.
105
- # @macro async
106
- # @macro http
108
+ # @async
107
109
  #
108
110
  # @param [String] reason The reason for deleting the emoji.
109
111
  #