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,145 +1,157 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a select menu component.
6
- #
7
- class SelectMenu < Component
8
- # @return [String] The custom ID of the select menu.
9
- attr_accessor :custom_id
10
- # @return [Array<SelectMenu::Option>] The options of the select menu.
11
- attr_accessor :options
12
- # @return [Integer] The minimum number of values.
13
- attr_accessor :min_values
14
- # @return [Integer] The maximum number of values.
15
- attr_accessor :max_values
16
- # @return [Boolean] Whether the select menu is disabled.
17
- attr_accessor :disabled
18
- alias disabled? disabled
19
-
20
- #
21
- # Initialize a new select menu.
22
- #
23
- # @param [String, Symbol] custom_id Custom ID of the select menu.
24
- # @param [Array<Discorb::SelectMenu::Option>] options The options of the select menu.
25
- # @param [String] placeholder The placeholder of the select menu.
26
- # @param [Integer] min_values The minimum number of values.
27
- # @param [Integer] max_values The maximum number of values.
28
- #
29
- def initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1)
30
- @custom_id = custom_id
31
- @options = options
32
- @placeholder = placeholder
33
- @min_values = min_values
34
- @max_values = max_values
35
- end
36
-
37
- #
38
- # Converts the select menu to a hash.
39
- #
40
- # @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-menu-structure
41
- # Official Discord API docs
42
- # @return [Hash] A hash representation of the select menu.
43
- #
44
- def to_hash
45
- {
46
- type: 3,
47
- custom_id: @custom_id,
48
- options: @options.map(&:to_hash),
49
- placeholder: @placeholder,
50
- min_values: @min_values,
51
- max_values: @max_values,
52
- disabled: @disabled,
53
- }
54
- end
55
-
56
- def inspect
57
- "#<#{self.class}: #{@custom_id}>"
58
- end
59
-
60
- class << self
61
- #
62
- # Creates a new select menu from a hash.
63
- #
64
- # @param [Hash] data The hash to create the select menu from.
65
- #
66
- # @return [Discorb::SelectMenu] The created select menu.
67
- #
68
- def from_hash(data)
69
- new(
70
- data[:custom_id],
71
- data[:options].map { |o| SelectMenu::Option.from_hash(o) },
72
- placeholder: data[:placeholder],
73
- min_values: data[:min_values],
74
- max_values: data[:max_values],
75
- )
76
- end
77
- end
78
-
79
- #
80
- # Represents an option of a select menu.
81
- #
82
- class Option
83
- # @return [String] The label of the option.
84
- attr_accessor :label
85
- # @return [String] The value of the option.
86
- attr_accessor :value
87
- # @return [String] The description of the option.
88
- attr_accessor :description
89
- # @return [Discorb::Emoji] The emoji of the option.
90
- attr_accessor :emoji
91
- # @return [Boolean] Whether the option is default.
92
- attr_accessor :default
93
-
94
- #
95
- # Initialize a new option.
96
- #
97
- # @param [String] label The label of the option.
98
- # @param [String] value The value of the option.
99
- # @param [String] description The description of the option.
100
- # @param [Discorb::Emoji] emoji The emoji of the option.
101
- # @param [Boolean] default Whether the option is default.
102
- def initialize(label, value, description: nil, emoji: nil, default: false)
103
- @label = label
104
- @value = value
105
- @description = description
106
- @emoji = emoji
107
- @default = default
108
- end
109
-
110
- #
111
- # Converts the option to a hash.
112
- #
113
- # @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure
114
- # Official Discord API docs
115
- # @return [Hash] Hash representation of the option.
116
- #
117
- def to_hash
118
- {
119
- label: @label,
120
- value: @value,
121
- description: @description,
122
- emoji: @emoji&.to_hash,
123
- default: @default,
124
- }
125
- end
126
-
127
- def inspect
128
- "#<#{self.class} #{@label}: #{@value}>"
129
- end
130
-
131
- class << self
132
- #
133
- # Creates a new option from a hash.
134
- #
135
- # @param [Hash] data A hash representing the option.
136
- #
137
- # @return [Discorb::SelectMenu::Option] A new option.
138
- #
139
- def from_hash(data)
140
- new(data[:label], data[:value], description: data[:description], emoji: data[:emoji], default: data[:default])
141
- end
142
- end
143
- end
144
- end
145
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a select menu component.
6
+ #
7
+ class SelectMenu < Component
8
+ # @return [String] The custom ID of the select menu.
9
+ attr_accessor :custom_id
10
+ # @return [Array<SelectMenu::Option>] The options of the select menu.
11
+ attr_accessor :options
12
+ # @return [Integer] The minimum number of values.
13
+ attr_accessor :min_values
14
+ # @return [Integer] The maximum number of values.
15
+ attr_accessor :max_values
16
+ # @return [Boolean] Whether the select menu is disabled.
17
+ attr_accessor :disabled
18
+ alias disabled? disabled
19
+
20
+ #
21
+ # Initialize a new select menu.
22
+ #
23
+ # @param [String, Symbol] custom_id Custom ID of the select menu.
24
+ # @param [Array<Discorb::SelectMenu::Option>] options The options of the select menu.
25
+ # @param [String] placeholder The placeholder of the select menu.
26
+ # @param [Integer] min_values The minimum number of values.
27
+ # @param [Integer] max_values The maximum number of values.
28
+ #
29
+ def initialize(
30
+ custom_id,
31
+ options,
32
+ placeholder: nil,
33
+ min_values: 1,
34
+ max_values: 1
35
+ )
36
+ @custom_id = custom_id
37
+ @options = options
38
+ @placeholder = placeholder
39
+ @min_values = min_values
40
+ @max_values = max_values
41
+ end
42
+
43
+ #
44
+ # Converts the select menu to a hash.
45
+ #
46
+ # @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-menu-structure
47
+ # Official Discord API docs
48
+ # @return [Hash] A hash representation of the select menu.
49
+ #
50
+ def to_hash
51
+ {
52
+ type: 3,
53
+ custom_id: @custom_id,
54
+ options: @options.map(&:to_hash),
55
+ placeholder: @placeholder,
56
+ min_values: @min_values,
57
+ max_values: @max_values,
58
+ disabled: @disabled
59
+ }
60
+ end
61
+
62
+ def inspect
63
+ "#<#{self.class}: #{@custom_id}>"
64
+ end
65
+
66
+ class << self
67
+ #
68
+ # Creates a new select menu from a hash.
69
+ #
70
+ # @param [Hash] data The hash to create the select menu from.
71
+ #
72
+ # @return [Discorb::SelectMenu] The created select menu.
73
+ #
74
+ def from_hash(data)
75
+ new(
76
+ data[:custom_id],
77
+ data[:options].map { |o| SelectMenu::Option.from_hash(o) },
78
+ placeholder: data[:placeholder],
79
+ min_values: data[:min_values],
80
+ max_values: data[:max_values]
81
+ )
82
+ end
83
+ end
84
+
85
+ #
86
+ # Represents an option of a select menu.
87
+ #
88
+ class Option
89
+ # @return [String] The label of the option.
90
+ attr_accessor :label
91
+ # @return [String] The value of the option.
92
+ attr_accessor :value
93
+ # @return [String] The description of the option.
94
+ attr_accessor :description
95
+ # @return [Discorb::Emoji] The emoji of the option.
96
+ attr_accessor :emoji
97
+ # @return [Boolean] Whether the option is default.
98
+ attr_accessor :default
99
+
100
+ #
101
+ # Initialize a new option.
102
+ #
103
+ # @param [String] label The label of the option.
104
+ # @param [String] value The value of the option.
105
+ # @param [String] description The description of the option.
106
+ # @param [Discorb::Emoji] emoji The emoji of the option.
107
+ # @param [Boolean] default Whether the option is default.
108
+ def initialize(label, value, description: nil, emoji: nil, default: false)
109
+ @label = label
110
+ @value = value
111
+ @description = description
112
+ @emoji = emoji
113
+ @default = default
114
+ end
115
+
116
+ #
117
+ # Converts the option to a hash.
118
+ #
119
+ # @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure
120
+ # Official Discord API docs
121
+ # @return [Hash] Hash representation of the option.
122
+ #
123
+ def to_hash
124
+ {
125
+ label: @label,
126
+ value: @value,
127
+ description: @description,
128
+ emoji: @emoji&.to_hash,
129
+ default: @default
130
+ }
131
+ end
132
+
133
+ def inspect
134
+ "#<#{self.class} #{@label}: #{@value}>"
135
+ end
136
+
137
+ class << self
138
+ #
139
+ # Creates a new option from a hash.
140
+ #
141
+ # @param [Hash] data A hash representing the option.
142
+ #
143
+ # @return [Discorb::SelectMenu::Option] A new option.
144
+ #
145
+ def from_hash(data)
146
+ new(
147
+ data[:label],
148
+ data[:value],
149
+ description: data[:description],
150
+ emoji: data[:emoji],
151
+ default: data[:default]
152
+ )
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
@@ -1,106 +1,103 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a text input component.
6
- #
7
- class TextInput < Component
8
- # @private
9
- STYLES = {
10
- short: 1,
11
- paragraph: 2,
12
- }.freeze
13
-
14
- # @return [String] The label of the text input.
15
- attr_accessor :label
16
- # @return [String] The custom id of the text input.
17
- attr_accessor :custom_id
18
- # @return [:short, :paragraph] The style of the text input.
19
- attr_accessor :style
20
- # @return [Integer, nil] The minimum length of the text input.
21
- attr_accessor :min_length
22
- # @return [Integer, nil] The maximum length of the text input.
23
- attr_accessor :max_length
24
- # @return [Boolean] Whether the text input is required.
25
- attr_accessor :required
26
- # @return [String, nil] The prefilled value of the text input.
27
- attr_accessor :value
28
- # @return [String, nil] The placeholder of the text input.
29
- attr_accessor :placeholder
30
-
31
- #
32
- # Initialize a new text input component.
33
- #
34
- # @param [String] label The label of the text input.
35
- # @param [String] custom_id The custom id of the text input.
36
- # @param [:short, :paragraph] style The style of the text input.
37
- # @param [Integer, nil] min_length The minimum length of the text input.
38
- # @param [Integer, nil] max_length The maximum length of the text input.
39
- # @param [Boolean] required Whether the text input is required.
40
- # @param [String, nil] value The prefilled value of the text input.
41
- # @param [String, nil] placeholder The placeholder of the text input.
42
- #
43
- def initialize(
44
- label,
45
- custom_id,
46
- style,
47
- min_length: nil,
48
- max_length: nil,
49
- required: false,
50
- value: nil,
51
- placeholder: nil
52
- )
53
- @label = label
54
- @custom_id = custom_id
55
- @style = style
56
- @min_length = min_length
57
- @max_length = max_length
58
- @required = required
59
- @value = value
60
- @placeholder = placeholder
61
- end
62
-
63
- #
64
- # Converts the select menu to a hash.
65
- #
66
- # @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
67
- # Official Discord API docs
68
- # @return [Hash] A hash representation of the text input.
69
- #
70
- def to_hash
71
- {
72
- type: 4,
73
- label: @label,
74
- style: STYLES[@style],
75
- custom_id: @custom_id,
76
- min_length: @min_length,
77
- max_length: @max_length,
78
- required: @required,
79
- value: @value,
80
- placeholder: @placeholder,
81
- }
82
- end
83
-
84
- class << self
85
- #
86
- # Creates a new text input from a hash.
87
- #
88
- # @param [Hash] data The hash to create the text input from.
89
- #
90
- # @return [Discorb::TextInput] The created text input.
91
- #
92
- def from_hash(data)
93
- new(
94
- data[:label],
95
- data[:custom_id],
96
- STYLES.key(data[:style]),
97
- min_length: data[:min_length],
98
- max_length: data[:max_length],
99
- required: data[:required],
100
- value: data[:value],
101
- placeholder: data[:placeholder],
102
- )
103
- end
104
- end
105
- end
106
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a text input component.
6
+ #
7
+ class TextInput < Component
8
+ # @private
9
+ STYLES = { short: 1, paragraph: 2 }.freeze
10
+
11
+ # @return [String] The label of the text input.
12
+ attr_accessor :label
13
+ # @return [String] The custom id of the text input.
14
+ attr_accessor :custom_id
15
+ # @return [:short, :paragraph] The style of the text input.
16
+ attr_accessor :style
17
+ # @return [Integer, nil] The minimum length of the text input.
18
+ attr_accessor :min_length
19
+ # @return [Integer, nil] The maximum length of the text input.
20
+ attr_accessor :max_length
21
+ # @return [Boolean] Whether the text input is required.
22
+ attr_accessor :required
23
+ # @return [String, nil] The prefilled value of the text input.
24
+ attr_accessor :value
25
+ # @return [String, nil] The placeholder of the text input.
26
+ attr_accessor :placeholder
27
+
28
+ #
29
+ # Initialize a new text input component.
30
+ #
31
+ # @param [String] label The label of the text input.
32
+ # @param [String] custom_id The custom id of the text input.
33
+ # @param [:short, :paragraph] style The style of the text input.
34
+ # @param [Integer, nil] min_length The minimum length of the text input.
35
+ # @param [Integer, nil] max_length The maximum length of the text input.
36
+ # @param [Boolean] required Whether the text input is required.
37
+ # @param [String, nil] value The prefilled value of the text input.
38
+ # @param [String, nil] placeholder The placeholder of the text input.
39
+ #
40
+ def initialize(
41
+ label,
42
+ custom_id,
43
+ style,
44
+ min_length: nil,
45
+ max_length: nil,
46
+ required: false,
47
+ value: nil,
48
+ placeholder: nil
49
+ )
50
+ @label = label
51
+ @custom_id = custom_id
52
+ @style = style
53
+ @min_length = min_length
54
+ @max_length = max_length
55
+ @required = required
56
+ @value = value
57
+ @placeholder = placeholder
58
+ end
59
+
60
+ #
61
+ # Converts the select menu to a hash.
62
+ #
63
+ # @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
64
+ # Official Discord API docs
65
+ # @return [Hash] A hash representation of the text input.
66
+ #
67
+ def to_hash
68
+ {
69
+ type: 4,
70
+ label: @label,
71
+ style: STYLES[@style],
72
+ custom_id: @custom_id,
73
+ min_length: @min_length,
74
+ max_length: @max_length,
75
+ required: @required,
76
+ value: @value,
77
+ placeholder: @placeholder
78
+ }
79
+ end
80
+
81
+ class << self
82
+ #
83
+ # Creates a new text input from a hash.
84
+ #
85
+ # @param [Hash] data The hash to create the text input from.
86
+ #
87
+ # @return [Discorb::TextInput] The created text input.
88
+ #
89
+ def from_hash(data)
90
+ new(
91
+ data[:label],
92
+ data[:custom_id],
93
+ STYLES.key(data[:style]),
94
+ min_length: data[:min_length],
95
+ max_length: data[:max_length],
96
+ required: data[:required],
97
+ value: data[:value],
98
+ placeholder: data[:placeholder]
99
+ )
100
+ end
101
+ end
102
+ end
103
+ end
@@ -1,66 +1,68 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # @abstract
6
- # Represents a Discord component.
7
- #
8
- class Component
9
- def inspect
10
- "#<#{self.class}>"
11
- end
12
-
13
- class << self
14
- #
15
- # Create a new component from hash data.
16
- #
17
- # @see https://discord.com/developers/docs/interactions/message-components Official Discord API documentation
18
- # @param [Hash] data Hash data.
19
- #
20
- # @return [Component] A new component.
21
- #
22
- def from_hash(data)
23
- case data[:type]
24
- when 2
25
- Button
26
- when 3
27
- SelectMenu
28
- when 4
29
- TextInput
30
- end.from_hash(data)
31
- end
32
-
33
- #
34
- # Convert components to a hash.
35
- #
36
- # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components Components.
37
- #
38
- # @return [Array<Hash>] Hash data.
39
- #
40
- def to_payload(components)
41
- tmp_components = []
42
- tmp_row = []
43
- components.each do |c|
44
- case c
45
- when Array
46
- tmp_components << tmp_row
47
- tmp_row = []
48
- tmp_components << c
49
- when SelectMenu, TextInput
50
- tmp_components << tmp_row
51
- tmp_row = []
52
- tmp_components << [c]
53
- else
54
- tmp_row << c
55
- end
56
- end
57
- tmp_components << tmp_row
58
- tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
59
- end
60
- end
61
- end
62
- end
63
-
64
- %w[button text_input select_menu].each do |name|
65
- require_relative "components/#{name}"
66
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # @abstract
6
+ # Represents a Discord component.
7
+ #
8
+ class Component
9
+ def inspect
10
+ "#<#{self.class}>"
11
+ end
12
+
13
+ class << self
14
+ #
15
+ # Create a new component from hash data.
16
+ #
17
+ # @see https://discord.com/developers/docs/interactions/message-components Official Discord API documentation
18
+ # @param [Hash] data Hash data.
19
+ #
20
+ # @return [Component] A new component.
21
+ #
22
+ def from_hash(data)
23
+ case data[:type]
24
+ when 2
25
+ Button
26
+ when 3
27
+ SelectMenu
28
+ when 4
29
+ TextInput
30
+ end.from_hash(data)
31
+ end
32
+
33
+ #
34
+ # Convert components to a hash.
35
+ #
36
+ # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components Components.
37
+ #
38
+ # @return [Array<Hash>] Hash data.
39
+ #
40
+ def to_payload(components)
41
+ tmp_components = []
42
+ tmp_row = []
43
+ components.each do |c|
44
+ case c
45
+ when Array
46
+ tmp_components << tmp_row
47
+ tmp_row = []
48
+ tmp_components << c
49
+ when SelectMenu, TextInput
50
+ tmp_components << tmp_row
51
+ tmp_row = []
52
+ tmp_components << [c]
53
+ else
54
+ tmp_row << c
55
+ end
56
+ end
57
+ tmp_components << tmp_row
58
+ tmp_components
59
+ .filter { |c| c.length.positive? }
60
+ .map { |c| { type: 1, components: c.map(&:to_hash) } }
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ %w[button text_input select_menu].each do |name|
67
+ require_relative "components/#{name}"
68
+ end