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,164 +1,168 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- # @return [String] The API base URL.
5
- API_BASE_URL = "https://discord.com/api/v10"
6
- # @return [String] The version of discorb.
7
- VERSION = "0.19.0"
8
- # @return [Array<Integer>] The version array of discorb.
9
- VERSION_ARRAY = VERSION.split(".").map(&:to_i).freeze
10
- # @return [String] The user agent for the bot.
11
- USER_AGENT = "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}".freeze
12
-
13
- #
14
- # @abstract
15
- # Represents Discord model.
16
- #
17
- class DiscordModel
18
- def eql?(other)
19
- self == other
20
- end
21
-
22
- def ==(other)
23
- if respond_to?(:id) && other.respond_to?(:id)
24
- id == other.id
25
- else
26
- super
27
- end
28
- end
29
-
30
- def inspect
31
- "#<#{self.class}: #{@id}>"
32
- end
33
-
34
- # @private
35
- def hash
36
- @id.hash
37
- end
38
- end
39
-
40
- #
41
- # Represents Snowflake of Discord.
42
- #
43
- # @see https://discord.com/developers/docs/reference#snowflakes Official Discord API docs
44
- class Snowflake < String
45
- #
46
- # Initialize new snowflake.
47
- # @private
48
- #
49
- # @param [#to_s] value The value of the snowflake.
50
- #
51
- def initialize(value)
52
- @value = value.to_i
53
- super(@value.to_s)
54
- end
55
-
56
- # @!attribute [r] timestamp
57
- # Timestamp of snowflake.
58
- #
59
- # @return [Time] Timestamp of snowflake.
60
- #
61
- # @!attribute [r] worker_id
62
- # Worker ID of snowflake.
63
- #
64
- # @return [Integer] Worker ID of snowflake.
65
- #
66
- # @!attribute [r] process_id
67
- # Process ID of snowflake.
68
- #
69
- # @return [Integer] Process ID of snowflake.
70
- # @!attribute [r] increment
71
- # Increment of snowflake.
72
- #
73
- # @return [Integer] Increment of snowflake.
74
- # @!attribute [r] id
75
- # Alias of to_s.
76
- #
77
- # @return [String] The snowflake.
78
-
79
- #
80
- # Compares snowflake with other object.
81
- #
82
- # @param [#to_s] other Object to compare with.
83
- #
84
- # @return [Boolean] True if snowflake is equal to other object.
85
- #
86
- def ==(other)
87
- return false unless other.respond_to?(:to_s)
88
-
89
- to_s == other.to_s
90
- end
91
-
92
- #
93
- # Alias of {#==}.
94
- #
95
- def eql?(other)
96
- self == other
97
- end
98
-
99
- # Return hash of snowflake.
100
- def hash
101
- to_s.hash
102
- end
103
-
104
- def timestamp
105
- Time.at(((@value >> 22) + 1_420_070_400_000) / 1000.0)
106
- end
107
-
108
- def worker_id
109
- (@value & 0x3E0000) >> 17
110
- end
111
-
112
- def process_id
113
- (@value & 0x1F000) >> 12
114
- end
115
-
116
- def increment
117
- @value & 0xFFF
118
- end
119
-
120
- def inspect
121
- "#<#{self.class} #{self}>"
122
- end
123
-
124
- alias id to_s
125
- end
126
-
127
- #
128
- # Represents an endpoint.
129
- # @private
130
- #
131
- class Route
132
- attr_reader :url, :key, :method
133
-
134
- def initialize(url, key, method)
135
- @url = url
136
- @key = key
137
- @method = method
138
- end
139
-
140
- def inspect
141
- "#<#{self.class} #{self.identifier}>"
142
- end
143
-
144
- def hash
145
- @url.hash
146
- end
147
-
148
- def identifier
149
- "#{@method} #{@key}"
150
- end
151
-
152
- def major_param
153
- param_type = @key.split("/").find { |k| k.start_with?(":") }
154
- return "" unless param_type
155
-
156
- param = url.gsub(API_BASE_URL, "").split("/")[@key.split("/").index(param_type) - 1]
157
- %w[:channel_id :guild_id :webhook_id].include?(param_type) ? param : ""
158
- end
159
- end
160
-
161
- # @return [Object] Object that represents unspecified value.
162
- # This is used as a default value for optional parameters.
163
- Unset = Object.new
164
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ # @return [String] The API base URL.
5
+ API_BASE_URL = "https://discord.com/api/v10"
6
+ # @return [String] The version of discorb.
7
+ VERSION = "0.20.0"
8
+ # @return [Array<Integer>] The version array of discorb.
9
+ VERSION_ARRAY = VERSION.split(".").map(&:to_i).freeze
10
+ # @return [String] The user agent for the bot.
11
+ USER_AGENT =
12
+ "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}".freeze
13
+
14
+ #
15
+ # @abstract
16
+ # Represents Discord model.
17
+ #
18
+ class DiscordModel
19
+ def eql?(other)
20
+ self == other
21
+ end
22
+
23
+ def ==(other)
24
+ if respond_to?(:id) && other.respond_to?(:id)
25
+ id == other.id
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ def inspect
32
+ "#<#{self.class}: #{@id}>"
33
+ end
34
+
35
+ # @private
36
+ def hash
37
+ @id.hash
38
+ end
39
+ end
40
+
41
+ #
42
+ # Represents Snowflake of Discord.
43
+ #
44
+ # @see https://discord.com/developers/docs/reference#snowflakes Official Discord API docs
45
+ class Snowflake < String
46
+ #
47
+ # Initialize new snowflake.
48
+ # @private
49
+ #
50
+ # @param [#to_s] value The value of the snowflake.
51
+ #
52
+ def initialize(value)
53
+ @value = value.to_i
54
+ super(@value.to_s)
55
+ end
56
+
57
+ # @!attribute [r] timestamp
58
+ # Timestamp of snowflake.
59
+ #
60
+ # @return [Time] Timestamp of snowflake.
61
+ #
62
+ # @!attribute [r] worker_id
63
+ # Worker ID of snowflake.
64
+ #
65
+ # @return [Integer] Worker ID of snowflake.
66
+ #
67
+ # @!attribute [r] process_id
68
+ # Process ID of snowflake.
69
+ #
70
+ # @return [Integer] Process ID of snowflake.
71
+ # @!attribute [r] increment
72
+ # Increment of snowflake.
73
+ #
74
+ # @return [Integer] Increment of snowflake.
75
+ # @!attribute [r] id
76
+ # Alias of to_s.
77
+ #
78
+ # @return [String] The snowflake.
79
+
80
+ #
81
+ # Compares snowflake with other object.
82
+ #
83
+ # @param [#to_s] other Object to compare with.
84
+ #
85
+ # @return [Boolean] True if snowflake is equal to other object.
86
+ #
87
+ def ==(other)
88
+ return false unless other.respond_to?(:to_s)
89
+
90
+ to_s == other.to_s
91
+ end
92
+
93
+ #
94
+ # Alias of {#==}.
95
+ #
96
+ def eql?(other)
97
+ self == other
98
+ end
99
+
100
+ # Return hash of snowflake.
101
+ def hash
102
+ to_s.hash
103
+ end
104
+
105
+ def timestamp
106
+ Time.at(((@value >> 22) + 1_420_070_400_000) / 1000.0)
107
+ end
108
+
109
+ def worker_id
110
+ (@value & 0x3E0000) >> 17
111
+ end
112
+
113
+ def process_id
114
+ (@value & 0x1F000) >> 12
115
+ end
116
+
117
+ def increment
118
+ @value & 0xFFF
119
+ end
120
+
121
+ def inspect
122
+ "#<#{self.class} #{self}>"
123
+ end
124
+
125
+ alias id to_s
126
+ end
127
+
128
+ #
129
+ # Represents an endpoint.
130
+ # @private
131
+ #
132
+ class Route
133
+ attr_reader :url, :key, :method
134
+
135
+ def initialize(url, key, method)
136
+ @url = url
137
+ @key = key
138
+ @method = method
139
+ end
140
+
141
+ def inspect
142
+ "#<#{self.class} #{identifier}>"
143
+ end
144
+
145
+ def hash
146
+ @url.hash
147
+ end
148
+
149
+ def identifier
150
+ "#{@method} #{@key}"
151
+ end
152
+
153
+ def major_param
154
+ param_type = @key.split("/").find { |k| k.start_with?(":") }
155
+ return "" unless param_type
156
+
157
+ param =
158
+ url.gsub(API_BASE_URL, "").split("/")[
159
+ @key.split("/").index(param_type) - 1
160
+ ]
161
+ %w[:channel_id :guild_id :webhook_id].include?(param_type) ? param : ""
162
+ end
163
+ end
164
+
165
+ # @return [Object] Object that represents unspecified value.
166
+ # This is used as a default value for optional parameters.
167
+ Unset = Object.new
168
+ end
@@ -1,106 +1,107 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a button component.
6
- #
7
- class Button < Component
8
- # @return [String] The label of the button.
9
- attr_accessor :label
10
- # @return [:primary, :secondary, :success, :danger, :link] The style of the button.
11
- attr_accessor :style
12
- # @return [Discorb::Emoji] The emoji of the button.
13
- attr_accessor :emoji
14
- # @return [String] The custom ID of the button.
15
- # Won't be used if the style is `:link`.
16
- attr_accessor :custom_id
17
- # @return [String] The URL of the button.
18
- # Only used when the style is `:link`.
19
- attr_accessor :url
20
- # @return [Boolean] Whether the button is disabled.
21
- attr_accessor :disabled
22
- alias disabled? disabled
23
-
24
- # @private
25
- # @return [{Symbol => Integer}] The mapping of button styles.
26
- STYLES = {
27
- primary: 1,
28
- secondary: 2,
29
- success: 3,
30
- danger: 4,
31
- link: 5,
32
- }.freeze
33
-
34
- #
35
- # Initialize a new button.
36
- #
37
- # @param [String] label The label of the button.
38
- # @param [:primary, :secondary, :success, :danger, :link] style The style of the button.
39
- # @param [Discorb::Emoji] emoji The emoji of the button.
40
- # @param [String] custom_id The custom ID of the button.
41
- # @param [String] url The URL of the button.
42
- # @param [Boolean] disabled Whether the button is disabled.
43
- #
44
- def initialize(label, style = :primary, emoji: nil, custom_id: nil, url: nil, disabled: false)
45
- @label = label
46
- @style = style
47
- @emoji = emoji
48
- @custom_id = custom_id
49
- @url = url
50
- @disabled = disabled
51
- end
52
-
53
- #
54
- # Converts the button to a hash.
55
- #
56
- # @see https://discord.com/developers/docs/interactions/message-components#button-object-button-structure
57
- # Official Discord API docs
58
- # @return [Hash] A hash representation of the button.
59
- #
60
- def to_hash
61
- if @style == :link
62
- {
63
- type: 2,
64
- label: @label,
65
- style: STYLES[@style],
66
- url: @url,
67
- emoji: @emoji&.to_hash,
68
- disabled: @disabled,
69
- }
70
- else
71
- {
72
- type: 2,
73
- label: @label,
74
- style: STYLES[@style],
75
- custom_id: @custom_id,
76
- emoji: @emoji&.to_hash,
77
- disabled: @disabled,
78
- }
79
- end
80
- end
81
-
82
- def inspect
83
- "#<#{self.class}: #{@custom_id || @url}>"
84
- end
85
-
86
- class << self
87
- #
88
- # Creates a new button from a hash.
89
- #
90
- # @param [Hash] data The hash to create the button from.
91
- #
92
- # @return [Discorb::Button] The created button.
93
- #
94
- def from_hash(data)
95
- new(
96
- data[:label],
97
- data[:style],
98
- emoji: data[:emoji],
99
- custom_id: data[:custom_id],
100
- url: data[:url],
101
- disabled: data[:disabled],
102
- )
103
- end
104
- end
105
- end
106
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a button component.
6
+ #
7
+ class Button < Component
8
+ # @return [String] The label of the button.
9
+ attr_accessor :label
10
+ # @return [:primary, :secondary, :success, :danger, :link] The style of the button.
11
+ attr_accessor :style
12
+ # @return [Discorb::Emoji] The emoji of the button.
13
+ attr_accessor :emoji
14
+ # @return [String] The custom ID of the button.
15
+ # Won't be used if the style is `:link`.
16
+ attr_accessor :custom_id
17
+ # @return [String] The URL of the button.
18
+ # Only used when the style is `:link`.
19
+ attr_accessor :url
20
+ # @return [Boolean] Whether the button is disabled.
21
+ attr_accessor :disabled
22
+ alias disabled? disabled
23
+
24
+ # @private
25
+ # @return [{Symbol => Integer}] The mapping of button styles.
26
+ STYLES = { primary: 1, secondary: 2, success: 3, danger: 4, link: 5 }.freeze
27
+
28
+ #
29
+ # Initialize a new button.
30
+ #
31
+ # @param [String] label The label of the button.
32
+ # @param [:primary, :secondary, :success, :danger, :link] style The style of the button.
33
+ # @param [Discorb::Emoji] emoji The emoji of the button.
34
+ # @param [String] custom_id The custom ID of the button.
35
+ # @param [String] url The URL of the button.
36
+ # @param [Boolean] disabled Whether the button is disabled.
37
+ #
38
+ def initialize(
39
+ label,
40
+ style = :primary,
41
+ emoji: nil,
42
+ custom_id: nil,
43
+ url: nil,
44
+ disabled: false
45
+ )
46
+ @label = label
47
+ @style = style
48
+ @emoji = emoji
49
+ @custom_id = custom_id
50
+ @url = url
51
+ @disabled = disabled
52
+ end
53
+
54
+ #
55
+ # Converts the button to a hash.
56
+ #
57
+ # @see https://discord.com/developers/docs/interactions/message-components#button-object-button-structure
58
+ # Official Discord API docs
59
+ # @return [Hash] A hash representation of the button.
60
+ #
61
+ def to_hash
62
+ if @style == :link
63
+ {
64
+ type: 2,
65
+ label: @label,
66
+ style: STYLES[@style],
67
+ url: @url,
68
+ emoji: @emoji&.to_hash,
69
+ disabled: @disabled
70
+ }
71
+ else
72
+ {
73
+ type: 2,
74
+ label: @label,
75
+ style: STYLES[@style],
76
+ custom_id: @custom_id,
77
+ emoji: @emoji&.to_hash,
78
+ disabled: @disabled
79
+ }
80
+ end
81
+ end
82
+
83
+ def inspect
84
+ "#<#{self.class}: #{@custom_id || @url}>"
85
+ end
86
+
87
+ class << self
88
+ #
89
+ # Creates a new button from a hash.
90
+ #
91
+ # @param [Hash] data The hash to create the button from.
92
+ #
93
+ # @return [Discorb::Button] The created button.
94
+ #
95
+ def from_hash(data)
96
+ new(
97
+ data[:label],
98
+ data[:style],
99
+ emoji: data[:emoji],
100
+ custom_id: data[:custom_id],
101
+ url: data[:url],
102
+ disabled: data[:disabled]
103
+ )
104
+ end
105
+ end
106
+ end
107
+ end