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
data/lib/discorb/common.rb
CHANGED
@@ -4,7 +4,9 @@ module Discorb
|
|
4
4
|
# @return [String] The API base URL.
|
5
5
|
API_BASE_URL = "https://discord.com/api/v10"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.15.
|
7
|
+
VERSION = "0.15.1"
|
8
|
+
# @return [Array<Integer>] The version array of discorb.
|
9
|
+
VERSION_ARRAY = VERSION.split(".").map(&:to_i).freeze
|
8
10
|
# @return [String] The user agent for the bot.
|
9
11
|
USER_AGENT = "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}".freeze
|
10
12
|
|
@@ -25,8 +27,11 @@ module Discorb
|
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
|
30
|
+
def inspect
|
31
|
+
"#<#{self.class}: #{@id}>"
|
32
|
+
end
|
29
33
|
|
34
|
+
# @private
|
30
35
|
def hash
|
31
36
|
@id.hash
|
32
37
|
end
|
@@ -37,7 +42,12 @@ module Discorb
|
|
37
42
|
#
|
38
43
|
# @see https://discord.com/developers/docs/reference#snowflakes Official Discord API docs
|
39
44
|
class Snowflake < String
|
45
|
+
#
|
46
|
+
# Initialize new snowflake.
|
40
47
|
# @private
|
48
|
+
#
|
49
|
+
# @param [#to_s] value The value of the snowflake.
|
50
|
+
#
|
41
51
|
def initialize(value)
|
42
52
|
@value = value.to_i
|
43
53
|
super(@value.to_s)
|
@@ -92,7 +102,7 @@ module Discorb
|
|
92
102
|
end
|
93
103
|
|
94
104
|
def timestamp
|
95
|
-
Time.at(((@value >> 22) + 1_420_070_400_000) / 1000)
|
105
|
+
Time.at(((@value >> 22) + 1_420_070_400_000) / 1000.0)
|
96
106
|
end
|
97
107
|
|
98
108
|
def worker_id
|
@@ -127,6 +137,10 @@ module Discorb
|
|
127
137
|
@method = method
|
128
138
|
end
|
129
139
|
|
140
|
+
def inspect
|
141
|
+
"#<#{self.class} #{self.identifier}>"
|
142
|
+
end
|
143
|
+
|
130
144
|
def hash
|
131
145
|
@url.hash
|
132
146
|
end
|
@@ -21,7 +21,9 @@ module Discorb
|
|
21
21
|
attr_accessor :disabled
|
22
22
|
alias disabled? disabled
|
23
23
|
|
24
|
-
@
|
24
|
+
# @private
|
25
|
+
# @return [{Symbol => Integer}] The mapping of button styles.
|
26
|
+
STYLES = {
|
25
27
|
primary: 1,
|
26
28
|
secondary: 2,
|
27
29
|
success: 3,
|
@@ -59,7 +61,7 @@ module Discorb
|
|
59
61
|
{
|
60
62
|
type: 2,
|
61
63
|
label: @label,
|
62
|
-
style:
|
64
|
+
style: STYLES[@style],
|
63
65
|
url: @url,
|
64
66
|
emoji: @emoji&.to_hash,
|
65
67
|
disabled: @disabled,
|
@@ -68,7 +70,7 @@ module Discorb
|
|
68
70
|
{
|
69
71
|
type: 2,
|
70
72
|
label: @label,
|
71
|
-
style:
|
73
|
+
style: STYLES[@style],
|
72
74
|
custom_id: @custom_id,
|
73
75
|
emoji: @emoji&.to_hash,
|
74
76
|
disabled: @disabled,
|
@@ -81,9 +83,6 @@ module Discorb
|
|
81
83
|
end
|
82
84
|
|
83
85
|
class << self
|
84
|
-
# @private
|
85
|
-
attr_reader :styles
|
86
|
-
|
87
86
|
#
|
88
87
|
# Creates a new button from a hash.
|
89
88
|
#
|
@@ -122,22 +122,8 @@ module Discorb
|
|
122
122
|
}
|
123
123
|
end
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
case emoji
|
128
|
-
when UnicodeEmoji
|
129
|
-
{
|
130
|
-
id: nil,
|
131
|
-
name: emoji.to_s,
|
132
|
-
animated: false,
|
133
|
-
}
|
134
|
-
when CustomEmoji
|
135
|
-
{
|
136
|
-
id: emoji.id,
|
137
|
-
name: emoji.name,
|
138
|
-
animated: emoji.animated?,
|
139
|
-
}
|
140
|
-
end
|
125
|
+
def inspect
|
126
|
+
"#<#{self.class} #{@label}: #{@value}>"
|
141
127
|
end
|
142
128
|
|
143
129
|
class << self
|
data/lib/discorb/dictionary.rb
CHANGED
data/lib/discorb/embed.rb
CHANGED
@@ -59,7 +59,12 @@ module Discorb
|
|
59
59
|
@type = "rich"
|
60
60
|
end
|
61
61
|
|
62
|
+
#
|
63
|
+
# Initialize embed from hash.
|
62
64
|
# @private
|
65
|
+
#
|
66
|
+
# @param [Hash] data The hash data to initialize embed.
|
67
|
+
#
|
63
68
|
def initialize_hash(data)
|
64
69
|
@title = data[:title]
|
65
70
|
@description = data[:description]
|
@@ -118,10 +123,21 @@ module Discorb
|
|
118
123
|
inst
|
119
124
|
end
|
120
125
|
|
126
|
+
#
|
127
|
+
# Represents an entry in embed.
|
128
|
+
# @abstract
|
129
|
+
# @private
|
130
|
+
#
|
131
|
+
class Entry
|
132
|
+
def inspect
|
133
|
+
"#<#{self.class}>"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
121
137
|
#
|
122
138
|
# Represents an author of embed.
|
123
139
|
#
|
124
|
-
class Author
|
140
|
+
class Author < Entry
|
125
141
|
# @return [String] The name of author.
|
126
142
|
attr_accessor :name
|
127
143
|
# @return [String, nil] The url of author.
|
@@ -160,7 +176,7 @@ module Discorb
|
|
160
176
|
#
|
161
177
|
# Represemts a footer of embed.
|
162
178
|
#
|
163
|
-
class Footer
|
179
|
+
class Footer < Entry
|
164
180
|
attr_accessor :text, :icon
|
165
181
|
|
166
182
|
#
|
@@ -191,7 +207,7 @@ module Discorb
|
|
191
207
|
#
|
192
208
|
# Represents a field of embed.
|
193
209
|
#
|
194
|
-
class Field
|
210
|
+
class Field < Entry
|
195
211
|
# @return [String] The name of field.
|
196
212
|
attr_accessor :name
|
197
213
|
# @return [String] The value of field.
|
@@ -230,7 +246,7 @@ module Discorb
|
|
230
246
|
#
|
231
247
|
# Represents an image of embed.
|
232
248
|
#
|
233
|
-
class Image
|
249
|
+
class Image < Entry
|
234
250
|
# @return [String] The url of image.
|
235
251
|
attr_accessor :url
|
236
252
|
# @return [String] The proxy url of image.
|
@@ -274,7 +290,7 @@ module Discorb
|
|
274
290
|
#
|
275
291
|
# Represents a thumbnail of embed.
|
276
292
|
#
|
277
|
-
class Thumbnail
|
293
|
+
class Thumbnail < Entry
|
278
294
|
# @return [String] The url of thumbnail.
|
279
295
|
attr_accessor :url
|
280
296
|
# @return [String] The proxy url of thumbnail.
|
@@ -318,7 +334,7 @@ module Discorb
|
|
318
334
|
#
|
319
335
|
# Represents a video of embed.
|
320
336
|
#
|
321
|
-
class Video
|
337
|
+
class Video < Entry
|
322
338
|
# @return [String] The url of video.
|
323
339
|
attr_reader :url
|
324
340
|
# @return [String] The proxy url of video.
|
@@ -328,7 +344,12 @@ module Discorb
|
|
328
344
|
# @return [Integer] The width of video.
|
329
345
|
attr_reader :width
|
330
346
|
|
347
|
+
#
|
348
|
+
# Initialize a new Video object.
|
331
349
|
# @private
|
350
|
+
#
|
351
|
+
# @param [Hash] data The data of video.
|
352
|
+
#
|
332
353
|
def initialize(data)
|
333
354
|
@url = data[:url]
|
334
355
|
@proxy_url = data[:proxy_url]
|
@@ -340,13 +361,18 @@ module Discorb
|
|
340
361
|
#
|
341
362
|
# Represents a provider of embed.
|
342
363
|
#
|
343
|
-
class Provider
|
364
|
+
class Provider < Entry
|
344
365
|
# @return [String] The name of provider.
|
345
366
|
attr_reader :name
|
346
367
|
# @return [String] The url of provider.
|
347
368
|
attr_reader :url
|
348
369
|
|
370
|
+
#
|
371
|
+
# Initialize a new Provider object.
|
349
372
|
# @private
|
373
|
+
#
|
374
|
+
# @param [Hash] data The data of provider.
|
375
|
+
#
|
350
376
|
def initialize(data)
|
351
377
|
@name = data[:name]
|
352
378
|
@url = data[:url]
|
data/lib/discorb/emoji.rb
CHANGED
@@ -44,7 +44,14 @@ module Discorb
|
|
44
44
|
# @!attribute [r] roles?
|
45
45
|
# @return [Boolean] whether or not this emoji is restricted to certain roles.
|
46
46
|
|
47
|
+
#
|
48
|
+
# Initialize a new custom emoji.
|
47
49
|
# @private
|
50
|
+
#
|
51
|
+
# @param [Discorb::Client] client The client that owns this emoji.
|
52
|
+
# @param [Discorb::Guild] guild The guild that owns this emoji.
|
53
|
+
# @param [Hash] data The data of the emoji.
|
54
|
+
#
|
48
55
|
def initialize(client, guild, data)
|
49
56
|
@client = client
|
50
57
|
@guild = guild
|
@@ -121,7 +128,12 @@ module Discorb
|
|
121
128
|
|
122
129
|
alias destroy! delete!
|
123
130
|
|
131
|
+
#
|
132
|
+
# Converts the object to a hash.
|
124
133
|
# @private
|
134
|
+
#
|
135
|
+
# @return [Hash] The hash represents the object.
|
136
|
+
#
|
125
137
|
def to_hash
|
126
138
|
{
|
127
139
|
name: @name,
|
@@ -135,7 +147,7 @@ module Discorb
|
|
135
147
|
def _set_data(data)
|
136
148
|
@id = Snowflake.new(data[:id])
|
137
149
|
@name = data[:name]
|
138
|
-
@roles = data[:role] ? data[:role].map { |r| Role.new(@client, r) } : []
|
150
|
+
@roles = data[:role] ? data[:role].map { |r| Role.new(@client, guild, r) } : []
|
139
151
|
@user = User.new(@client, data[:user]) if data[:user]
|
140
152
|
@require_colons = data[:require_colons]
|
141
153
|
@managed = data[:managed]
|
@@ -158,7 +170,12 @@ module Discorb
|
|
158
170
|
attr_reader :deleted
|
159
171
|
alias deleted? deleted
|
160
172
|
|
173
|
+
#
|
174
|
+
# Initialize a new partial custom emoji.
|
161
175
|
# @private
|
176
|
+
#
|
177
|
+
# @param [Hash] data The data of the emoji.
|
178
|
+
#
|
162
179
|
def initialize(data)
|
163
180
|
@id = Snowflake.new(data[:id])
|
164
181
|
@name = data[:name]
|
@@ -200,7 +217,12 @@ module Discorb
|
|
200
217
|
# @return [Integer] The skin tone of the emoji.
|
201
218
|
attr_reader :skin_tone
|
202
219
|
|
203
|
-
#
|
220
|
+
#
|
221
|
+
# Initialize a new unicode emoji.
|
222
|
+
#
|
223
|
+
# @param [String] name The name of the emoji.
|
224
|
+
# @param [Integer] tone The skin tone of the emoji.
|
225
|
+
#
|
204
226
|
def initialize(name, tone: 0)
|
205
227
|
if EmojiTable::DISCORD_TO_UNICODE.key?(name)
|
206
228
|
@name = name
|
@@ -232,7 +254,12 @@ module Discorb
|
|
232
254
|
"#<#{self.class} :#{@name}:>"
|
233
255
|
end
|
234
256
|
|
257
|
+
#
|
258
|
+
# Converts the object to a hash.
|
235
259
|
# @private
|
260
|
+
#
|
261
|
+
# @return [Hash] The hash represents the object.
|
262
|
+
#
|
236
263
|
def to_hash
|
237
264
|
{
|
238
265
|
name: @value,
|
data/lib/discorb/emoji_table.rb
CHANGED
data/lib/discorb/error.rb
CHANGED
@@ -42,7 +42,10 @@ module Discorb
|
|
42
42
|
# @return [Net::HTTPResponse] the HTTP response.
|
43
43
|
attr_reader :response
|
44
44
|
|
45
|
+
#
|
46
|
+
# Initialize a new instance of the HTTPError class.
|
45
47
|
# @private
|
48
|
+
#
|
46
49
|
def initialize(resp, data)
|
47
50
|
@code = data[:code]
|
48
51
|
@response = resp
|
@@ -54,7 +57,10 @@ module Discorb
|
|
54
57
|
# Represents a 400 error.
|
55
58
|
#
|
56
59
|
class BadRequestError < HTTPError
|
60
|
+
#
|
61
|
+
# Initialize a new instance of the BadRequestError class.
|
57
62
|
# @private
|
63
|
+
#
|
58
64
|
def initialize(resp, data)
|
59
65
|
@code = data[:code]
|
60
66
|
@response = resp
|
@@ -62,7 +68,7 @@ module Discorb
|
|
62
68
|
[
|
63
69
|
data[:message] + " (#{@code})", enumerate_errors(data[:errors])
|
64
70
|
.map { |ek, ev| "#{ek}=>#{ev}" }
|
65
|
-
.join("\n")
|
71
|
+
.join("\n"),
|
66
72
|
].join("\n")
|
67
73
|
)
|
68
74
|
end
|
data/lib/discorb/event.rb
CHANGED
@@ -4,20 +4,26 @@ module Discorb
|
|
4
4
|
# Represents an event in guild.
|
5
5
|
#
|
6
6
|
class ScheduledEvent < DiscordModel
|
7
|
-
@
|
7
|
+
# @private
|
8
|
+
# @return [{Integer => Symbol}] The mapping of privacy level.
|
9
|
+
PRIVACY_LEVEL = {
|
8
10
|
2 => :guild_only,
|
9
|
-
}
|
10
|
-
@
|
11
|
+
}.freeze
|
12
|
+
# @private
|
13
|
+
# @return [{Integer => Symbol}] The mapping of status.
|
14
|
+
STATUS = {
|
11
15
|
1 => :scheduled,
|
12
16
|
2 => :active,
|
13
17
|
3 => :completed,
|
14
18
|
4 => :canceled,
|
15
|
-
}
|
16
|
-
@
|
19
|
+
}.freeze
|
20
|
+
# @private
|
21
|
+
# @return [{Integer => Symbol}] The mapping of entity_type.
|
22
|
+
ENTITY_TYPE = {
|
17
23
|
1 => :stage_instance,
|
18
24
|
2 => :voice,
|
19
25
|
3 => :external,
|
20
|
-
}
|
26
|
+
}.freeze
|
21
27
|
|
22
28
|
# @!visibility private
|
23
29
|
def initialize(client, data)
|
@@ -36,6 +42,10 @@ module Discorb
|
|
36
42
|
def initialize(data)
|
37
43
|
@location = data[:location]
|
38
44
|
end
|
45
|
+
|
46
|
+
def inspect
|
47
|
+
"#<#{self.class.name} #{@name}>"
|
48
|
+
end
|
39
49
|
end
|
40
50
|
|
41
51
|
# @return [Discorb::Snowflake] The ID of the event.
|
@@ -132,10 +142,10 @@ module Discorb
|
|
132
142
|
description: description,
|
133
143
|
scheduled_start_time: start_time.iso8601,
|
134
144
|
scheduled_end_time: end_time&.iso8601,
|
135
|
-
privacy_level: Discorb::ScheduledEvent.
|
145
|
+
privacy_level: Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level) || Discorb::Unset,
|
136
146
|
channel_id: channel&.id,
|
137
|
-
entity_type: Discorb::ScheduledEvent.
|
138
|
-
status: Discorb::ScheduledEvent.
|
147
|
+
entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:stage_instance),
|
148
|
+
status: Discorb::ScheduledEvent::STATUS.key(status) || Discorb::Unset,
|
139
149
|
}.reject { |_, v| v == Discorb::Unset }
|
140
150
|
when :voice
|
141
151
|
raise ArgumentError, "channel must be provided for voice events" unless channel
|
@@ -144,10 +154,10 @@ module Discorb
|
|
144
154
|
description: description,
|
145
155
|
scheduled_start_time: start_time.iso8601,
|
146
156
|
scheduled_end_time: end_time&.iso8601,
|
147
|
-
privacy_level: Discorb::ScheduledEvent.
|
157
|
+
privacy_level: Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level) || Discorb::Unset,
|
148
158
|
channel_id: channel&.id,
|
149
|
-
entity_type: Discorb::ScheduledEvent.
|
150
|
-
status: Discorb::ScheduledEvent.
|
159
|
+
entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:voice),
|
160
|
+
status: Discorb::ScheduledEvent::STATUS.key(status) || Discorb::Unset,
|
151
161
|
}.reject { |_, v| v == Discorb::Unset }
|
152
162
|
when :external
|
153
163
|
raise ArgumentError, "location must be provided for external events" unless location
|
@@ -158,12 +168,12 @@ module Discorb
|
|
158
168
|
channel_id: nil,
|
159
169
|
scheduled_start_time: start_time.iso8601,
|
160
170
|
scheduled_end_time: end_time.iso8601,
|
161
|
-
privacy_level: Discorb::ScheduledEvent.
|
162
|
-
entity_type: Discorb::ScheduledEvent.
|
171
|
+
privacy_level: Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level) || Discorb::Unset,
|
172
|
+
entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:external),
|
163
173
|
entity_metadata: {
|
164
174
|
location: location,
|
165
175
|
},
|
166
|
-
status: Discorb::ScheduledEvent.
|
176
|
+
status: Discorb::ScheduledEvent::STATUS.key(status) || Discorb::Unset,
|
167
177
|
}.reject { |_, v| v == Discorb::Unset }
|
168
178
|
else
|
169
179
|
raise ArgumentError, "Invalid scheduled event type: #{type}"
|
@@ -264,8 +274,8 @@ module Discorb
|
|
264
274
|
@scheduled_start_time = Time.iso8601(data[:scheduled_start_time])
|
265
275
|
@scheduled_end_time = data[:scheduled_end_time] && Time.iso8601(data[:scheduled_end_time])
|
266
276
|
@privacy_level = :guild_only # data[:privacy_level]
|
267
|
-
@status =
|
268
|
-
@entity_type =
|
277
|
+
@status = STATUS[data[:status]]
|
278
|
+
@entity_type = ENTITY_TYPE[data[:entity_type]]
|
269
279
|
@entity_id = data[:entity_id] && Snowflake.new(data[:entity_id])
|
270
280
|
@entity_metadata = data[:entity_metadata] && Metadata.new(data[:entity_metadata])
|
271
281
|
@creator = @client.users[@creator_id] || (data[:creator] && User.new(@client, data[:creator]))
|
data/lib/discorb/gateway.rb
CHANGED
@@ -14,12 +14,22 @@ module Discorb
|
|
14
14
|
module Gateway
|
15
15
|
#
|
16
16
|
# Represents an event.
|
17
|
+
# @abstract
|
17
18
|
#
|
18
19
|
class GatewayEvent
|
20
|
+
#
|
21
|
+
# Initializes a new instance of the GatewayEvent class.
|
19
22
|
# @private
|
23
|
+
#
|
24
|
+
# @param [Hash] data The data of the event.
|
25
|
+
#
|
20
26
|
def initialize(data)
|
21
27
|
@data = data
|
22
28
|
end
|
29
|
+
|
30
|
+
def inspect
|
31
|
+
"#<#{self.class}>"
|
32
|
+
end
|
23
33
|
end
|
24
34
|
|
25
35
|
#
|
@@ -61,7 +71,13 @@ module Discorb
|
|
61
71
|
alias reactor fired_by
|
62
72
|
alias from fired_by
|
63
73
|
|
74
|
+
#
|
75
|
+
# Initializes a new instance of the ReactionEvent class.
|
64
76
|
# @private
|
77
|
+
#
|
78
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
79
|
+
# @param [Hash] data The data of the event.
|
80
|
+
#
|
65
81
|
def initialize(client, data)
|
66
82
|
@client = client
|
67
83
|
@data = data
|
@@ -121,7 +137,14 @@ module Discorb
|
|
121
137
|
# @macro client_cache
|
122
138
|
# @return [Discorb::User] The user associated with the integration.
|
123
139
|
|
140
|
+
#
|
141
|
+
# Initialize a new instance of the IntegrationDeleteEvent class.
|
124
142
|
# @private
|
143
|
+
#
|
144
|
+
#
|
145
|
+
# @param [Hash] data The data of the event.
|
146
|
+
#
|
147
|
+
#
|
125
148
|
def initialize(_client, data)
|
126
149
|
@id = Snowflake.new(data[:id])
|
127
150
|
@guild_id = data[:guild_id]
|
@@ -157,7 +180,13 @@ module Discorb
|
|
157
180
|
# @return [Discorb::Message] The message the reaction was sent in.
|
158
181
|
attr_reader :message
|
159
182
|
|
183
|
+
#
|
184
|
+
# Initialize a new instance of the ReactionRemoveAllEvent class.
|
160
185
|
# @private
|
186
|
+
#
|
187
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
188
|
+
# @param [Hash] data The data of the event.
|
189
|
+
#
|
161
190
|
def initialize(client, data)
|
162
191
|
@client = client
|
163
192
|
@data = data
|
@@ -207,7 +236,13 @@ module Discorb
|
|
207
236
|
# @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
|
208
237
|
attr_reader :emoji
|
209
238
|
|
239
|
+
#
|
240
|
+
# Initialize a new instance of the ReactionRemoveEmojiEvent class.
|
210
241
|
# @private
|
242
|
+
#
|
243
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
244
|
+
# @param [Hash] data The data of the event.
|
245
|
+
#
|
211
246
|
def initialize(client, data)
|
212
247
|
@client = client
|
213
248
|
@data = data
|
@@ -246,7 +281,13 @@ module Discorb
|
|
246
281
|
attr_reader :guild
|
247
282
|
# @return [Discorb::ScheduledEvent] The scheduled event.
|
248
283
|
attr_reader :scheduled_event
|
284
|
+
#
|
285
|
+
# Initialize a new instance of the ScheduledEventUserEvent class.
|
249
286
|
# @private
|
287
|
+
#
|
288
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
289
|
+
# @param [Hash] data The data of the event.
|
290
|
+
#
|
250
291
|
def initialize(client, data)
|
251
292
|
@client = client
|
252
293
|
@scheduled_event_id = Snowflake.new(data[:scheduled_event_id])
|
@@ -342,7 +383,13 @@ module Discorb
|
|
342
383
|
# @macro client_cache
|
343
384
|
# @return [Discorb::Guild] The guild the message was sent in.
|
344
385
|
|
386
|
+
#
|
387
|
+
# Initialize a new instance of the UnknownDeleteBulkMessage class.
|
345
388
|
# @private
|
389
|
+
#
|
390
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
391
|
+
# @param [Hash] data The data of the event.
|
392
|
+
#
|
346
393
|
def initialize(client, id, data)
|
347
394
|
@client = client
|
348
395
|
@id = id
|
@@ -374,7 +421,13 @@ module Discorb
|
|
374
421
|
# @macro client_cache
|
375
422
|
# @return [Discorb::Guild] The guild the message was sent in.
|
376
423
|
|
424
|
+
#
|
425
|
+
# Initialize a new instance of the InviteDeleteEvent class.
|
377
426
|
# @private
|
427
|
+
#
|
428
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
429
|
+
# @param [Hash] data The data of the event.
|
430
|
+
#
|
378
431
|
def initialize(client, data)
|
379
432
|
@client = client
|
380
433
|
@data = data
|
@@ -392,21 +445,6 @@ module Discorb
|
|
392
445
|
end
|
393
446
|
end
|
394
447
|
|
395
|
-
#
|
396
|
-
# Represents a `GUILD_INTEGRATIONS_UPDATE` event.
|
397
|
-
#
|
398
|
-
class GuildIntegrationsUpdateEvent < GatewayEvent
|
399
|
-
def initialize(client, data)
|
400
|
-
@client = client
|
401
|
-
@data = data
|
402
|
-
@guild_id = Snowflake.new(data[:guild_id])
|
403
|
-
end
|
404
|
-
|
405
|
-
def guild
|
406
|
-
@client.guilds[@guild_id]
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|
410
448
|
#
|
411
449
|
# Represents a `TYPING_START` event.
|
412
450
|
#
|
@@ -430,7 +468,13 @@ module Discorb
|
|
430
468
|
# @macro client_cache
|
431
469
|
# @return [Discorb::Member, Discorb::User] The member or user that started typing.
|
432
470
|
|
471
|
+
#
|
472
|
+
# Initialize a new instance of the TypingStartEvent class.
|
433
473
|
# @private
|
474
|
+
#
|
475
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
476
|
+
# @param [Hash] data The data of the event.
|
477
|
+
#
|
434
478
|
def initialize(client, data)
|
435
479
|
@client = client
|
436
480
|
@data = data
|
@@ -507,7 +551,13 @@ module Discorb
|
|
507
551
|
# @macro client_cache
|
508
552
|
# @return [Discorb::Guild] The guild where the webhook was updated.
|
509
553
|
|
554
|
+
#
|
555
|
+
# Initialize a new instance of the WebhooksUpdateEvent class.
|
510
556
|
# @private
|
557
|
+
#
|
558
|
+
# @param [Discorb::Client] client The client that instantiated the object.
|
559
|
+
# @param [Hash] data The data of the event.
|
560
|
+
#
|
511
561
|
def initialize(client, data)
|
512
562
|
@client = client
|
513
563
|
@data = data
|
@@ -718,7 +768,7 @@ module Discorb
|
|
718
768
|
ready
|
719
769
|
end
|
720
770
|
elsif @guilds.has?(data[:id])
|
721
|
-
@guilds[data[:id]].send(:_set_data, data)
|
771
|
+
@guilds[data[:id]].send(:_set_data, data, true)
|
722
772
|
dispatch(:guild_available, guild)
|
723
773
|
else
|
724
774
|
guild = Guild.new(self, data, true)
|
@@ -741,7 +791,7 @@ module Discorb
|
|
741
791
|
return @log.warn "Unknown guild id #{data[:id]}, ignoring" unless (guild = @guilds.delete(data[:id]))
|
742
792
|
|
743
793
|
dispatch(:guild_delete, guild)
|
744
|
-
if
|
794
|
+
if data[:unavailable]
|
745
795
|
dispatch(:guild_destroy, guild)
|
746
796
|
else
|
747
797
|
dispatch(:guild_leave, guild)
|
@@ -815,7 +865,7 @@ module Discorb
|
|
815
865
|
|
816
866
|
if (member = thread.members[data[:id]])
|
817
867
|
old = ThreadChannel::Member.new(self, member.instance_variable_get(:@data))
|
818
|
-
member._set_data
|
868
|
+
member.send(:_set_data, data)
|
819
869
|
else
|
820
870
|
old = nil
|
821
871
|
member = ThreadChannel::Member.new(self, data)
|
@@ -902,8 +952,7 @@ module Discorb
|
|
902
952
|
guild.emojis.delete(emoji)
|
903
953
|
end
|
904
954
|
when "GUILD_INTEGRATIONS_UPDATE"
|
905
|
-
|
906
|
-
# Currently not implemented
|
955
|
+
dispatch(:guild_integrations_update, @guilds[data[:guild_id]])
|
907
956
|
when "INTEGRATION_CREATE"
|
908
957
|
dispatch(:integration_create, Integration.new(self, data, data[:guild_id]))
|
909
958
|
when "INTEGRATION_UPDATE"
|
@@ -1095,7 +1144,7 @@ module Discorb
|
|
1095
1144
|
(target_reaction = target_message.reactions.find { |r| data[:emoji][:id].nil? ? r.name == data[:emoji][:name] : r.id == data[:emoji][:id] })
|
1096
1145
|
target_message.reactions.delete(target_reaction)
|
1097
1146
|
end
|
1098
|
-
dispatch(:reaction_remove_emoji, ReactionRemoveEmojiEvent.new(data))
|
1147
|
+
dispatch(:reaction_remove_emoji, ReactionRemoveEmojiEvent.new(self, data))
|
1099
1148
|
when "TYPING_START"
|
1100
1149
|
dispatch(:typing_start, TypingStartEvent.new(self, data))
|
1101
1150
|
when "INTERACTION_CREATE"
|
@@ -1179,6 +1228,10 @@ module Discorb
|
|
1179
1228
|
@closed = false
|
1180
1229
|
end
|
1181
1230
|
|
1231
|
+
def inspect
|
1232
|
+
"<#{self.class.name} #{io.fileno}>"
|
1233
|
+
end
|
1234
|
+
|
1182
1235
|
def closed?
|
1183
1236
|
@closed
|
1184
1237
|
end
|
@@ -1191,10 +1244,14 @@ module Discorb
|
|
1191
1244
|
end
|
1192
1245
|
|
1193
1246
|
def force_close
|
1194
|
-
|
1247
|
+
io.close
|
1195
1248
|
@closed = true
|
1196
1249
|
end
|
1197
1250
|
|
1251
|
+
def io
|
1252
|
+
@framer.instance_variable_get(:@stream).instance_variable_get(:@io).instance_variable_get(:@io).instance_variable_get(:@io)
|
1253
|
+
end
|
1254
|
+
|
1198
1255
|
def parse(buffer)
|
1199
1256
|
# noop
|
1200
1257
|
buffer.to_s
|