discorb 0.18.0 → 0.20.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/build_version.yml +2 -2
  3. data/.rubocop.yml +12 -75
  4. data/Changelog.md +25 -0
  5. data/Gemfile +4 -4
  6. data/README.md +2 -1
  7. data/Rakefile +482 -459
  8. data/Steepfile +8 -6
  9. data/docs/application_command.md +1 -0
  10. data/docs/events.md +2 -2
  11. data/docs/voice_events.md +6 -6
  12. data/lib/discorb/allowed_mentions.rb +68 -72
  13. data/lib/discorb/app_command/command.rb +466 -394
  14. data/lib/discorb/app_command/common.rb +65 -25
  15. data/lib/discorb/app_command/handler.rb +304 -265
  16. data/lib/discorb/app_command.rb +5 -5
  17. data/lib/discorb/application.rb +198 -197
  18. data/lib/discorb/asset.rb +101 -101
  19. data/lib/discorb/attachment.rb +134 -119
  20. data/lib/discorb/audit_logs.rb +412 -385
  21. data/lib/discorb/automod.rb +279 -269
  22. data/lib/discorb/channel/base.rb +107 -108
  23. data/lib/discorb/channel/category.rb +32 -32
  24. data/lib/discorb/channel/container.rb +44 -44
  25. data/lib/discorb/channel/dm.rb +26 -28
  26. data/lib/discorb/channel/guild.rb +311 -246
  27. data/lib/discorb/channel/stage.rb +156 -140
  28. data/lib/discorb/channel/text.rb +430 -336
  29. data/lib/discorb/channel/thread.rb +374 -325
  30. data/lib/discorb/channel/voice.rb +85 -79
  31. data/lib/discorb/channel.rb +5 -5
  32. data/lib/discorb/client.rb +635 -623
  33. data/lib/discorb/color.rb +178 -182
  34. data/lib/discorb/common.rb +168 -164
  35. data/lib/discorb/components/button.rb +107 -106
  36. data/lib/discorb/components/select_menu.rb +157 -145
  37. data/lib/discorb/components/text_input.rb +103 -106
  38. data/lib/discorb/components.rb +68 -66
  39. data/lib/discorb/dictionary.rb +135 -135
  40. data/lib/discorb/embed.rb +404 -398
  41. data/lib/discorb/emoji.rb +309 -302
  42. data/lib/discorb/emoji_table.rb +16099 -8857
  43. data/lib/discorb/error.rb +131 -131
  44. data/lib/discorb/event.rb +360 -314
  45. data/lib/discorb/event_handler.rb +39 -39
  46. data/lib/discorb/exe/about.rb +17 -17
  47. data/lib/discorb/exe/irb.rb +72 -67
  48. data/lib/discorb/exe/new.rb +323 -315
  49. data/lib/discorb/exe/run.rb +69 -68
  50. data/lib/discorb/exe/setup.rb +57 -55
  51. data/lib/discorb/exe/show.rb +12 -12
  52. data/lib/discorb/extend.rb +25 -45
  53. data/lib/discorb/extension.rb +89 -83
  54. data/lib/discorb/flag.rb +126 -128
  55. data/lib/discorb/gateway.rb +984 -794
  56. data/lib/discorb/gateway_events.rb +670 -638
  57. data/lib/discorb/gateway_requests.rb +45 -48
  58. data/lib/discorb/guild.rb +2115 -1626
  59. data/lib/discorb/guild_template.rb +280 -241
  60. data/lib/discorb/http.rb +247 -232
  61. data/lib/discorb/image.rb +42 -42
  62. data/lib/discorb/integration.rb +169 -161
  63. data/lib/discorb/intents.rb +161 -163
  64. data/lib/discorb/interaction/autocomplete.rb +76 -62
  65. data/lib/discorb/interaction/command.rb +279 -224
  66. data/lib/discorb/interaction/components.rb +114 -104
  67. data/lib/discorb/interaction/modal.rb +36 -32
  68. data/lib/discorb/interaction/response.rb +379 -330
  69. data/lib/discorb/interaction/root.rb +271 -118
  70. data/lib/discorb/interaction.rb +5 -5
  71. data/lib/discorb/invite.rb +154 -153
  72. data/lib/discorb/member.rb +344 -311
  73. data/lib/discorb/message.rb +615 -544
  74. data/lib/discorb/message_meta.rb +197 -186
  75. data/lib/discorb/modules.rb +371 -290
  76. data/lib/discorb/permission.rb +305 -289
  77. data/lib/discorb/presence.rb +352 -346
  78. data/lib/discorb/rate_limit.rb +81 -76
  79. data/lib/discorb/reaction.rb +55 -54
  80. data/lib/discorb/role.rb +272 -240
  81. data/lib/discorb/shard.rb +76 -74
  82. data/lib/discorb/sticker.rb +193 -171
  83. data/lib/discorb/user.rb +205 -188
  84. data/lib/discorb/utils/colored_puts.rb +16 -16
  85. data/lib/discorb/utils.rb +12 -16
  86. data/lib/discorb/voice_state.rb +305 -281
  87. data/lib/discorb/webhook.rb +537 -507
  88. data/lib/discorb.rb +62 -56
  89. data/sig/discorb/activity.rbs +1 -0
  90. data/sig/discorb/allowed_mentions.rbs +1 -0
  91. data/sig/discorb/app_command/base.rbs +7 -1
  92. data/sig/discorb/application.rbs +6 -0
  93. data/sig/discorb/asset.rbs +2 -0
  94. data/sig/discorb/attachment.rbs +8 -0
  95. data/sig/discorb/audit_log.rbs +7 -0
  96. data/sig/discorb/automod.rbs +32 -6
  97. data/sig/discorb/avatar.rbs +1 -0
  98. data/sig/discorb/channel/base.rbs +8 -1
  99. data/sig/discorb/channel/category.rbs +1 -0
  100. data/sig/discorb/channel/container.rbs +4 -0
  101. data/sig/discorb/channel/stage.rbs +4 -0
  102. data/sig/discorb/channel/text.rbs +2 -2
  103. data/sig/discorb/channel/thread.rbs +11 -0
  104. data/sig/discorb/channel/voice.rbs +2 -0
  105. data/sig/discorb/client.rbs +21 -20
  106. data/sig/discorb/color.rbs +6 -0
  107. data/sig/discorb/component/base.rbs +1 -0
  108. data/sig/discorb/component/button.rbs +2 -0
  109. data/sig/discorb/component/select_menu.rbs +4 -0
  110. data/sig/discorb/component/text_input.rbs +1 -0
  111. data/sig/discorb/custom_emoji.rbs +5 -1
  112. data/sig/discorb/dictionary.rbs +2 -0
  113. data/sig/discorb/discord_model.rbs +2 -0
  114. data/sig/discorb/embed.rbs +7 -0
  115. data/sig/discorb/emoji.rbs +1 -0
  116. data/sig/discorb/event_handler.rbs +2 -1
  117. data/sig/discorb/extension.rbs +13 -12
  118. data/sig/discorb/flag.rbs +2 -0
  119. data/sig/discorb/gateway.rbs +5 -0
  120. data/sig/discorb/guild.rbs +8 -4
  121. data/sig/discorb/guild_template.rbs +1 -1
  122. data/sig/discorb/http.rbs +4 -1
  123. data/sig/discorb/image.rbs +2 -0
  124. data/sig/discorb/integration.rbs +1 -1
  125. data/sig/discorb/intents.rbs +4 -3
  126. data/sig/discorb/interaction/base.rbs +36 -0
  127. data/sig/discorb/interaction/message_component.rbs +1 -2
  128. data/sig/discorb/interaction/modal.rbs +1 -2
  129. data/sig/discorb/interaction/responder.rbs +49 -49
  130. data/sig/discorb/invite.rbs +1 -1
  131. data/sig/discorb/member.rbs +2 -0
  132. data/sig/discorb/message.rbs +8 -1
  133. data/sig/discorb/messageable.rbs +1 -4
  134. data/sig/discorb/partial_emoji.rbs +3 -0
  135. data/sig/discorb/permissions.rbs +7 -0
  136. data/sig/discorb/presence.rbs +2 -0
  137. data/sig/discorb/reaction.rbs +5 -1
  138. data/sig/discorb/role.rbs +7 -1
  139. data/sig/discorb/scheduled_event.rbs +2 -1
  140. data/sig/discorb/shard.rbs +2 -1
  141. data/sig/discorb/snowflake.rbs +2 -0
  142. data/sig/discorb/stage_instance.rbs +9 -3
  143. data/sig/discorb/sticker.rbs +1 -1
  144. data/sig/discorb/unicode_emoji.rbs +4 -0
  145. data/sig/discorb/user.rbs +24 -20
  146. data/sig/discorb/webhook.rbs +17 -6
  147. data/sig/discorb/welcome_screen.rbs +1 -0
  148. data/sig/override.rbs +2 -0
  149. metadata +3 -3
@@ -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.18.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