discorb 0.15.0 → 0.15.1
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -2
- data/Changelog.md +9 -0
- data/Rakefile +6 -0
- data/docs/events.md +50 -0
- data/lib/discorb/allowed_mentions.rb +7 -0
- data/lib/discorb/app_command/command.rb +64 -2
- data/lib/discorb/application.rb +16 -7
- data/lib/discorb/asset.rb +9 -0
- data/lib/discorb/attachment.rb +16 -1
- data/lib/discorb/audit_logs.rb +42 -4
- data/lib/discorb/channel.rb +42 -3
- data/lib/discorb/client.rb +4 -0
- data/lib/discorb/common.rb +17 -3
- data/lib/discorb/components/button.rb +5 -6
- data/lib/discorb/components/select_menu.rb +2 -16
- data/lib/discorb/dictionary.rb +2 -0
- data/lib/discorb/embed.rb +33 -7
- data/lib/discorb/emoji.rb +29 -2
- data/lib/discorb/emoji_table.rb +1 -1
- data/lib/discorb/error.rb +7 -1
- data/lib/discorb/event.rb +27 -17
- data/lib/discorb/gateway.rb +79 -22
- data/lib/discorb/gateway_requests.rb +4 -7
- data/lib/discorb/guild.rb +67 -33
- data/lib/discorb/guild_template.rb +24 -3
- data/lib/discorb/http.rb +7 -2
- data/lib/discorb/integration.rb +23 -8
- data/lib/discorb/intents.rb +7 -7
- data/lib/discorb/interaction/autocomplete.rb +2 -2
- data/lib/discorb/interaction/command.rb +32 -3
- data/lib/discorb/interaction/components.rb +14 -1
- data/lib/discorb/interaction/response.rb +12 -0
- data/lib/discorb/interaction/root.rb +15 -0
- data/lib/discorb/invite.rb +11 -7
- data/lib/discorb/log.rb +4 -4
- data/lib/discorb/member.rb +21 -0
- data/lib/discorb/message.rb +9 -1
- data/lib/discorb/message_meta.rb +38 -9
- data/lib/discorb/permission.rb +14 -5
- data/lib/discorb/presence.rb +41 -8
- data/lib/discorb/rate_limit.rb +5 -0
- data/lib/discorb/reaction.rb +6 -0
- data/lib/discorb/role.rb +12 -0
- data/lib/discorb/sticker.rb +22 -14
- data/lib/discorb/user.rb +11 -0
- data/lib/discorb/voice_state.rb +20 -2
- data/lib/discorb/webhook.rb +52 -1
- data/lib/discorb.rb +3 -1
- data/sig/discorb.rbs +6850 -5836
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bc9c7d6433e9e093a0d58d821ed97e3f001d63224c9f65eb1693a2ee3d16f7d
|
4
|
+
data.tar.gz: daff87553c1996cbc1a68765ee3df54947f46b7660fc1a16f0a17a0e0660e2c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dceaba51436368feeb9e99bc4afda5cea9ac45aa0525bb44cdd33c427fef6c6617d17bf1a56b27acac137df05b4d6f27395e22883ce574e4e48d3e7a8ca05a13
|
7
|
+
data.tar.gz: 81622ca789eee2f8c55b4fd98e7c0bdc602d164247602508c8b041757d61fcb77f659d01142db8a8c16b9dd6e6cc402ebf9f45cf881e787a77449ba4831b8376
|
data/.rubocop.yml
CHANGED
@@ -10,10 +10,14 @@ Metrics:
|
|
10
10
|
Enabled: false
|
11
11
|
|
12
12
|
Style/TrailingCommaInHashLiteral: # Disabled for rufo
|
13
|
-
|
13
|
+
EnforcedStyleForMultiline: consistent_comma
|
14
|
+
|
15
|
+
Style/TrailingCommaInArrayLiteral: # Disabled for rufo
|
16
|
+
EnforcedStyleForMultiline: consistent_comma
|
14
17
|
|
15
18
|
Style/StringLiterals: # Disabled for rufo
|
16
|
-
Enabled:
|
19
|
+
Enabled: true
|
20
|
+
EnforcedStyle: double_quotes
|
17
21
|
|
18
22
|
Style/TrailingCommaInArguments: # Disabled for rufo
|
19
23
|
Enabled: false
|
data/Changelog.md
CHANGED
@@ -6,6 +6,15 @@
|
|
6
6
|
|
7
7
|
## v0.15
|
8
8
|
|
9
|
+
### v0.15.1
|
10
|
+
|
11
|
+
- Add: Add `Member#can_manage?`
|
12
|
+
- Add: Add `Discorb::VERSION_ARRAY`
|
13
|
+
- Fix: `Snowflake#timestamp` includes milliseconds now
|
14
|
+
- Fix: `TextChannel#create_invite` will no longer return `ArgumentError`
|
15
|
+
- Fix: Connection will not closed with 4001 when `Client#update_presence`
|
16
|
+
is called
|
17
|
+
|
9
18
|
### v0.15.0
|
10
19
|
|
11
20
|
- Add: Migrate to API v10
|
data/Rakefile
CHANGED
data/docs/events.md
CHANGED
@@ -487,6 +487,46 @@ Fires when an invitation is deleted.
|
|
487
487
|
|
488
488
|
### Interaction events
|
489
489
|
|
490
|
+
#### `interaction_create(interaction)`
|
491
|
+
|
492
|
+
Fires when an interaction is created. This will fire for all interactions.
|
493
|
+
|
494
|
+
| Parameter | Type | Description |
|
495
|
+
| ---------- | ----- | ----------- |
|
496
|
+
| `interaction` | {Discorb::Interaction}| The created interaction. |
|
497
|
+
|
498
|
+
#### `application_command(interaction)`
|
499
|
+
|
500
|
+
Fires when an application command is used.
|
501
|
+
|
502
|
+
| Parameter | Type | Description |
|
503
|
+
| ---------- | ----- | ----------- |
|
504
|
+
| `interaction` | {Discorb::CommandInteraction}| The created interaction. |
|
505
|
+
|
506
|
+
#### `slash_command(interaction)`
|
507
|
+
|
508
|
+
Fires when a slash command is used.
|
509
|
+
|
510
|
+
| Parameter | Type | Description |
|
511
|
+
| ---------- | ----- | ----------- |
|
512
|
+
| `interaction` | {Discorb::CommandInteraction::SlashCommand}| The created interaction. |
|
513
|
+
|
514
|
+
#### `message_command(interaction)`
|
515
|
+
|
516
|
+
Fires when a message command is used.
|
517
|
+
|
518
|
+
| Parameter | Type | Description |
|
519
|
+
| ---------- | ----- | ----------- |
|
520
|
+
| `interaction` | {Discorb::CommandInteraction::MessageMenuCommand}| The created interaction. |
|
521
|
+
|
522
|
+
#### `user_command(interaction)`
|
523
|
+
|
524
|
+
Fires when a user command is used.
|
525
|
+
|
526
|
+
| Parameter | Type | Description |
|
527
|
+
| ---------- | ----- | ----------- |
|
528
|
+
| `interaction` | {Discorb::CommandInteraction::UserMenuCommand}| The created interaction. |
|
529
|
+
|
490
530
|
#### `button_click(interaction)`
|
491
531
|
|
492
532
|
Fires when a button is clicked.
|
@@ -503,6 +543,16 @@ Fires when a select menu is selected.
|
|
503
543
|
| ---------- | ----- | ----------- |
|
504
544
|
|`interaction`| {Discorb::MessageComponentInteraction::SelectMenu}| The interaction object. |
|
505
545
|
|
546
|
+
#### `form_submit(interaction)`
|
547
|
+
|
548
|
+
Fires when a form is submitted.
|
549
|
+
|
550
|
+
| Parameter | Type | Description |
|
551
|
+
| ---------- | ----- | ----------- |
|
552
|
+
| `interaction` | {Discorb::ModalInteraction} | The interaction object. |
|
553
|
+
|
554
|
+
#### `slash_command
|
555
|
+
|
506
556
|
### Voice events
|
507
557
|
|
508
558
|
Because it's big, it's documented in {file:docs/voice_events.md}.
|
@@ -32,7 +32,14 @@ module Discorb
|
|
32
32
|
"#<#{self.class} @everyone=#{@everyone} @roles=#{@roles} @users=#{@users} @replied_user=#{@replied_user}>"
|
33
33
|
end
|
34
34
|
|
35
|
+
#
|
36
|
+
# Converts the object to a hash.
|
35
37
|
# @private
|
38
|
+
#
|
39
|
+
# @param [Discorb::AllowedMentions, nil] other The object to merge.
|
40
|
+
#
|
41
|
+
# @return [Hash] The hash.
|
42
|
+
#
|
36
43
|
def to_hash(other = nil)
|
37
44
|
payload = {
|
38
45
|
parse: %w[everyone roles users],
|
@@ -23,24 +23,39 @@ module Discorb
|
|
23
23
|
# @return [Discorb::Dictionary{Discorb::Snowflake, :global => Discorb::Snowflake}] The ID mapping.
|
24
24
|
attr_reader :id_map
|
25
25
|
|
26
|
-
@
|
26
|
+
# @private
|
27
|
+
# @return [{Integer => Symbol}] The mapping of raw types to types.
|
28
|
+
TYPES = {
|
27
29
|
1 => :chat_input,
|
28
30
|
2 => :user,
|
29
31
|
3 => :message,
|
30
32
|
}.freeze
|
31
33
|
|
34
|
+
#
|
35
|
+
# Initialize a new command.
|
32
36
|
# @private
|
37
|
+
#
|
38
|
+
# @param [String] name The name of the command.
|
39
|
+
# @param [Array<#to_s>] guild_ids The guild ids that the command is enabled in.
|
40
|
+
# @param [Proc] block The block of the command.
|
41
|
+
# @param [:chat_input, :user, :message] type The type of the command.
|
42
|
+
#
|
33
43
|
def initialize(name, guild_ids, block, type)
|
34
44
|
@name = name
|
35
45
|
@guild_ids = guild_ids&.map(&:to_s)
|
36
46
|
@block = block
|
37
47
|
@raw_type = type
|
38
|
-
@type = Discorb::ApplicationCommand::Command
|
48
|
+
@type = Discorb::ApplicationCommand::Command::TYPES[type]
|
39
49
|
@type_raw = type
|
40
50
|
@id_map = Discorb::Dictionary.new
|
41
51
|
end
|
42
52
|
|
53
|
+
#
|
54
|
+
# Changes the self pointer to the given object.
|
43
55
|
# @private
|
56
|
+
#
|
57
|
+
# @param [Object] instance The object to change the self pointer to.
|
58
|
+
#
|
44
59
|
def replace_block(instance)
|
45
60
|
current_block = @block.dup
|
46
61
|
@block = proc do |*args|
|
@@ -48,7 +63,12 @@ module Discorb
|
|
48
63
|
end
|
49
64
|
end
|
50
65
|
|
66
|
+
#
|
67
|
+
# Converts the object to a hash.
|
51
68
|
# @private
|
69
|
+
#
|
70
|
+
# @return [Hash] The hash represents the object.
|
71
|
+
#
|
52
72
|
def to_hash
|
53
73
|
{
|
54
74
|
name: @name,
|
@@ -66,7 +86,18 @@ module Discorb
|
|
66
86
|
# @return [Hash{String => Hash}] The options of the command.
|
67
87
|
attr_reader :options
|
68
88
|
|
89
|
+
#
|
90
|
+
# Initialize a new slash command.
|
69
91
|
# @private
|
92
|
+
#
|
93
|
+
# @param [String] name The name of the command.
|
94
|
+
# @param [String] description The description of the command.
|
95
|
+
# @param [Hash{String => Hash}] options The options of the command.
|
96
|
+
# @param [Array<#to_s>] guild_ids The guild ids that the command is enabled in.
|
97
|
+
# @param [Proc] block The block of the command.
|
98
|
+
# @param [:chat_input, :user, :message] type The type of the command.
|
99
|
+
# @param [Discorb::ApplicationCommand::Command, nil] parent The parent command.
|
100
|
+
#
|
70
101
|
def initialize(name, description, options, guild_ids, block, type, parent)
|
71
102
|
super(name, guild_ids, block, type)
|
72
103
|
@description = description
|
@@ -85,7 +116,12 @@ module Discorb
|
|
85
116
|
(@parent + " " + @name).strip
|
86
117
|
end
|
87
118
|
|
119
|
+
#
|
120
|
+
# Converts the object to a hash.
|
88
121
|
# @private
|
122
|
+
#
|
123
|
+
# @return [Hash] The hash represents the object.
|
124
|
+
#
|
89
125
|
def to_hash
|
90
126
|
options_payload = options.map do |name, value|
|
91
127
|
ret = {
|
@@ -145,7 +181,16 @@ module Discorb
|
|
145
181
|
# @return [String] The description of the command.
|
146
182
|
attr_reader :description
|
147
183
|
|
184
|
+
#
|
185
|
+
# Initialize a new group command.
|
148
186
|
# @private
|
187
|
+
#
|
188
|
+
# @param [String] name The name of the command.
|
189
|
+
# @param [String] description The description of the command.
|
190
|
+
# @param [Array<#to_s>] guild_ids The guild ids that the command is enabled in.
|
191
|
+
# @param [:chat_input, :user, :message] type The type of the command.
|
192
|
+
# @param [Discorb::Client] client The client of the command.
|
193
|
+
#
|
149
194
|
def initialize(name, description, guild_ids, type, client)
|
150
195
|
super(name, guild_ids, block, type)
|
151
196
|
@description = description
|
@@ -196,13 +241,23 @@ module Discorb
|
|
196
241
|
@name
|
197
242
|
end
|
198
243
|
|
244
|
+
#
|
245
|
+
# Changes the self pointer to the given object.
|
199
246
|
# @private
|
247
|
+
#
|
248
|
+
# @param [Object] instance The object to change to.
|
249
|
+
#
|
200
250
|
def block_replace(instance)
|
201
251
|
super
|
202
252
|
@commands.each { |c| c.replace_block(instance) }
|
203
253
|
end
|
204
254
|
|
255
|
+
#
|
256
|
+
# Converts the object to a hash.
|
205
257
|
# @private
|
258
|
+
#
|
259
|
+
# @return [Hash] The hash represents the object.
|
260
|
+
#
|
206
261
|
def to_hash
|
207
262
|
options_payload = @commands.map do |command|
|
208
263
|
if command.is_a?(SlashCommand)
|
@@ -240,7 +295,14 @@ module Discorb
|
|
240
295
|
# @return [Array<Discorb::ApplicationCommand::Command::SlashCommand>] The subcommands of the command.
|
241
296
|
attr_reader :commands
|
242
297
|
|
298
|
+
#
|
299
|
+
# Initialize a new subcommand group.
|
243
300
|
# @private
|
301
|
+
#
|
302
|
+
# @param [String] name The name of the command.
|
303
|
+
# @param [String] description The description of the command.
|
304
|
+
# @param [Discorb::ApplicationCommand::Command::GroupCommand] parent The parent command.
|
305
|
+
# @param [Discorb::Client] client The client.
|
244
306
|
def initialize(name, description, parent, client)
|
245
307
|
super(name, description, [], 1, client)
|
246
308
|
|
data/lib/discorb/application.rb
CHANGED
@@ -29,7 +29,13 @@ module Discorb
|
|
29
29
|
alias bot_require_code_grant? bot_require_code_grant
|
30
30
|
# @return [Discorb::Application::Flag] The application's flags.
|
31
31
|
attr_reader :flags
|
32
|
+
#
|
33
|
+
# Initializes a new instance of the Application class.
|
32
34
|
# @private
|
35
|
+
#
|
36
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
37
|
+
# @param [Hash] data The data of the object.
|
38
|
+
#
|
33
39
|
def initialize(client, data)
|
34
40
|
@client = client
|
35
41
|
@data = data
|
@@ -97,7 +103,13 @@ module Discorb
|
|
97
103
|
# @return [Discorb::Application::Team::Member] The team's member.
|
98
104
|
attr_reader :members
|
99
105
|
|
106
|
+
#
|
107
|
+
# Initializes a new instance of the Team class.
|
100
108
|
# @private
|
109
|
+
#
|
110
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
111
|
+
# @param [Hash] data The data of the object.
|
112
|
+
#
|
101
113
|
def initialize(client, data)
|
102
114
|
@client = client
|
103
115
|
@id = Snowflake.new(data[:id])
|
@@ -142,7 +154,9 @@ module Discorb
|
|
142
154
|
# @!attribute [r] owner?
|
143
155
|
# @return [Boolean] Whether the member is the team's owner.
|
144
156
|
|
145
|
-
@
|
157
|
+
# @private
|
158
|
+
# @return [{Integer => Symbol}] The permission map.
|
159
|
+
MEMBERSHIP_STATE = {
|
146
160
|
1 => :invited,
|
147
161
|
2 => :accepted,
|
148
162
|
}.freeze
|
@@ -153,7 +167,7 @@ module Discorb
|
|
153
167
|
@team = team
|
154
168
|
@user = client.users[data[:user][:id]] || User.new(client, data[:user])
|
155
169
|
@team_id = Snowflake.new(data[:team_id])
|
156
|
-
@membership_state =
|
170
|
+
@membership_state = MEMBERSHIP_STATE[data[:membership_state]]
|
157
171
|
@permissions = data[:permissions].map(&:to_sym)
|
158
172
|
end
|
159
173
|
|
@@ -176,11 +190,6 @@ module Discorb
|
|
176
190
|
def ==(other)
|
177
191
|
super || @user == other
|
178
192
|
end
|
179
|
-
|
180
|
-
class << self
|
181
|
-
# @private
|
182
|
-
attr_reader :membership_state
|
183
|
-
end
|
184
193
|
end
|
185
194
|
end
|
186
195
|
end
|
data/lib/discorb/asset.rb
CHANGED
@@ -11,7 +11,13 @@ module Discorb
|
|
11
11
|
# @!attribute [r] animated?
|
12
12
|
# @return [Boolean] Whether the asset is animated.
|
13
13
|
|
14
|
+
#
|
15
|
+
# Initialize a new instance of the Asset class.
|
14
16
|
# @private
|
17
|
+
#
|
18
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
19
|
+
# @param [Hash] data The data of the object.
|
20
|
+
#
|
15
21
|
def initialize(target, hash, path: nil)
|
16
22
|
@hash = hash
|
17
23
|
@target = target
|
@@ -63,7 +69,10 @@ module Discorb
|
|
63
69
|
# @!attribute [r] animated?
|
64
70
|
# @return [false] For compatibility with {Asset}, always `false`.
|
65
71
|
|
72
|
+
#
|
73
|
+
# Initialize a new instance of the DefaultAvatar class.
|
66
74
|
# @private
|
75
|
+
#
|
67
76
|
def initialize(discriminator)
|
68
77
|
@discriminator = discriminator.to_s.rjust(4, "0")
|
69
78
|
end
|
data/lib/discorb/attachment.rb
CHANGED
@@ -33,6 +33,7 @@ module Discorb
|
|
33
33
|
# @return [:client, :discord] The attachment was created by.
|
34
34
|
attr_reader :created_by
|
35
35
|
# @private
|
36
|
+
# @return [Boolean] Whether the attachment will be closed after it is sent.
|
36
37
|
attr_reader :will_close
|
37
38
|
|
38
39
|
# @!attribute [r] image?
|
@@ -62,7 +63,10 @@ module Discorb
|
|
62
63
|
@created_by = :client
|
63
64
|
end
|
64
65
|
|
66
|
+
#
|
67
|
+
# Initializes the object from a hash.
|
65
68
|
# @private
|
69
|
+
#
|
66
70
|
def initialize_hash(data)
|
67
71
|
@id = Snowflake.new(data[:id])
|
68
72
|
@filename = data[:filename]
|
@@ -79,7 +83,18 @@ module Discorb
|
|
79
83
|
@content_type.start_with? "image/"
|
80
84
|
end
|
81
85
|
|
86
|
+
def inspect
|
87
|
+
if @created_by == :discord
|
88
|
+
"<#{self.class} #{@id}: #{@filename}>"
|
89
|
+
else
|
90
|
+
"<#{self.class} #{io.fileno}: #{@filename}>"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Creates a new file from a hash.
|
82
96
|
# @private
|
97
|
+
#
|
83
98
|
def self.from_hash(data)
|
84
99
|
inst = allocate
|
85
100
|
inst.initialize_hash(data)
|
@@ -93,7 +108,7 @@ module Discorb
|
|
93
108
|
# @param [String] filename The filename of the file. object_id of the string is used if not set.
|
94
109
|
# @param [String] content_type The content type of the file. If not set, it is guessed from the filename.
|
95
110
|
#
|
96
|
-
# @return [
|
111
|
+
# @return [Discorb::Attachment] The new file.
|
97
112
|
#
|
98
113
|
def self.from_string(string, filename = nil, content_type: nil, description: nil)
|
99
114
|
io = StringIO.new(string)
|
data/lib/discorb/audit_logs.rb
CHANGED
@@ -14,7 +14,10 @@ module Discorb
|
|
14
14
|
# @return [Array<Discorb::AuditLog::Entry>] The entries in this audit log.
|
15
15
|
attr_reader :entries
|
16
16
|
|
17
|
+
#
|
18
|
+
# Initializes a new instance of the AuditLog class.
|
17
19
|
# @private
|
20
|
+
#
|
18
21
|
def initialize(client, data, guild)
|
19
22
|
@client = client
|
20
23
|
@guild = guild
|
@@ -24,6 +27,10 @@ module Discorb
|
|
24
27
|
@entries = data[:audit_log_entries].map { |entry| AuditLog::Entry.new(@client, entry, guild.id) }
|
25
28
|
end
|
26
29
|
|
30
|
+
def inspect
|
31
|
+
"<#{self.class} #{@entries.length} entries>"
|
32
|
+
end
|
33
|
+
|
27
34
|
#
|
28
35
|
# Gets an entry from entries.
|
29
36
|
#
|
@@ -108,8 +115,11 @@ module Discorb
|
|
108
115
|
# @!attribute [r] user
|
109
116
|
# @return [Discorb::User] The user who performed the action.
|
110
117
|
|
118
|
+
#
|
119
|
+
# @return [{Integer => Symbol}] The map of events to their respective changes.
|
111
120
|
# @private
|
112
|
-
|
121
|
+
#
|
122
|
+
EVENTS = {
|
113
123
|
1 => :guild_update,
|
114
124
|
10 => :channel_create,
|
115
125
|
11 => :channel_update,
|
@@ -159,24 +169,30 @@ module Discorb
|
|
159
169
|
112 => :thread_delete,
|
160
170
|
}.freeze
|
161
171
|
|
172
|
+
#
|
173
|
+
# The converter for the change.
|
162
174
|
# @private
|
163
|
-
|
175
|
+
#
|
176
|
+
CONVERTERS = {
|
164
177
|
channel: ->(client, id, _guild_id) { client.channels[id] },
|
165
178
|
thread: ->(client, id, _guild_id) { client.channels[id] },
|
166
179
|
role: ->(client, id, guild_id) { client.guilds[guild_id]&.roles&.[](id) },
|
167
180
|
member: ->(client, id, guild_id) { client.guilds[guild_id]&.members&.[](id) },
|
168
181
|
guild: ->(client, id, _guild_id) { client.guilds[id] },
|
169
182
|
message: ->(client, id, _guild_id) { client.messages[id] },
|
170
|
-
}
|
183
|
+
}.freeze
|
171
184
|
|
185
|
+
#
|
186
|
+
# Initializes a new AuditLog entry.
|
172
187
|
# @private
|
188
|
+
#
|
173
189
|
def initialize(client, data, guild_id)
|
174
190
|
@client = client
|
175
191
|
@guild_id = Snowflake.new(guild_id)
|
176
192
|
@id = Snowflake.new(data[:id])
|
177
193
|
@user_id = Snowflake.new(data[:user_id])
|
178
194
|
@target_id = Snowflake.new(data[:target_id])
|
179
|
-
@type =
|
195
|
+
@type = EVENTS[data[:action_type]]
|
180
196
|
@target = self.class.converts[@type.to_s.split("_")[0].to_sym]&.call(client, @target_id, @gui)
|
181
197
|
@target ||= Snowflake.new(data[:target_id])
|
182
198
|
@changes = data[:changes] && Changes.new(data[:changes])
|
@@ -223,8 +239,11 @@ module Discorb
|
|
223
239
|
attr_reader :data
|
224
240
|
|
225
241
|
#
|
242
|
+
# Initializes a new changes object.
|
226
243
|
# @private
|
227
244
|
#
|
245
|
+
# @param [Hash] data The data to initialize with.
|
246
|
+
#
|
228
247
|
def initialize(data)
|
229
248
|
@data = data.to_h { |d| [d[:key].to_sym, d] }
|
230
249
|
@data.each do |k, v|
|
@@ -232,6 +251,9 @@ module Discorb
|
|
232
251
|
end
|
233
252
|
end
|
234
253
|
|
254
|
+
#
|
255
|
+
# Formats the changes into a string.
|
256
|
+
#
|
235
257
|
def inspect
|
236
258
|
"#<#{self.class} #{@data.length} changes>"
|
237
259
|
end
|
@@ -270,7 +292,10 @@ module Discorb
|
|
270
292
|
# @return [Object] The new value of the change.
|
271
293
|
attr_reader :new_value
|
272
294
|
|
295
|
+
#
|
296
|
+
# Initializes a new change object.
|
273
297
|
# @private
|
298
|
+
#
|
274
299
|
def initialize(data)
|
275
300
|
@key = data[:key].to_sym
|
276
301
|
method = case @key.to_s
|
@@ -298,10 +323,20 @@ module Discorb
|
|
298
323
|
@new_value.__send__(method, ...)
|
299
324
|
end
|
300
325
|
|
326
|
+
#
|
327
|
+
# Format the change into a string.
|
328
|
+
#
|
329
|
+
# @return [String] The string representation of the change.
|
330
|
+
#
|
301
331
|
def inspect
|
302
332
|
"#<#{self.class} #{@key.inspect} #{@old_value.inspect} -> #{@new_value.inspect}>"
|
303
333
|
end
|
304
334
|
|
335
|
+
#
|
336
|
+
# Whether the change responds to the given method.
|
337
|
+
#
|
338
|
+
# @return [Boolean] Whether the change responds to the given method.
|
339
|
+
#
|
305
340
|
def respond_to_missing?(method, include_private = false)
|
306
341
|
@new_value.respond_to?(method, include_private)
|
307
342
|
end
|
@@ -321,7 +356,10 @@ module Discorb
|
|
321
356
|
# @return [Discorb::Integration::Account] The account of the integration.
|
322
357
|
attr_reader :account
|
323
358
|
|
359
|
+
#
|
360
|
+
# Initializes a new integration object.
|
324
361
|
# @private
|
362
|
+
#
|
325
363
|
def initialize(data)
|
326
364
|
@id = Snowflake.new(data[:id])
|
327
365
|
@type = data[:type].to_sym
|
data/lib/discorb/channel.rb
CHANGED
@@ -19,7 +19,10 @@ module Discorb
|
|
19
19
|
@channel_type = nil
|
20
20
|
@subclasses = []
|
21
21
|
|
22
|
+
#
|
23
|
+
# Initializes a new instance of the Channel class.
|
22
24
|
# @private
|
25
|
+
#
|
23
26
|
def initialize(client, data, no_cache: false)
|
24
27
|
@client = client
|
25
28
|
@data = {}
|
@@ -44,12 +47,22 @@ module Discorb
|
|
44
47
|
"#<#{self.class} \"##{@name}\" id=#{@id}>"
|
45
48
|
end
|
46
49
|
|
50
|
+
#
|
51
|
+
# Returns the descendants of the Channel class.
|
47
52
|
# @private
|
53
|
+
#
|
48
54
|
def self.descendants
|
49
55
|
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
50
56
|
end
|
51
57
|
|
58
|
+
#
|
59
|
+
# Creates a new instance of the Channel class or instance of its descendants.
|
52
60
|
# @private
|
61
|
+
#
|
62
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
63
|
+
# @param [Hash] data The data of the object.
|
64
|
+
# @param [Boolean] no_cache Whether to disable cache the object.
|
65
|
+
#
|
53
66
|
def self.make_channel(client, data, no_cache: false)
|
54
67
|
descendants.each do |klass|
|
55
68
|
return klass.new(client, data, no_cache: no_cache) if !klass.channel_type.nil? && klass.channel_type == data[:type]
|
@@ -59,7 +72,10 @@ module Discorb
|
|
59
72
|
end
|
60
73
|
|
61
74
|
class << self
|
75
|
+
#
|
62
76
|
# @private
|
77
|
+
# @return [Integer] The type of the channel.
|
78
|
+
#
|
63
79
|
attr_reader :channel_type
|
64
80
|
end
|
65
81
|
|
@@ -67,7 +83,12 @@ module Discorb
|
|
67
83
|
self.class.channel_type
|
68
84
|
end
|
69
85
|
|
86
|
+
#
|
87
|
+
# Returns the channel id to request.
|
70
88
|
# @private
|
89
|
+
#
|
90
|
+
# @return [Async::Task<Discorb::Snowflake>] A task that resolves to the channel id.
|
91
|
+
#
|
71
92
|
def channel_id
|
72
93
|
Async do
|
73
94
|
@id
|
@@ -114,7 +135,7 @@ module Discorb
|
|
114
135
|
#
|
115
136
|
# @param [Discorb::GuildChannel] other The channel to compare.
|
116
137
|
#
|
117
|
-
# @return [-1, 1] -1 if the channel is at lower than the other, 1 if the channel is at highter than the other.
|
138
|
+
# @return [-1, 0, 1] -1 if the channel is at lower than the other, 1 if the channel is at highter than the other.
|
118
139
|
#
|
119
140
|
def <=>(other)
|
120
141
|
return 0 unless other.respond_to?(:position)
|
@@ -419,7 +440,7 @@ module Discorb
|
|
419
440
|
def fetch_invites
|
420
441
|
Async do
|
421
442
|
_resp, data = @client.http.request(Route.new("/channels/#{@id}/invites", "//channels/:channel_id/invites", :get)).wait
|
422
|
-
data.map { |invite| Invite.new(@client, invite) }
|
443
|
+
data.map { |invite| Invite.new(@client, invite, false) }
|
423
444
|
end
|
424
445
|
end
|
425
446
|
|
@@ -444,7 +465,7 @@ module Discorb
|
|
444
465
|
temporary: temporary,
|
445
466
|
unique: unique,
|
446
467
|
}, audit_log_reason: reason).wait
|
447
|
-
Invite.new(@client, data)
|
468
|
+
Invite.new(@client, data, false)
|
448
469
|
end
|
449
470
|
end
|
450
471
|
|
@@ -664,7 +685,10 @@ module Discorb
|
|
664
685
|
attr_reader :bitrate
|
665
686
|
# @return [Integer] The user limit of the voice channel.
|
666
687
|
attr_reader :user_limit
|
688
|
+
#
|
667
689
|
# @private
|
690
|
+
# @return [Discorb::Dictionary{Discorb::Snowflake => StageInstance}] The stage instances associated with the stage channel.
|
691
|
+
#
|
668
692
|
attr_reader :stage_instances
|
669
693
|
|
670
694
|
include Connectable
|
@@ -673,7 +697,10 @@ module Discorb
|
|
673
697
|
# @return [Discorb::StageInstance] The stage instance of the channel.
|
674
698
|
|
675
699
|
@channel_type = 13
|
700
|
+
#
|
701
|
+
# Initialize a new stage channel.
|
676
702
|
# @private
|
703
|
+
#
|
677
704
|
def initialize(...)
|
678
705
|
@stage_instances = Dictionary.new
|
679
706
|
super(...)
|
@@ -823,7 +850,14 @@ module Discorb
|
|
823
850
|
include Messageable
|
824
851
|
@channel_type = nil
|
825
852
|
|
853
|
+
#
|
854
|
+
# Initialize a new thread channel.
|
826
855
|
# @private
|
856
|
+
#
|
857
|
+
# @param [Discorb::Client] client The client.
|
858
|
+
# @param [Hash] data The data of the thread channel.
|
859
|
+
# @param [Boolean] no_cache Whether to disable the cache.
|
860
|
+
#
|
827
861
|
def initialize(client, data, no_cache: false)
|
828
862
|
@members = Dictionary.new
|
829
863
|
super
|
@@ -1113,7 +1147,12 @@ module Discorb
|
|
1113
1147
|
class DMChannel < Channel
|
1114
1148
|
include Messageable
|
1115
1149
|
|
1150
|
+
#
|
1151
|
+
# Returns the channel id to request.
|
1116
1152
|
# @private
|
1153
|
+
#
|
1154
|
+
# @return [Async::Task<Discorb::Snowflake>] A task that resolves to the channel id.
|
1155
|
+
#
|
1117
1156
|
def channel_id
|
1118
1157
|
Async do
|
1119
1158
|
@id
|
data/lib/discorb/client.rb
CHANGED
@@ -54,7 +54,10 @@ module Discorb
|
|
54
54
|
attr_reader :session_id
|
55
55
|
# @return [Hash{String => Discorb::Extension}] The loaded extensions.
|
56
56
|
attr_reader :extensions
|
57
|
+
#
|
57
58
|
# @private
|
59
|
+
# @return [Hash{Discorb::Snowflake => Discorb::ApplicationCommand::Command}] The commands on the top level.
|
60
|
+
#
|
58
61
|
attr_reader :bottom_commands
|
59
62
|
|
60
63
|
#
|
@@ -309,6 +312,7 @@ module Discorb
|
|
309
312
|
activities: [],
|
310
313
|
status: status,
|
311
314
|
since: nil,
|
315
|
+
afk: nil,
|
312
316
|
}
|
313
317
|
payload[:activities] = [activity.to_hash] unless activity.nil?
|
314
318
|
payload[:status] = status unless status.nil?
|