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,161 +1,169 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a integration.
6
- #
7
- class Integration < DiscordModel
8
- # @return [Discorb::Snowflake] The ID of the integration.
9
- attr_reader :id
10
- # @return [Symbol] The type of integration.
11
- attr_reader :type
12
- # @return [Boolean] Whether the integration is enabled.
13
- attr_reader :enabled
14
- alias enabled? enabled
15
- # @return [Boolean] Whether the integration is syncing.
16
- attr_reader :syncing
17
- alias syncing? syncing
18
- # @return [Boolean] Whether the integration is enabled emoticons.
19
- attr_reader :enable_emoticons
20
- alias enable_emoticons? enable_emoticons
21
- # @return [:remove_role, :kick] The behavior of the integration when it expires.
22
- attr_reader :expire_behavior
23
- # @return [Integer] The grace period of the integration.
24
- attr_reader :expire_grace_period
25
- # @return [Discorb::User] The user for the integration.
26
- attr_reader :user
27
- # @return [Discorb::Integration::Account] The account for the integration.
28
- attr_reader :account
29
- # @return [Integer] The number of subscribers for the integration.
30
- attr_reader :subscriber_count
31
- # @return [Boolean] Whether the integration is revoked.
32
- attr_reader :revoked
33
- alias revoked? revoked
34
- # @return [Discorb::Application] The application for the integration.
35
- attr_reader :application
36
-
37
- # @!attribute [r] guild
38
- # @macro client_cache
39
- # @return [Discorb::Guild] The guild this integration is in.
40
-
41
- # @private
42
- # @return [{Integer => String}] The map of the expire behavior.
43
- EXPIRE_BEHAVIOR = {
44
- 0 => :remove_role,
45
- 1 => :kick,
46
- }.freeze
47
-
48
- #
49
- # Initialize a new integration.
50
- # @private
51
- #
52
- # @param [Discorb::Client] client The client.
53
- # @param [Hash] data The data of the welcome screen.
54
- # @param [Discorb::Guild] guild The guild this integration is in.
55
- #
56
- def initialize(client, data, guild_id)
57
- @client = client
58
- @data = data
59
- @guild_id = guild_id
60
- _set_data(data)
61
- end
62
-
63
- def guild
64
- @client.guilds[@guild_id]
65
- end
66
-
67
- #
68
- # Delete the integration.
69
- # @async
70
- #
71
- # @param [String] reason The reason for deleting the integration.
72
- #
73
- # @return [Async::Task<void>] The task.
74
- #
75
- def delete(reason: nil)
76
- Async do
77
- @client.http.request(
78
- Route.new("/guilds/#{@guild}/integrations/#{@id}", "//guilds/:guild_id/integrations/:integration_id",
79
- :delete), {}, audit_log_reason: reason
80
- ).wait
81
- end
82
- end
83
-
84
- alias destroy delete
85
-
86
- private
87
-
88
- def _set_data(data)
89
- @id = Snowflake.new(data[:id])
90
- @type = data[:type].to_sym
91
- @enabled = data[:enabled]
92
- @syncing = data[:syncing]
93
- @role_id = Snowflake.new(data[:role_id])
94
- @enable_emoticons = data[:enable_emoticons]
95
- @expire_behavior = EXPIRE_BEHAVIOR[data[:expire_behavior]]
96
- @expire_grace_period = data[:expire_grace_period]
97
- @user = @client.users[data[:user][:id]] or Discorb::User.new(@client, data[:user])
98
- @account = Account.new(data[:account])
99
- @subscriber_count = data[:subscriber_count]
100
- @revoked = data[:revoked]
101
- @application = data[:application] and Application.new(@client, data[:application])
102
- end
103
-
104
- #
105
- # Represents an account for an integration.
106
- #
107
- class Account < DiscordModel
108
- # @return [String] The ID of the account.
109
- attr_reader :id
110
- # @return [String] The name of the account.
111
- attr_reader :name
112
-
113
- #
114
- # Initialize a new account.
115
- # @private
116
- #
117
- # @param [Hash] data The data from Discord.
118
- #
119
- def initialize(data)
120
- @id = data[:id]
121
- @name = data[:name]
122
- end
123
- end
124
-
125
- #
126
- # Represents an application for an integration.
127
- #
128
- class Application < DiscordModel
129
- # @return [Discorb::Snowflake] The ID of the application.
130
- attr_reader :id
131
- # @return [String] The name of the application.
132
- attr_reader :name
133
- # @return [Asset] The icon of the application.
134
- # @return [nil] If the application has no icon.
135
- attr_reader :icon
136
- # @return [String] The description of the application.
137
- attr_reader :description
138
- # @return [String] The summary of the application.
139
- attr_reader :summary
140
- # @return [Discorb::User] The bot user associated with the application.
141
- # @return [nil] If the application has no bot user.
142
- attr_reader :bot
143
-
144
- #
145
- # Initialize a new application.
146
- # @private
147
- #
148
- # @param [Discorb::Client] client The client.
149
- # @param [Hash] data The data from Discord.
150
- #
151
- def initialize(client, data)
152
- @id = Snowflake.new(data[:id])
153
- @name = data[:name]
154
- @icon = data[:icon] && Asset.new(self, data[:icon])
155
- @description = data[:description]
156
- @summary = data[:summary]
157
- @bot = data[:bot] and client.users[data[:bot][:id]] || Discorb::User.new(client, data[:bot])
158
- end
159
- end
160
- end
161
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a integration.
6
+ #
7
+ class Integration < DiscordModel
8
+ # @return [Discorb::Snowflake] The ID of the integration.
9
+ attr_reader :id
10
+ # @return [Symbol] The type of integration.
11
+ attr_reader :type
12
+ # @return [Boolean] Whether the integration is enabled.
13
+ attr_reader :enabled
14
+ alias enabled? enabled
15
+ # @return [Boolean] Whether the integration is syncing.
16
+ attr_reader :syncing
17
+ alias syncing? syncing
18
+ # @return [Boolean] Whether the integration is enabled emoticons.
19
+ attr_reader :enable_emoticons
20
+ alias enable_emoticons? enable_emoticons
21
+ # @return [:remove_role, :kick] The behavior of the integration when it expires.
22
+ attr_reader :expire_behavior
23
+ # @return [Integer] The grace period of the integration.
24
+ attr_reader :expire_grace_period
25
+ # @return [Discorb::User] The user for the integration.
26
+ attr_reader :user
27
+ # @return [Discorb::Integration::Account] The account for the integration.
28
+ attr_reader :account
29
+ # @return [Integer] The number of subscribers for the integration.
30
+ attr_reader :subscriber_count
31
+ # @return [Boolean] Whether the integration is revoked.
32
+ attr_reader :revoked
33
+ alias revoked? revoked
34
+ # @return [Discorb::Application] The application for the integration.
35
+ attr_reader :application
36
+
37
+ # @!attribute [r] guild
38
+ # @macro client_cache
39
+ # @return [Discorb::Guild] The guild this integration is in.
40
+
41
+ # @private
42
+ # @return [{Integer => String}] The map of the expire behavior.
43
+ EXPIRE_BEHAVIOR = { 0 => :remove_role, 1 => :kick }.freeze
44
+
45
+ #
46
+ # Initialize a new integration.
47
+ # @private
48
+ #
49
+ # @param [Discorb::Client] client The client.
50
+ # @param [Hash] data The data of the welcome screen.
51
+ # @param [Discorb::Guild] guild The guild this integration is in.
52
+ #
53
+ def initialize(client, data, guild_id)
54
+ @client = client
55
+ @data = data
56
+ @guild_id = guild_id
57
+ _set_data(data)
58
+ end
59
+
60
+ def guild
61
+ @client.guilds[@guild_id]
62
+ end
63
+
64
+ #
65
+ # Delete the integration.
66
+ # @async
67
+ #
68
+ # @param [String] reason The reason for deleting the integration.
69
+ #
70
+ # @return [Async::Task<void>] The task.
71
+ #
72
+ def delete(reason: nil)
73
+ Async do
74
+ @client
75
+ .http
76
+ .request(
77
+ Route.new(
78
+ "/guilds/#{@guild}/integrations/#{@id}",
79
+ "//guilds/:guild_id/integrations/:integration_id",
80
+ :delete
81
+ ),
82
+ {},
83
+ audit_log_reason: reason
84
+ )
85
+ .wait
86
+ end
87
+ end
88
+
89
+ alias destroy delete
90
+
91
+ private
92
+
93
+ def _set_data(data)
94
+ @id = Snowflake.new(data[:id])
95
+ @type = data[:type].to_sym
96
+ @enabled = data[:enabled]
97
+ @syncing = data[:syncing]
98
+ @role_id = Snowflake.new(data[:role_id])
99
+ @enable_emoticons = data[:enable_emoticons]
100
+ @expire_behavior = EXPIRE_BEHAVIOR[data[:expire_behavior]]
101
+ @expire_grace_period = data[:expire_grace_period]
102
+ @user = @client.users[data[:user][:id]] or
103
+ Discorb::User.new(@client, data[:user])
104
+ @account = Account.new(data[:account])
105
+ @subscriber_count = data[:subscriber_count]
106
+ @revoked = data[:revoked]
107
+ @application = data[:application] and
108
+ Application.new(@client, data[:application])
109
+ end
110
+
111
+ #
112
+ # Represents an account for an integration.
113
+ #
114
+ class Account < DiscordModel
115
+ # @return [String] The ID of the account.
116
+ attr_reader :id
117
+ # @return [String] The name of the account.
118
+ attr_reader :name
119
+
120
+ #
121
+ # Initialize a new account.
122
+ # @private
123
+ #
124
+ # @param [Hash] data The data from Discord.
125
+ #
126
+ def initialize(data)
127
+ @id = data[:id]
128
+ @name = data[:name]
129
+ end
130
+ end
131
+
132
+ #
133
+ # Represents an application for an integration.
134
+ #
135
+ class Application < DiscordModel
136
+ # @return [Discorb::Snowflake] The ID of the application.
137
+ attr_reader :id
138
+ # @return [String] The name of the application.
139
+ attr_reader :name
140
+ # @return [Asset] The icon of the application.
141
+ # @return [nil] If the application has no icon.
142
+ attr_reader :icon
143
+ # @return [String] The description of the application.
144
+ attr_reader :description
145
+ # @return [String] The summary of the application.
146
+ attr_reader :summary
147
+ # @return [Discorb::User] The bot user associated with the application.
148
+ # @return [nil] If the application has no bot user.
149
+ attr_reader :bot
150
+
151
+ #
152
+ # Initialize a new application.
153
+ # @private
154
+ #
155
+ # @param [Discorb::Client] client The client.
156
+ # @param [Hash] data The data from Discord.
157
+ #
158
+ def initialize(client, data)
159
+ @id = Snowflake.new(data[:id])
160
+ @name = data[:name]
161
+ @icon = data[:icon] && Asset.new(self, data[:icon])
162
+ @description = data[:description]
163
+ @summary = data[:summary]
164
+ @bot = data[:bot] and
165
+ client.users[data[:bot][:id]] || Discorb::User.new(client, data[:bot])
166
+ end
167
+ end
168
+ end
169
+ end
@@ -1,163 +1,161 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- # Represents intents.
5
- class Intents
6
- # @private
7
- # @return [{Symbol => Integer}] The mapping of intent names to bit values.
8
- INTENT_BITS = {
9
- guilds: 1 << 0,
10
- members: 1 << 1,
11
- bans: 1 << 2,
12
- emojis: 1 << 3,
13
- integrations: 1 << 4,
14
- webhooks: 1 << 5,
15
- invites: 1 << 6,
16
- voice_states: 1 << 7,
17
- presences: 1 << 8,
18
- messages: 1 << 9,
19
- reactions: 1 << 10,
20
- typing: 1 << 11,
21
- dm_messages: 1 << 12,
22
- dm_reactions: 1 << 13,
23
- dm_typing: 1 << 14,
24
- message_content: 1 << 15,
25
- scheduled_events: 1 << 16,
26
- automod_configuration: 1 << 20,
27
- automod_execution: 1 << 21,
28
- }.freeze
29
-
30
- #
31
- # Create new intents object with default (no members and presence) intents.
32
- #
33
- # @param guilds [Boolean] Whether guild related events are enabled.
34
- # @param members [Boolean] Whether guild members related events are enabled.
35
- # @param bans [Boolean] Whether guild ban related events are enabled.
36
- # @param emojis [Boolean] Whether guild emojis related events are enabled.
37
- # @param integrations [Boolean] Whether guild integration related events are enabled.
38
- # @param webhooks [Boolean] Whether guild webhooks related events are enabled.
39
- # @param invites [Boolean] Whether guild invite related events are enabled.
40
- # @param voice_states [Boolean] Whether guild voice state related events are enabled.
41
- # @param presences [Boolean] Whether guild presences related events are enabled.
42
- # @param messages [Boolean] Whether guild messages related events are enabled.
43
- # @param reactions [Boolean] Whether guild reaction related events are enabled.
44
- # @param dm_messages [Boolean] Whether dm messages related events are enabled.
45
- # @param dm_reactions [Boolean] Whether dm reactions related events are enabled.
46
- # @param dm_typing [Boolean] Whether dm typing related events are enabled.
47
- # @param message_content [Boolean] Whether message content will be sent with events.
48
- # @param scheduled_events [Boolean] Whether events related scheduled events are enabled.
49
- # @param automod_configuration [Boolean] Whether automod configuration related events are enabled.
50
- # @param automod_execution [Boolean] Whether automod execution related events are enabled.
51
- # @note You must enable privileged intents to use `members` and/or `presences` intents.
52
- # @note Message Content Intent is not required to use `message_content` intents for now,
53
- # this will be required in September 1, 2022. [Learn More](https://support-dev.discord.com/hc/en-us/articles/4404772028055).
54
- # You should specify `message_content` intent for preventing unexpected changes in the future.
55
- #
56
- def initialize(
57
- guilds: true,
58
- members: false,
59
- bans: true,
60
- emojis: true,
61
- integrations: true,
62
- webhooks: true,
63
- invites: true,
64
- voice_states: true,
65
- presences: false,
66
- messages: true,
67
- reactions: true,
68
- typing: true,
69
- dm_messages: true,
70
- dm_reactions: true,
71
- dm_typing: true,
72
- message_content: nil,
73
- scheduled_events: true,
74
- automod_configuration: true,
75
- automod_execution: true
76
- )
77
- @raw_value = {
78
- guilds: guilds,
79
- members: members,
80
- bans: bans,
81
- emojis: emojis,
82
- integrations: integrations,
83
- webhooks: webhooks,
84
- invites: invites,
85
- voice_states: voice_states,
86
- presences: presences,
87
- messages: messages,
88
- reactions: reactions,
89
- typing: typing,
90
- dm_messages: dm_messages,
91
- dm_reactions: dm_reactions,
92
- dm_typing: dm_typing,
93
- message_content: message_content,
94
- scheduled_events: scheduled_events,
95
- automod_configuration: automod_configuration,
96
- automod_execution: automod_execution,
97
- }
98
- end
99
-
100
- #
101
- # (see Flag#method_missing)
102
- #
103
- def method_missing(name, args = nil)
104
- if @raw_value.key?(name)
105
- @raw_value[name]
106
- elsif name.end_with?("=") && @raw_value.key?(name[0..-2].to_sym)
107
- raise ArgumentError, "true/false expected" unless args.is_a?(TrueClass) || args.is_a?(FalseClass)
108
-
109
- @raw_value[name[0..-2].to_sym] = args
110
- else
111
- super
112
- end
113
- end
114
-
115
- def respond_to_missing?(name, include_private)
116
- @raw_value.key?(name) ? true : super
117
- end
118
-
119
- # Returns value of the intent.
120
- # @return [Integer] The value of the intent.
121
- def value
122
- res = 0
123
- INTENT_BITS.each do |intent, bit|
124
- res += bit if @raw_value[intent]
125
- end
126
- res
127
- end
128
-
129
- def inspect
130
- "#<#{self.class} value=#{value}>"
131
- end
132
-
133
- def to_h
134
- @raw_value
135
- end
136
-
137
- class << self
138
- # Create new intent object from raw value.
139
- # @param value [Integer] The value of the intent.
140
- def from_value(value)
141
- raw_value = {}
142
- INTENT_BITS.each do |intent, bit|
143
- raw_value[intent] = value & bit != 0
144
- end
145
- new(**raw_value)
146
- end
147
-
148
- # Create new intent object with default values.
149
- # This will return intents without members and presence.
150
- alias default new
151
-
152
- # Create new intent object with all intents.
153
- def all
154
- from_value(INTENT_BITS.values.reduce(:+))
155
- end
156
-
157
- # Create new intent object with no intents.
158
- def none
159
- from_value(0)
160
- end
161
- end
162
- end
163
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ # Represents intents.
5
+ class Intents
6
+ # @private
7
+ # @return [{Symbol => Integer}] The mapping of intent names to bit values.
8
+ INTENT_BITS = {
9
+ guilds: 1 << 0,
10
+ members: 1 << 1,
11
+ bans: 1 << 2,
12
+ emojis: 1 << 3,
13
+ integrations: 1 << 4,
14
+ webhooks: 1 << 5,
15
+ invites: 1 << 6,
16
+ voice_states: 1 << 7,
17
+ presences: 1 << 8,
18
+ messages: 1 << 9,
19
+ reactions: 1 << 10,
20
+ typing: 1 << 11,
21
+ dm_messages: 1 << 12,
22
+ dm_reactions: 1 << 13,
23
+ dm_typing: 1 << 14,
24
+ message_content: 1 << 15,
25
+ scheduled_events: 1 << 16,
26
+ automod_configuration: 1 << 20,
27
+ automod_execution: 1 << 21
28
+ }.freeze
29
+
30
+ #
31
+ # Create new intents object with default (no members and presence) intents.
32
+ #
33
+ # @param guilds [Boolean] Whether guild related events are enabled.
34
+ # @param members [Boolean] Whether guild members related events are enabled.
35
+ # @param bans [Boolean] Whether guild ban related events are enabled.
36
+ # @param emojis [Boolean] Whether guild emojis related events are enabled.
37
+ # @param integrations [Boolean] Whether guild integration related events are enabled.
38
+ # @param webhooks [Boolean] Whether guild webhooks related events are enabled.
39
+ # @param invites [Boolean] Whether guild invite related events are enabled.
40
+ # @param voice_states [Boolean] Whether guild voice state related events are enabled.
41
+ # @param presences [Boolean] Whether guild presences related events are enabled.
42
+ # @param messages [Boolean] Whether guild messages related events are enabled.
43
+ # @param reactions [Boolean] Whether guild reaction related events are enabled.
44
+ # @param dm_messages [Boolean] Whether dm messages related events are enabled.
45
+ # @param dm_reactions [Boolean] Whether dm reactions related events are enabled.
46
+ # @param dm_typing [Boolean] Whether dm typing related events are enabled.
47
+ # @param message_content [Boolean] Whether message content will be sent with events.
48
+ # @param scheduled_events [Boolean] Whether events related scheduled events are enabled.
49
+ # @param automod_configuration [Boolean] Whether automod configuration related events are enabled.
50
+ # @param automod_execution [Boolean] Whether automod execution related events are enabled.
51
+ # @note You must enable privileged intents to use `members` and/or `presences` intents.
52
+ # @note Message Content Intent is not required to use `message_content` intents for now,
53
+ # this will be required in September 1, 2022. [Learn More](https://support-dev.discord.com/hc/en-us/articles/4404772028055).
54
+ # You should specify `message_content` intent for preventing unexpected changes in the future.
55
+ #
56
+ def initialize(
57
+ guilds: true,
58
+ members: false,
59
+ bans: true,
60
+ emojis: true,
61
+ integrations: true,
62
+ webhooks: true,
63
+ invites: true,
64
+ voice_states: true,
65
+ presences: false,
66
+ messages: true,
67
+ reactions: true,
68
+ typing: true,
69
+ dm_messages: true,
70
+ dm_reactions: true,
71
+ dm_typing: true,
72
+ message_content: nil,
73
+ scheduled_events: true,
74
+ automod_configuration: true,
75
+ automod_execution: true
76
+ )
77
+ @raw_value = {
78
+ guilds: guilds,
79
+ members: members,
80
+ bans: bans,
81
+ emojis: emojis,
82
+ integrations: integrations,
83
+ webhooks: webhooks,
84
+ invites: invites,
85
+ voice_states: voice_states,
86
+ presences: presences,
87
+ messages: messages,
88
+ reactions: reactions,
89
+ typing: typing,
90
+ dm_messages: dm_messages,
91
+ dm_reactions: dm_reactions,
92
+ dm_typing: dm_typing,
93
+ message_content: message_content,
94
+ scheduled_events: scheduled_events,
95
+ automod_configuration: automod_configuration,
96
+ automod_execution: automod_execution
97
+ }
98
+ end
99
+
100
+ #
101
+ # (see Flag#method_missing)
102
+ #
103
+ def method_missing(name, args = nil)
104
+ if @raw_value.key?(name)
105
+ @raw_value[name]
106
+ elsif name.end_with?("=") && @raw_value.key?(name[0..-2].to_sym)
107
+ unless args.is_a?(TrueClass) || args.is_a?(FalseClass)
108
+ raise ArgumentError, "true/false expected"
109
+ end
110
+
111
+ @raw_value[name[0..-2].to_sym] = args
112
+ else
113
+ super
114
+ end
115
+ end
116
+
117
+ def respond_to_missing?(name, include_private)
118
+ @raw_value.key?(name) ? true : super
119
+ end
120
+
121
+ # Returns value of the intent.
122
+ # @return [Integer] The value of the intent.
123
+ def value
124
+ res = 0
125
+ INTENT_BITS.each { |intent, bit| res += bit if @raw_value[intent] }
126
+ res
127
+ end
128
+
129
+ def inspect
130
+ "#<#{self.class} value=#{value}>"
131
+ end
132
+
133
+ def to_h
134
+ @raw_value
135
+ end
136
+
137
+ class << self
138
+ # Create new intent object from raw value.
139
+ # @param value [Integer] The value of the intent.
140
+ def from_value(value)
141
+ raw_value = {}
142
+ INTENT_BITS.each { |intent, bit| raw_value[intent] = value & bit != 0 }
143
+ new(**raw_value)
144
+ end
145
+
146
+ # Create new intent object with default values.
147
+ # This will return intents without members and presence.
148
+ alias default new
149
+
150
+ # Create new intent object with all intents.
151
+ def all
152
+ from_value(INTENT_BITS.values.reduce(:+))
153
+ end
154
+
155
+ # Create new intent object with no intents.
156
+ def none
157
+ from_value(0)
158
+ end
159
+ end
160
+ end
161
+ end