discorb 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
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,104 +1,114 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a message component interaction.
6
- # @abstract
7
- #
8
- class MessageComponentInteraction < Interaction
9
- include Interaction::SourceResponder
10
- include Interaction::UpdateResponder
11
- include Interaction::ModalResponder
12
-
13
- # @return [String] The content of the response.
14
- attr_reader :custom_id
15
- # @return [Discorb::Message] The target message.
16
- attr_reader :message
17
-
18
- @interaction_type = 3
19
- @interaction_name = :message_component
20
-
21
- #
22
- # Initialize a new message component interaction.
23
- # @private
24
- #
25
- # @param [Discorb::Client] client The client.
26
- # @param [Hash] data The data.
27
- #
28
- def initialize(client, data)
29
- super
30
- @message = Message.new(@client, data[:message].merge({ member: data[:member], guild_id: data[:guild_id] }))
31
- end
32
-
33
- class << self
34
- # @private
35
- # @return [Integer] The component type.
36
- attr_reader :component_type
37
-
38
- #
39
- # Create a MessageComponentInteraction instance for the given data.
40
- # @private
41
- #
42
- def make_interaction(client, data)
43
- nested_classes.each do |klass|
44
- if !klass.component_type.nil? && klass.component_type == data[:data][:component_type]
45
- return klass.new(client,
46
- data)
47
- end
48
- end
49
- client.logger.warn("Unknown component type #{data[:component_type]}, initialized Interaction")
50
- MessageComponentInteraction.new(client, data)
51
- end
52
-
53
- #
54
- # Returns the classes under this class.
55
- # @private
56
- #
57
- def nested_classes
58
- constants.select { |c| const_get(c).is_a? Class }.map { |c| const_get(c) }
59
- end
60
- end
61
-
62
- #
63
- # Represents a button interaction.
64
- #
65
- class Button < MessageComponentInteraction
66
- @component_type = 2
67
- @event_name = :button_click
68
- # @return [String] The custom id of the button.
69
- attr_reader :custom_id
70
-
71
- private
72
-
73
- def _set_data(data)
74
- @custom_id = data[:custom_id]
75
- end
76
- end
77
-
78
- #
79
- # Represents a select menu interaction.
80
- #
81
- class SelectMenu < MessageComponentInteraction
82
- @component_type = 3
83
- @event_name = :select_menu_select
84
- # @return [String] The custom id of the select menu.
85
- attr_reader :custom_id
86
- # @return [Array<String>] The selected options.
87
- attr_reader :values
88
-
89
- # @!attribute [r] value
90
- # @return [String] The first selected value.
91
-
92
- def value
93
- @values[0]
94
- end
95
-
96
- private
97
-
98
- def _set_data(data)
99
- @custom_id = data[:custom_id]
100
- @values = data[:values]
101
- end
102
- end
103
- end
104
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a message component interaction.
6
+ # @abstract
7
+ #
8
+ class MessageComponentInteraction < Interaction
9
+ include Interaction::SourceResponder
10
+ include Interaction::UpdateResponder
11
+ include Interaction::ModalResponder
12
+
13
+ # @return [String] The content of the response.
14
+ attr_reader :custom_id
15
+ # @return [Discorb::Message] The target message.
16
+ attr_reader :message
17
+
18
+ @interaction_type = 3
19
+ @interaction_name = :message_component
20
+
21
+ #
22
+ # Initialize a new message component interaction.
23
+ # @private
24
+ #
25
+ # @param [Discorb::Client] client The client.
26
+ # @param [Hash] data The data.
27
+ #
28
+ def initialize(client, data)
29
+ super
30
+ @message =
31
+ Message.new(
32
+ @client,
33
+ data[:message].merge(
34
+ { member: data[:member], guild_id: data[:guild_id] }
35
+ )
36
+ )
37
+ end
38
+
39
+ class << self
40
+ # @private
41
+ # @return [Integer] The component type.
42
+ attr_reader :component_type
43
+
44
+ #
45
+ # Create a MessageComponentInteraction instance for the given data.
46
+ # @private
47
+ #
48
+ def make_interaction(client, data)
49
+ nested_classes.each do |klass|
50
+ if !klass.component_type.nil? &&
51
+ klass.component_type == data[:data][:component_type]
52
+ return klass.new(client, data)
53
+ end
54
+ end
55
+ client.logger.warn(
56
+ "Unknown component type #{data[:component_type]}, initialized Interaction"
57
+ )
58
+ MessageComponentInteraction.new(client, data)
59
+ end
60
+
61
+ #
62
+ # Returns the classes under this class.
63
+ # @private
64
+ #
65
+ def nested_classes
66
+ constants
67
+ .select { |c| const_get(c).is_a? Class }
68
+ .map { |c| const_get(c) }
69
+ end
70
+ end
71
+
72
+ #
73
+ # Represents a button interaction.
74
+ #
75
+ class Button < MessageComponentInteraction
76
+ @component_type = 2
77
+ @event_name = :button_click
78
+ # @return [String] The custom id of the button.
79
+ attr_reader :custom_id
80
+
81
+ private
82
+
83
+ def _set_data(data)
84
+ @custom_id = data[:custom_id]
85
+ end
86
+ end
87
+
88
+ #
89
+ # Represents a select menu interaction.
90
+ #
91
+ class SelectMenu < MessageComponentInteraction
92
+ @component_type = 3
93
+ @event_name = :select_menu_select
94
+ # @return [String] The custom id of the select menu.
95
+ attr_reader :custom_id
96
+ # @return [Array<String>] The selected options.
97
+ attr_reader :values
98
+
99
+ # @!attribute [r] value
100
+ # @return [String] The first selected value.
101
+
102
+ def value
103
+ @values[0]
104
+ end
105
+
106
+ private
107
+
108
+ def _set_data(data)
109
+ @custom_id = data[:custom_id]
110
+ @values = data[:values]
111
+ end
112
+ end
113
+ end
114
+ end
@@ -1,32 +1,36 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a modal interaction.
6
- #
7
- class ModalInteraction < Interaction
8
- include Interaction::SourceResponder
9
-
10
- @interaction_type = 5
11
- @interaction_name = :modal_submit
12
- @event_name = :modal_submit
13
-
14
- # @return [String] The custom id of the modal.
15
- attr_reader :custom_id
16
- # @return [{String => String}] The contents of the modal.
17
- attr_reader :contents
18
-
19
- private
20
-
21
- def _set_data(data)
22
- @custom_id = data[:custom_id]
23
- @contents = data[:components].to_h do |component|
24
- [component[:components][0][:custom_id], component[:components][0][:value]]
25
- end
26
- end
27
-
28
- class << self
29
- alias make_interaction new
30
- end
31
- end
32
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a modal interaction.
6
+ #
7
+ class ModalInteraction < Interaction
8
+ include Interaction::SourceResponder
9
+
10
+ @interaction_type = 5
11
+ @interaction_name = :modal_submit
12
+ @event_name = :modal_submit
13
+
14
+ # @return [String] The custom id of the modal.
15
+ attr_reader :custom_id
16
+ # @return [{String => String}] The contents of the modal.
17
+ attr_reader :contents
18
+
19
+ private
20
+
21
+ def _set_data(data)
22
+ @custom_id = data[:custom_id]
23
+ @contents =
24
+ data[:components].to_h do |component|
25
+ [
26
+ component[:components][0][:custom_id],
27
+ component[:components][0][:value]
28
+ ]
29
+ end
30
+ end
31
+
32
+ class << self
33
+ alias make_interaction new
34
+ end
35
+ end
36
+ end