discorb 0.19.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +10 -0
- data/Rakefile +482 -454
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -398
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -266
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -621
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -804
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -336
- data/lib/discorb/interaction/root.rb +271 -257
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -291
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/application.rbs +2 -0
- data/sig/discorb/automod.rbs +10 -1
- data/sig/discorb/guild.rbs +2 -0
- data/sig/discorb/message.rbs +2 -0
- data/sig/discorb/user.rbs +22 -20
- metadata +2 -2
data/lib/discorb/integration.rb
CHANGED
@@ -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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# @
|
51
|
-
#
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
@
|
95
|
-
@
|
96
|
-
@
|
97
|
-
@
|
98
|
-
@
|
99
|
-
@
|
100
|
-
@
|
101
|
-
@
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
# @
|
116
|
-
|
117
|
-
# @
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
# @return [
|
137
|
-
attr_reader :
|
138
|
-
# @return [String] The
|
139
|
-
attr_reader :
|
140
|
-
# @return [
|
141
|
-
# @return [nil] If the application has no
|
142
|
-
attr_reader :
|
143
|
-
|
144
|
-
|
145
|
-
#
|
146
|
-
|
147
|
-
#
|
148
|
-
# @
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
data/lib/discorb/intents.rb
CHANGED
@@ -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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|