discorb 0.19.0 → 0.20.0

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 (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,76 +1,81 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Class to handle rate limiting.
6
- # @private
7
- #
8
- class RatelimitHandler
9
- #
10
- # Initialize a rate limit handler.
11
- # @private
12
- #
13
- # @param [Discorb::Client] client The client.
14
- #
15
- def initialize(client)
16
- @client = client
17
- @path_ratelimit_bucket = {}
18
- @path_ratelimit_hash = {}
19
- @global = false
20
- end
21
-
22
- def inspect
23
- "#<#{self.class}>"
24
- end
25
-
26
- #
27
- # Wait for the rate limit to reset.
28
- #
29
- # @param [Discorb::Route] path The path.
30
- #
31
- def wait(path)
32
- # return if path.url.start_with?("https://")
33
- if @global && @global > Time.now.to_f
34
- time = @global - Time.now.to_f
35
- @client.logger.info("global rate limit reached, waiting #{time} seconds")
36
- sleep(time)
37
- @global = false
38
- end
39
-
40
- return unless hash = @path_ratelimit_hash[path.identifier]
41
-
42
- return unless bucket = @path_ratelimit_bucket[hash + path.major_param]
43
-
44
- if bucket[:reset_at] < Time.now.to_f
45
- @path_ratelimit_bucket.delete(path.identifier + path.major_param)
46
- return
47
- end
48
- return if (bucket[:remaining]).positive?
49
-
50
- time = bucket[:reset_at] - Time.now.to_f
51
- @client.logger.info("rate limit for #{path.identifier} with #{path.major_param} reached, " \
52
- "waiting #{time.round(4)} seconds")
53
- sleep(time)
54
- end
55
-
56
- #
57
- # Save the rate limit.
58
- #
59
- # @param [String] path The path.
60
- # @param [Net::HTTPResponse] resp The response.
61
- #
62
- def save(path, resp)
63
- if resp["X-Ratelimit-Global"] == "true"
64
- @global = Time.now.to_f + JSON.parse(resp.body,
65
- symbolize_names: true)[:retry_after]
66
- end
67
- return unless resp["X-RateLimit-Remaining"]
68
-
69
- @path_ratelimit_hash[path.identifier] = resp["X-Ratelimit-Bucket"]
70
- @path_ratelimit_bucket[resp["X-Ratelimit-Bucket"] + path.major_param] = {
71
- remaining: resp["X-RateLimit-Remaining"].to_i,
72
- reset_at: Time.now.to_f + resp["X-RateLimit-Reset-After"].to_f,
73
- }
74
- end
75
- end
76
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Class to handle rate limiting.
6
+ # @private
7
+ #
8
+ class RatelimitHandler
9
+ #
10
+ # Initialize a rate limit handler.
11
+ # @private
12
+ #
13
+ # @param [Discorb::Client] client The client.
14
+ #
15
+ def initialize(client)
16
+ @client = client
17
+ @path_ratelimit_bucket = {}
18
+ @path_ratelimit_hash = {}
19
+ @global = false
20
+ end
21
+
22
+ def inspect
23
+ "#<#{self.class}>"
24
+ end
25
+
26
+ #
27
+ # Wait for the rate limit to reset.
28
+ #
29
+ # @param [Discorb::Route] path The path.
30
+ #
31
+ def wait(path)
32
+ # return if path.url.start_with?("https://")
33
+ if @global && @global > Time.now.to_f
34
+ time = @global - Time.now.to_f
35
+ @client.logger.info(
36
+ "global rate limit reached, waiting #{time} seconds"
37
+ )
38
+ sleep(time)
39
+ @global = false
40
+ end
41
+
42
+ return unless hash = @path_ratelimit_hash[path.identifier]
43
+
44
+ return unless bucket = @path_ratelimit_bucket[hash + path.major_param]
45
+
46
+ if bucket[:reset_at] < Time.now.to_f
47
+ @path_ratelimit_bucket.delete(path.identifier + path.major_param)
48
+ return
49
+ end
50
+ return if (bucket[:remaining]).positive?
51
+
52
+ time = bucket[:reset_at] - Time.now.to_f
53
+ @client.logger.info(
54
+ "rate limit for #{path.identifier} with #{path.major_param} reached, " \
55
+ "waiting #{time.round(4)} seconds"
56
+ )
57
+ sleep(time)
58
+ end
59
+
60
+ #
61
+ # Save the rate limit.
62
+ #
63
+ # @param [String] path The path.
64
+ # @param [Net::HTTPResponse] resp The response.
65
+ #
66
+ def save(path, resp)
67
+ if resp["X-Ratelimit-Global"] == "true"
68
+ @global =
69
+ Time.now.to_f +
70
+ JSON.parse(resp.body, symbolize_names: true)[:retry_after]
71
+ end
72
+ return unless resp["X-RateLimit-Remaining"]
73
+
74
+ @path_ratelimit_hash[path.identifier] = resp["X-Ratelimit-Bucket"]
75
+ @path_ratelimit_bucket[resp["X-Ratelimit-Bucket"] + path.major_param] = {
76
+ remaining: resp["X-RateLimit-Remaining"].to_i,
77
+ reset_at: Time.now.to_f + resp["X-RateLimit-Reset-After"].to_f
78
+ }
79
+ end
80
+ end
81
+ end
@@ -1,54 +1,55 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a reaction to a message.
6
- #
7
- class Reaction < DiscordModel
8
- # @return [Integer] The number of users that have reacted with this emoji.
9
- attr_reader :count
10
- # @return [Discorb::Emoji, Discorb::PartialEmoji] The emoji that was reacted with.
11
- attr_reader :emoji
12
- # @return [Discorb::Message] The message that this reaction is on.
13
- attr_reader :message
14
- # @return [Boolean] Whether client user reacted with this emoji.
15
- attr_reader :me
16
- alias me? me
17
- alias reacted? me
18
-
19
- #
20
- # Initialize a new reaction.
21
- # @private
22
- #
23
- # @param [Discorb::Message] message The message that this reaction is on.
24
- # @param [Hash] data The data of the reaction.
25
- #
26
- def initialize(message, data)
27
- @message = message
28
- _set_data(data)
29
- end
30
-
31
- #
32
- # Fetch the user that reacted with this emoji.
33
- #
34
- # @param (see Message#fetch_reacted_users)
35
- #
36
- # @return [Async::Task<Array<Discorb::User>>] The users that reacted with this emoji.
37
- #
38
- def fetch_users(...)
39
- message.fetch_reacted_users(@emoji, ...)
40
- end
41
-
42
- private
43
-
44
- def _set_data(data)
45
- @count = data[:count]
46
- @me = data[:me]
47
- @emoji = if data[:emoji][:id].nil?
48
- UnicodeEmoji.new(data[:emoji][:name])
49
- else
50
- PartialEmoji.new(data[:emoji])
51
- end
52
- end
53
- end
54
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a reaction to a message.
6
+ #
7
+ class Reaction < DiscordModel
8
+ # @return [Integer] The number of users that have reacted with this emoji.
9
+ attr_reader :count
10
+ # @return [Discorb::Emoji, Discorb::PartialEmoji] The emoji that was reacted with.
11
+ attr_reader :emoji
12
+ # @return [Discorb::Message] The message that this reaction is on.
13
+ attr_reader :message
14
+ # @return [Boolean] Whether client user reacted with this emoji.
15
+ attr_reader :me
16
+ alias me? me
17
+ alias reacted? me
18
+
19
+ #
20
+ # Initialize a new reaction.
21
+ # @private
22
+ #
23
+ # @param [Discorb::Message] message The message that this reaction is on.
24
+ # @param [Hash] data The data of the reaction.
25
+ #
26
+ def initialize(message, data)
27
+ @message = message
28
+ _set_data(data)
29
+ end
30
+
31
+ #
32
+ # Fetch the user that reacted with this emoji.
33
+ #
34
+ # @param (see Message#fetch_reacted_users)
35
+ #
36
+ # @return [Async::Task<Array<Discorb::User>>] The users that reacted with this emoji.
37
+ #
38
+ def fetch_users(...)
39
+ message.fetch_reacted_users(@emoji, ...)
40
+ end
41
+
42
+ private
43
+
44
+ def _set_data(data)
45
+ @count = data[:count]
46
+ @me = data[:me]
47
+ @emoji =
48
+ if data[:emoji][:id].nil?
49
+ UnicodeEmoji.new(data[:emoji][:name])
50
+ else
51
+ PartialEmoji.new(data[:emoji])
52
+ end
53
+ end
54
+ end
55
+ end