discorb 0.13.0 → 0.13.4

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 (64) 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/CODE_OF_CONDUCT.md +128 -0
  8. data/Changelog.md +420 -388
  9. data/Gemfile +5 -1
  10. data/README.md +2 -2
  11. data/Rakefile +131 -1
  12. data/crowdin.yml +2 -0
  13. data/discorb.gemspec +12 -1
  14. data/docs/Examples.md +2 -0
  15. data/docs/application_command.md +7 -5
  16. data/docs/cli/irb.md +2 -0
  17. data/docs/cli/new.md +2 -0
  18. data/docs/cli/run.md +3 -1
  19. data/docs/cli/setup.md +4 -2
  20. data/docs/cli.md +2 -0
  21. data/docs/events.md +6 -4
  22. data/docs/extension.md +2 -2
  23. data/docs/faq.md +4 -2
  24. data/docs/license.md +2 -0
  25. data/docs/tutorial.md +4 -3
  26. data/docs/voice_events.md +2 -0
  27. data/lib/discorb/app_command.rb +32 -9
  28. data/lib/discorb/application.rb +1 -1
  29. data/lib/discorb/asset.rb +1 -1
  30. data/lib/discorb/channel.rb +170 -125
  31. data/lib/discorb/client.rb +20 -22
  32. data/lib/discorb/common.rb +32 -1
  33. data/lib/discorb/dictionary.rb +10 -2
  34. data/lib/discorb/emoji.rb +7 -9
  35. data/lib/discorb/emoji_table.rb +3891 -3891
  36. data/lib/discorb/event.rb +12 -11
  37. data/lib/discorb/exe/show.rb +2 -0
  38. data/lib/discorb/extension.rb +1 -1
  39. data/lib/discorb/flag.rb +1 -1
  40. data/lib/discorb/gateway.rb +63 -17
  41. data/lib/discorb/guild.rb +110 -156
  42. data/lib/discorb/guild_template.rb +15 -12
  43. data/lib/discorb/http.rb +41 -136
  44. data/lib/discorb/integration.rb +34 -2
  45. data/lib/discorb/interaction/autocomplete.rb +1 -1
  46. data/lib/discorb/interaction/response.rb +34 -32
  47. data/lib/discorb/interaction/root.rb +8 -0
  48. data/lib/discorb/invite.rb +4 -3
  49. data/lib/discorb/log.rb +3 -2
  50. data/lib/discorb/member.rb +44 -15
  51. data/lib/discorb/message.rb +33 -22
  52. data/lib/discorb/modules.rb +28 -35
  53. data/lib/discorb/presence.rb +2 -2
  54. data/lib/discorb/rate_limit.rb +14 -18
  55. data/lib/discorb/role.rb +18 -14
  56. data/lib/discorb/sticker.rb +10 -14
  57. data/lib/discorb/user.rb +10 -10
  58. data/lib/discorb/voice_state.rb +12 -7
  59. data/lib/discorb/webhook.rb +44 -50
  60. data/lib/discorb.rb +1 -1
  61. data/po/yard.pot +7772 -5154
  62. data/sig/discorb.rbs +3316 -3819
  63. data/template-replace/scripts/locale_ja.rb +62 -0
  64. metadata +18 -5
@@ -63,7 +63,7 @@ module Discorb
63
63
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions that the client is using.
64
64
  # @param [Discorb::Intents] intents The intents that the client is currently using.
65
65
  # @param [Integer] message_caches The number of messages to cache.
66
- # @param [#puts] log The IO object to use for logging.
66
+ # @param [#write] log The IO object to use for logging.
67
67
  # @param [Boolean] colorize_log Whether to colorize the log.
68
68
  # @param [:debug, :info, :warn, :error, :critical] log_level The log level.
69
69
  # @param [Boolean] wait_until_ready Whether to delay event dispatch until ready.
@@ -105,7 +105,7 @@ 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.
@@ -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])
@@ -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
  #
@@ -210,15 +212,14 @@ module Discorb
210
212
  #
211
213
  def fetch_user(id)
212
214
  Async do
213
- _resp, data = http.get("/users/#{id}").wait
215
+ _resp, data = @http.request(Route.new("/users/#{id}", "//users/:user_id", :get)).wait
214
216
  User.new(self, data)
215
217
  end
216
218
  end
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
  #
@@ -228,15 +229,14 @@ module Discorb
228
229
  #
229
230
  def fetch_channel(id)
230
231
  Async do
231
- _resp, data = http.get("/channels/#{id}").wait
232
+ _resp, data = @http.request(Route.new("/channels/#{id}", "//channels/:channel_id", :get)).wait
232
233
  Channel.make_channel(self, data)
233
234
  end
234
235
  end
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
  #
@@ -246,15 +246,14 @@ module Discorb
246
246
  #
247
247
  def fetch_guild(id)
248
248
  Async do
249
- _resp, data = http.get("/guilds/#{id}").wait
249
+ _resp, data = @http.request(Route.new("/guilds/#{id}", "//guilds/:guild_id", :get)).wait
250
250
  Guild.new(self, data, false)
251
251
  end
252
252
  end
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.
@@ -264,7 +263,7 @@ module Discorb
264
263
  #
265
264
  def fetch_invite(code, with_count: false, with_expiration: false)
266
265
  Async do
267
- _resp, data = http.get("/invites/#{code}?with_count=#{with_count}&with_expiration=#{with_expiration}").wait
266
+ _resp, data = @http.request(Route.new("/invites/#{code}?with_count=#{with_count}&with_expiration=#{with_expiration}", "//invites/:code", :get)).wait
268
267
  Invite.new(self, data, false)
269
268
  end
270
269
  end
@@ -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
  #
@@ -283,7 +281,7 @@ module Discorb
283
281
  Async do
284
282
  next @application if @application && !force
285
283
 
286
- _resp, data = http.get("/oauth2/applications/@me").wait
284
+ _resp, data = @http.request(Route.new("/oauth2/applications/@me", "//oauth2/applications/@me", :get)).wait
287
285
  @application = Application.new(self, data)
288
286
  @application
289
287
  end
@@ -291,14 +289,13 @@ 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
  #
299
296
  def fetch_nitro_sticker_packs
300
297
  Async do
301
- _resp, data = http.get("/stickers-packs").wait
298
+ _resp, data = @http.request(Route.new("/stickers-packs", "//stickers-packs", :get)).wait
302
299
  data.map { |pack| Sticker::Pack.new(self, pack) }
303
300
  end
304
301
  end
@@ -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.13.0"
7
+ VERSION = "0.13.4"
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
 
@@ -117,6 +117,37 @@ module Discorb
117
117
  alias id to_s
118
118
  end
119
119
 
120
+ #
121
+ # Represents an endpoint.
122
+ # @private
123
+ #
124
+ class Route
125
+ attr_reader :url, :key, :method
126
+
127
+ def initialize(url, key, method)
128
+ @url = url
129
+ @key = key
130
+ @method = method
131
+ end
132
+
133
+ def hash
134
+ @url.hash
135
+ end
136
+
137
+ def identifier
138
+ "#{@method} #{@key}"
139
+ end
140
+
141
+ def major_param
142
+ param_type = @key.split("/").find { |k| k.start_with?(":") }
143
+ return "" unless param_type
144
+ param = url.gsub(API_BASE_URL, "").split("/")[@key.split("/").index(param_type) - 1]
145
+ %w[:channel_id :guild_id :webhook_id].include?(param_type) ? param : ""
146
+ end
147
+ end
148
+
149
+ # @return [Object] Object that represents nil.
150
+ # This is used as a default value for optional parameters.
120
151
  Unset = Object.new
121
152
  class << Unset
122
153
  def method_missing(*)
@@ -16,6 +16,7 @@ module Discorb
16
16
  @cache = hash.transform_keys(&:to_s)
17
17
  @limit = limit
18
18
  @sort = sort
19
+ @cache = @cache.sort_by(&@sort).to_h if @sort
19
20
  end
20
21
 
21
22
  #
@@ -39,7 +40,7 @@ module Discorb
39
40
  # @param [Discorb::Dictionary] other The dictionary to merge.
40
41
  #
41
42
  def merge(other)
42
- @cache.merge!(other)
43
+ @cache.merge!(other.to_h)
43
44
  end
44
45
 
45
46
  #
@@ -73,6 +74,13 @@ module Discorb
73
74
  end
74
75
  end
75
76
 
77
+ #
78
+ # Convert the dictionary to a hash.
79
+ #
80
+ def to_h
81
+ @cache
82
+ end
83
+
76
84
  #
77
85
  # Returns the values of the dictionary.
78
86
  #
@@ -104,7 +112,7 @@ module Discorb
104
112
  end
105
113
  end
106
114
 
107
- def respond_to_missing?(name, args, kwargs)
115
+ def respond_to_missing?(name, ...)
108
116
  if values.respond_to?(name)
109
117
  true
110
118
  else
data/lib/discorb/emoji.rb CHANGED
@@ -82,8 +82,7 @@ module Discorb
82
82
 
83
83
  #
84
84
  # Edit the emoji.
85
- # @macro async
86
- # @macro http
85
+ # @async
87
86
  # @macro edit
88
87
  #
89
88
  # @param [String] name The new name of the emoji.
@@ -92,12 +91,12 @@ module Discorb
92
91
  #
93
92
  # @return [Async::Task<self>] The edited emoji.
94
93
  #
95
- def edit(name: :unset, roles: :unset, reason: nil)
94
+ def edit(name: Discorb::Unset, roles: Discorb::Unset, reason: nil)
96
95
  Async do
97
96
  payload = {}
98
- payload[:name] = name if name != :unset
99
- payload[:roles] = roles.map { |r| Discorb::Utils.try(r, :id) } if roles != :unset
100
- @client.http.patch("/guilds/#{@guild.id}/emojis/#{@id}", payload, audit_log_reason: reason)
97
+ payload[:name] = name if name != Discorb::Unset
98
+ payload[:roles] = roles.map { |r| Discorb::Utils.try(r, :id) } if roles != Discorb::Unset
99
+ @client.http.request(Route.new("/guilds/#{@guild.id}/emojis/#{@id}", "//guilds/:guild_id/emojis/:emoji_id", :patch), payload, audit_log_reason: reason)
101
100
  self
102
101
  end
103
102
  end
@@ -106,8 +105,7 @@ module Discorb
106
105
 
107
106
  #
108
107
  # Delete the emoji.
109
- # @macro async
110
- # @macro http
108
+ # @async
111
109
  #
112
110
  # @param [String] reason The reason for deleting the emoji.
113
111
  #
@@ -115,7 +113,7 @@ module Discorb
115
113
  #
116
114
  def delete!(reason: nil)
117
115
  Async do
118
- @client.http.delete("/guilds/#{@guild.id}/emojis/#{@id}", audit_log_reason: reason).wait
116
+ @client.http.request(Route.new("/guilds/#{@guild.id}/emojis/#{@id}", "//guilds/:guild_id/emojis/:emoji_id", :delete), audit_log_reason: reason).wait
119
117
  @available = false
120
118
  self
121
119
  end