discorb 0.12.4 → 0.13.3
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_main.yml +1 -0
- data/.github/workflows/build_version.yml +4 -3
- data/.github/workflows/crowdin.yml +32 -0
- data/.gitignore +3 -1
- data/.yardopts +2 -0
- data/Changelog.md +412 -378
- data/Gemfile +5 -1
- data/README.md +2 -2
- data/Rakefile +131 -1
- data/crowdin.yml +2 -0
- data/discorb.gemspec +12 -1
- data/docs/Examples.md +2 -0
- data/docs/application_command.md +16 -12
- data/docs/cli/irb.md +2 -0
- data/docs/cli/new.md +2 -0
- data/docs/cli/run.md +3 -1
- data/docs/cli/setup.md +4 -2
- data/docs/cli.md +2 -0
- data/docs/events.md +59 -5
- data/docs/extension.md +2 -2
- data/docs/faq.md +4 -2
- data/docs/license.md +2 -0
- data/docs/tutorial.md +4 -3
- data/docs/voice_events.md +2 -0
- data/lib/discorb/app_command.rb +8 -7
- data/lib/discorb/application.rb +32 -2
- data/lib/discorb/asset.rb +1 -1
- data/lib/discorb/audit_logs.rb +28 -16
- data/lib/discorb/channel.rb +140 -81
- data/lib/discorb/client.rb +17 -19
- data/lib/discorb/common.rb +28 -1
- data/lib/discorb/components.rb +12 -0
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +4 -0
- data/lib/discorb/emoji.rb +9 -7
- data/lib/discorb/emoji_table.rb +3891 -3891
- data/lib/discorb/event.rb +266 -24
- data/lib/discorb/event_handler.rb +39 -0
- data/lib/discorb/exe/show.rb +2 -0
- data/lib/discorb/extension.rb +5 -5
- data/lib/discorb/file.rb +4 -0
- data/lib/discorb/flag.rb +5 -1
- data/lib/discorb/gateway.rb +97 -17
- data/lib/discorb/gateway_requests.rb +4 -0
- data/lib/discorb/guild.rb +169 -82
- data/lib/discorb/guild_template.rb +12 -9
- data/lib/discorb/http.rb +82 -44
- data/lib/discorb/image.rb +7 -5
- data/lib/discorb/integration.rb +33 -1
- data/lib/discorb/intents.rb +8 -3
- data/lib/discorb/interaction/response.rb +27 -25
- data/lib/discorb/interaction/root.rb +8 -0
- data/lib/discorb/invite.rb +3 -2
- data/lib/discorb/log.rb +4 -0
- data/lib/discorb/member.rb +42 -13
- data/lib/discorb/message.rb +32 -17
- data/lib/discorb/modules.rb +19 -26
- data/lib/discorb/permission.rb +4 -0
- data/lib/discorb/rate_limit.rb +6 -2
- data/lib/discorb/role.rb +15 -11
- data/lib/discorb/sticker.rb +17 -12
- data/lib/discorb/user.rb +8 -7
- data/lib/discorb/voice_state.rb +8 -5
- data/lib/discorb/webhook.rb +38 -47
- data/lib/discorb.rb +2 -2
- data/po/yard.pot +7775 -5157
- data/sig/discorb.rbs +3317 -3820
- data/template-replace/scripts/locale_ja.rb +62 -0
- metadata +18 -5
data/lib/discorb/event.rb
CHANGED
@@ -1,35 +1,277 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Discorb
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
class ScheduledEvent < DiscordModel
|
3
|
+
@privacy_level = {
|
4
|
+
2 => :guild_only,
|
5
|
+
}
|
6
|
+
@status = {
|
7
|
+
1 => :scheduled,
|
8
|
+
2 => :active,
|
9
|
+
3 => :completed,
|
10
|
+
4 => :canceled,
|
11
|
+
}
|
12
|
+
@entity_type = {
|
13
|
+
1 => :stage_instance,
|
14
|
+
2 => :voice,
|
15
|
+
3 => :external,
|
16
|
+
}
|
17
|
+
|
18
|
+
# @!visibility private
|
19
|
+
def initialize(client, data)
|
20
|
+
@client = client
|
21
|
+
@data = data
|
22
|
+
_set_data(data)
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Represents the metadata of the event.
|
27
|
+
#
|
28
|
+
class Metadata
|
29
|
+
# @return [String, nil] The location of the event. Only present if the event is a external event.
|
30
|
+
attr_reader :location
|
31
|
+
# @!visibility private
|
32
|
+
def initialize(data)
|
33
|
+
@location = data[:location]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Discorb::Snowflake] The ID of the event.
|
13
38
|
attr_reader :id
|
14
|
-
# @return [
|
39
|
+
# @return [String] The name of the event.
|
40
|
+
attr_reader :name
|
41
|
+
# @return [String] The description of the event.
|
42
|
+
attr_reader :description
|
43
|
+
|
44
|
+
# @return [Time] The time the event starts.
|
45
|
+
attr_reader :scheduled_start_time
|
46
|
+
alias start_time scheduled_start_time
|
47
|
+
alias start_at scheduled_start_time
|
48
|
+
# @return [Time] The time the event ends.
|
49
|
+
attr_reader :scheduled_end_time
|
50
|
+
alias end_time scheduled_end_time
|
51
|
+
alias end_at scheduled_end_time
|
52
|
+
# @return [:guild_only] The privacy level of the event.
|
53
|
+
attr_reader :privacy_level
|
54
|
+
# @return [:scheduled, :active, :completed, :canceled] The status of the event.
|
55
|
+
attr_reader :status
|
56
|
+
# @return [:stage_instance, :voice, :external] The type of the event.
|
57
|
+
attr_reader :entity_type
|
58
|
+
# @return [Discorb::Snowflake] The ID of the entity the event is for.
|
59
|
+
attr_reader :entity_id
|
60
|
+
# @return [Discorb::ScheduledEvent::Metadata] The metadata of the event.
|
15
61
|
attr_reader :metadata
|
16
|
-
# @return [
|
17
|
-
attr_reader :
|
18
|
-
|
62
|
+
# @return [Integer] The user count of the event.
|
63
|
+
attr_reader :user_count
|
64
|
+
|
65
|
+
# @!attribute [r] guild
|
66
|
+
# @return [Discorb::Guild, nil] The guild of the event.
|
67
|
+
# @!attribute [r] channel
|
68
|
+
# @return [Discorb::Channel, nil] The channel of the event.
|
69
|
+
# Only present if the event will do in stage instance or voice channel.
|
70
|
+
# @!attribute [r] creator
|
71
|
+
# @return [Discorb::User] The user who created the event.#
|
72
|
+
# @!attribute [r] time
|
73
|
+
# @return [Range<Time>] The time range of the event.
|
74
|
+
|
75
|
+
def guild
|
76
|
+
@client.guilds[@guild_id]
|
77
|
+
end
|
78
|
+
|
79
|
+
def channel
|
80
|
+
@client.channels[@channel_id]
|
81
|
+
end
|
82
|
+
|
83
|
+
def creator
|
84
|
+
@creator || @client.users[@creator_id]
|
85
|
+
end
|
86
|
+
|
87
|
+
def time
|
88
|
+
@scheduled_start_time..@scheduled_end_time
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Create a scheduled event for the guild.
|
93
|
+
# @async
|
94
|
+
#
|
95
|
+
# @param [:stage_instance, :voice, :external] type The type of event to create.
|
96
|
+
# @param [String] name The name of the event.
|
97
|
+
# @param [String] description The description of the event.
|
98
|
+
# @param [Time] start_time The start time of the event.
|
99
|
+
# @param [Time, nil] end_time The end time of the event. Defaults to `nil`.
|
100
|
+
# @param [Discorb::Channel, Discorb::Snowflake, nil] channel The channel to run the event in.
|
101
|
+
# @param [String, nil] location The location of the event. Defaults to `nil`.
|
102
|
+
# @param [:guild_only] privacy_level The privacy level of the event. This must be `:guild_only`.
|
103
|
+
# @param [:active, :completed, :canceled] status The status of the event.
|
104
|
+
#
|
105
|
+
# @return [Async::Task<Discorb::ScheduledEvent>] The event that was created.
|
106
|
+
#
|
107
|
+
# @see Event#start
|
108
|
+
# @see Event#cancel
|
109
|
+
# @see Event#complete
|
110
|
+
#
|
111
|
+
def edit(
|
112
|
+
type: Discorb::Unset,
|
113
|
+
name: Discorb::Unset,
|
114
|
+
description: Discorb::Unset,
|
115
|
+
start_time: Discorb::Unset,
|
116
|
+
end_time: Discorb::Unset,
|
117
|
+
privacy_level: Discorb::Unset,
|
118
|
+
location: Discorb::Unset,
|
119
|
+
channel: Discorb::Unset,
|
120
|
+
status: Discorb::Unset
|
121
|
+
)
|
122
|
+
Async do
|
123
|
+
payload = case (type == Discorb::Unset) ? @entity_type : type
|
124
|
+
when :stage_instance
|
125
|
+
raise ArgumentError, "channel must be provided for stage_instance events" unless channel
|
126
|
+
{
|
127
|
+
name: name,
|
128
|
+
description: description,
|
129
|
+
scheduled_start_time: start_time.iso8601,
|
130
|
+
scheduled_end_time: end_time&.iso8601,
|
131
|
+
privacy_level: Discorb::ScheduledEvent.privacy_level.key(privacy_level) || Discorb::Unset,
|
132
|
+
channel_id: channel&.id,
|
133
|
+
entity_type: Discorb::ScheduledEvent.entity_type.key(:stage_instance),
|
134
|
+
status: Discorb::ScheduledEvent.status.key(status) || Discorb::Unset,
|
135
|
+
}.reject { |_, v| v == Discorb::Unset }
|
136
|
+
when :voice
|
137
|
+
raise ArgumentError, "channel must be provided for voice events" unless channel
|
138
|
+
{
|
139
|
+
name: name,
|
140
|
+
description: description,
|
141
|
+
scheduled_start_time: start_time.iso8601,
|
142
|
+
scheduled_end_time: end_time&.iso8601,
|
143
|
+
privacy_level: Discorb::ScheduledEvent.privacy_level.key(privacy_level) || Discorb::Unset,
|
144
|
+
channel_id: channel&.id,
|
145
|
+
entity_type: Discorb::ScheduledEvent.entity_type.key(:voice),
|
146
|
+
status: Discorb::ScheduledEvent.status.key(status) || Discorb::Unset,
|
147
|
+
}.reject { |_, v| v == Discorb::Unset }
|
148
|
+
when :external
|
149
|
+
raise ArgumentError, "location must be provided for external events" unless location
|
150
|
+
raise ArgumentError, "end_time must be provided for external events" unless end_time
|
151
|
+
{
|
152
|
+
name: name,
|
153
|
+
description: description,
|
154
|
+
channel_id: nil,
|
155
|
+
scheduled_start_time: start_time.iso8601,
|
156
|
+
scheduled_end_time: end_time.iso8601,
|
157
|
+
privacy_level: Discorb::ScheduledEvent.privacy_level.key(privacy_level) || Discorb::Unset,
|
158
|
+
entity_type: Discorb::ScheduledEvent.entity_type.key(:external),
|
159
|
+
entity_metadata: {
|
160
|
+
location: location,
|
161
|
+
},
|
162
|
+
status: Discorb::ScheduledEvent.status.key(status) || Discorb::Unset,
|
163
|
+
}.reject { |_, v| v == Discorb::Unset }
|
164
|
+
else
|
165
|
+
raise ArgumentError, "Invalid scheduled event type: #{type}"
|
166
|
+
end
|
167
|
+
@client.http.patch("/guilds/#{@guild_id}/scheduled-events/#{@id}", payload).wait
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
alias modify edit
|
19
172
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
173
|
+
#
|
174
|
+
# Starts the event. Shortcut for `edit(status: :active)`.
|
175
|
+
#
|
176
|
+
def start
|
177
|
+
edit(status: :active)
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Completes the event. Shortcut for `edit(status: :completed)`.
|
182
|
+
#
|
183
|
+
def complete
|
184
|
+
edit(status: :completed)
|
185
|
+
end
|
186
|
+
|
187
|
+
alias finish complete
|
188
|
+
|
189
|
+
#
|
190
|
+
# Cancels the event. Shortcut for `edit(status: :canceled)`.
|
191
|
+
#
|
192
|
+
def cancel
|
193
|
+
edit(status: :canceled)
|
194
|
+
end
|
195
|
+
|
196
|
+
#
|
197
|
+
# Deletes the event.
|
198
|
+
# @async
|
199
|
+
#
|
200
|
+
# @return [Async::Task<void>] The task.
|
201
|
+
#
|
202
|
+
def delete!
|
203
|
+
Async do
|
204
|
+
@client.http.delete("/guilds/#{@guild_id}/scheduled-events/#{@id}").wait
|
205
|
+
end
|
26
206
|
end
|
27
207
|
|
208
|
+
alias destroy! delete!
|
209
|
+
|
210
|
+
#
|
211
|
+
# Fetches the event users.
|
212
|
+
# @async
|
213
|
+
#
|
214
|
+
# @note You can fetch all of members by not specifying a parameter.
|
215
|
+
#
|
216
|
+
# @param [Integer] limit The maximum number of users to fetch. Defaults to `100`.
|
217
|
+
# @param [#to_s] after The ID of the user to start fetching from. Defaults to `nil`.
|
218
|
+
# @param [#to_s] before The ID of the user to stop fetching at. Defaults to `nil`.
|
219
|
+
# @param [Boolean] with_member Whether to include the member object of the event. Defaults to `false`.
|
220
|
+
# This should be used for manual fetching of members.
|
28
221
|
#
|
29
|
-
#
|
222
|
+
# @return [Async::Task<Array<Discorb::Member>>] The event users.
|
30
223
|
#
|
31
|
-
def
|
32
|
-
|
224
|
+
def fetch_users(limit = nil, before: nil, after: nil, with_member: true)
|
225
|
+
Async do
|
226
|
+
if limit.nil?
|
227
|
+
after = 0
|
228
|
+
res = []
|
229
|
+
while true
|
230
|
+
_resp, users = @client.http.get("/guilds/#{@guild_id}/scheduled-events/#{@id}/users?limit=100&after=#{after}&with_member=true").wait
|
231
|
+
if users.empty?
|
232
|
+
break
|
233
|
+
end
|
234
|
+
res += users.map { |u| Member.new(@client, @guild_id, u[:user], u[:member]) }
|
235
|
+
after = users.last[:user][:id]
|
236
|
+
end
|
237
|
+
res
|
238
|
+
else
|
239
|
+
params = {
|
240
|
+
limit: limit,
|
241
|
+
before: Discorb::Utils.try(after, :id),
|
242
|
+
after: Discorb::Utils.try(around, :id),
|
243
|
+
with_member: with_member,
|
244
|
+
}.filter { |_k, v| !v.nil? }.to_h
|
245
|
+
_resp, messages = @client.http.get("/channels/#{channel_id.wait}/messages?#{URI.encode_www_form(params)}").wait
|
246
|
+
messages.map { |m| Message.new(@client, m.merge({ guild_id: @guild_id.to_s })) }
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
alias fetch_members fetch_users
|
252
|
+
|
253
|
+
private
|
254
|
+
|
255
|
+
def _set_data(data)
|
256
|
+
@id = Snowflake.new(data[:id])
|
257
|
+
@guild_id = Snowflake.new(data[:guild_id])
|
258
|
+
@channel_id = data[:channel_id] && Snowflake.new(data[:channel_id])
|
259
|
+
@creator_id = data[:creator_id] && Snowflake.new(data[:creator_id])
|
260
|
+
@name = data[:name]
|
261
|
+
@description = data[:description]
|
262
|
+
@scheduled_start_time = Time.iso8601(data[:scheduled_start_time])
|
263
|
+
@scheduled_end_time = data[:scheduled_end_time] && Time.iso8601(data[:scheduled_end_time])
|
264
|
+
@privacy_level = :guild_only # data[:privacy_level]
|
265
|
+
@status = self.class.status[data[:status]]
|
266
|
+
@entity_type = self.class.entity_type[data[:entity_type]]
|
267
|
+
@entity_id = data[:entity_id] && Snowflake.new(data[:entity_id])
|
268
|
+
@entity_metadata = data[:entity_metadata] && Metadata.new(data[:entity_metadata])
|
269
|
+
@creator = @client.users[@creator_id] || (data[:creator] && User.new(@client, data[:creator]))
|
270
|
+
@user_count = data[:user_count]
|
271
|
+
end
|
272
|
+
|
273
|
+
class << self
|
274
|
+
attr_reader :status, :entity_type, :privacy_level
|
33
275
|
end
|
34
276
|
end
|
35
277
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a event handler.
|
6
|
+
# This class shouldn't be instantiated directly.
|
7
|
+
# Use {Client#on} instead.
|
8
|
+
#
|
9
|
+
class EventHandler
|
10
|
+
# @return [Proc] the block to be called.
|
11
|
+
attr_reader :block
|
12
|
+
# @return [Symbol] the event id.
|
13
|
+
attr_reader :id
|
14
|
+
# @return [Hash] the event metadata.
|
15
|
+
attr_reader :metadata
|
16
|
+
# @return [Boolean] whether the event is once or not.
|
17
|
+
attr_reader :once
|
18
|
+
alias once? once
|
19
|
+
|
20
|
+
def initialize(block, id, metadata)
|
21
|
+
@block = block
|
22
|
+
@id = id
|
23
|
+
@once = metadata.fetch(:once, false)
|
24
|
+
@metadata = metadata
|
25
|
+
@rescue = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
"#<#{self.class} @id=#{@id}"
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Calls the block associated with the event.
|
34
|
+
#
|
35
|
+
def call(...)
|
36
|
+
@block.call(...)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/discorb/exe/show.rb
CHANGED
data/lib/discorb/extension.rb
CHANGED
@@ -4,7 +4,7 @@ module Discorb
|
|
4
4
|
#
|
5
5
|
# Abstract class to make extension.
|
6
6
|
# Include from this module to make your own extension.
|
7
|
-
# @see file:docs/extension.md
|
7
|
+
# @see file:docs/extension.md Extension
|
8
8
|
# @abstract
|
9
9
|
#
|
10
10
|
module Extension
|
@@ -17,7 +17,7 @@ module Discorb
|
|
17
17
|
ret = {}
|
18
18
|
self.class.events.each do |event, handlers|
|
19
19
|
ret[event] = handlers.map do |handler|
|
20
|
-
Discorb::
|
20
|
+
Discorb::EventHandler.new(Proc.new { |*args, **kwargs| instance_exec(*args, **kwargs, &handler[2]) }, handler[0], handler[1])
|
21
21
|
end
|
22
22
|
end
|
23
23
|
@events = ret
|
@@ -38,7 +38,7 @@ module Discorb
|
|
38
38
|
# @param [Symbol] id The id of the event. Used to delete the event.
|
39
39
|
# @param [Hash] metadata Other metadata.
|
40
40
|
#
|
41
|
-
# @return [Discorb::
|
41
|
+
# @return [Discorb::EventHandler] The event.
|
42
42
|
#
|
43
43
|
def event(event_name, id: nil, **metadata, &block)
|
44
44
|
raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol)
|
@@ -57,13 +57,13 @@ module Discorb
|
|
57
57
|
# @param [Hash] metadata Other metadata.
|
58
58
|
# @param [Proc] block The block to execute when the event is triggered.
|
59
59
|
#
|
60
|
-
# @return [Discorb::
|
60
|
+
# @return [Discorb::EventHandler] The event.
|
61
61
|
#
|
62
62
|
def once_event(event_name, id: nil, **metadata, &block)
|
63
63
|
event(event_name, id: id, once: true, **metadata, &block)
|
64
64
|
end
|
65
65
|
|
66
|
-
# @return [Hash{Symbol => Array<Discorb::
|
66
|
+
# @return [Hash{Symbol => Array<Discorb::EventHandler>}] The events of the extension.
|
67
67
|
attr_reader :events
|
68
68
|
# @return [Array<Discorb::ApplicationCommand::Command>] The commands of the extension.
|
69
69
|
attr_reader :commands
|
data/lib/discorb/file.rb
CHANGED
data/lib/discorb/flag.rb
CHANGED
@@ -92,10 +92,14 @@ module Discorb
|
|
92
92
|
#
|
93
93
|
# @return [Discorb::Flag] The negation of the flag.
|
94
94
|
#
|
95
|
-
def
|
95
|
+
def ~
|
96
96
|
self.class.new(~@value)
|
97
97
|
end
|
98
98
|
|
99
|
+
def inspect
|
100
|
+
"#<#{self.class}: #{@value}>"
|
101
|
+
end
|
102
|
+
|
99
103
|
class << self
|
100
104
|
# @return [Hash{Integer => Symbol}] the bits of the flag.
|
101
105
|
attr_reader :bits
|
data/lib/discorb/gateway.rb
CHANGED
@@ -94,8 +94,7 @@ module Discorb
|
|
94
94
|
|
95
95
|
# Fetch the message.
|
96
96
|
# If message is cached, it will be returned.
|
97
|
-
# @
|
98
|
-
# @macro http
|
97
|
+
# @async
|
99
98
|
#
|
100
99
|
# @param [Boolean] force Whether to force fetching the message.
|
101
100
|
#
|
@@ -109,6 +108,35 @@ module Discorb
|
|
109
108
|
end
|
110
109
|
end
|
111
110
|
|
111
|
+
#
|
112
|
+
# Represents a `INTEGRATION_DELETE` event.
|
113
|
+
#
|
114
|
+
class IntegrationDeleteEvent < GatewayEvent
|
115
|
+
# @return [Discorb::Snowflake] The ID of the integration.
|
116
|
+
attr_reader :id
|
117
|
+
# @!attribute [r] guild
|
118
|
+
# @macro client_cache
|
119
|
+
# @return [Discorb::Guild] The guild of the integration.
|
120
|
+
# @!attribute [r] user
|
121
|
+
# @macro client_cache
|
122
|
+
# @return [Discorb::User] The user associated with the integration.
|
123
|
+
|
124
|
+
# @private
|
125
|
+
def initialize(client, data)
|
126
|
+
@id = Snowflake.new(data[:id])
|
127
|
+
@guild_id = data[:guild_id]
|
128
|
+
@user_id = data[:application_id]
|
129
|
+
end
|
130
|
+
|
131
|
+
def guild
|
132
|
+
@client.guilds[@guild_id]
|
133
|
+
end
|
134
|
+
|
135
|
+
def user
|
136
|
+
@client.users[@user_id]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
112
140
|
#
|
113
141
|
# Represents a `MESSAGE_REACTION_REMOVE_ALL` event.
|
114
142
|
#
|
@@ -143,8 +171,7 @@ module Discorb
|
|
143
171
|
|
144
172
|
# Fetch the message.
|
145
173
|
# If message is cached, it will be returned.
|
146
|
-
# @
|
147
|
-
# @macro http
|
174
|
+
# @async
|
148
175
|
#
|
149
176
|
# @param [Boolean] force Whether to force fetching the message.
|
150
177
|
#
|
@@ -195,8 +222,7 @@ module Discorb
|
|
195
222
|
|
196
223
|
# Fetch the message.
|
197
224
|
# If message is cached, it will be returned.
|
198
|
-
# @
|
199
|
-
# @macro http
|
225
|
+
# @async
|
200
226
|
#
|
201
227
|
# @param [Boolean] force Whether to force fetching the message.
|
202
228
|
#
|
@@ -210,6 +236,28 @@ module Discorb
|
|
210
236
|
end
|
211
237
|
end
|
212
238
|
|
239
|
+
#
|
240
|
+
# Represents a `GUILD_SCHEDULED_EVENT_USER_ADD` and `GUILD_SCHEDULED_EVENT_USER_REMOVE` event.
|
241
|
+
#
|
242
|
+
class ScheduledEventUserEvent < GatewayEvent
|
243
|
+
# @return [Discorb::User] The user that triggered the event.
|
244
|
+
attr_reader :user
|
245
|
+
# @return [Discorb::Guild] The guild the event was triggered in.
|
246
|
+
attr_reader :guild
|
247
|
+
# @return [Discorb::ScheduledEvent] The scheduled event.
|
248
|
+
attr_reader :scheduled_event
|
249
|
+
# @private
|
250
|
+
def initialize(client, data)
|
251
|
+
@client = client
|
252
|
+
@scheduled_event_id = Snowflake.new(data[:scheduled_event_id])
|
253
|
+
@user_id = Snowflake.new(data[:user_id])
|
254
|
+
@guild_id = Snowflake.new(data[:guild_id])
|
255
|
+
@guild = client.guilds[data[:guild_id]]
|
256
|
+
@scheduled_event = @guild.scheduled_events[@scheduled_event_id]
|
257
|
+
@user = client.users[data[:user_id]]
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
213
261
|
#
|
214
262
|
# Represents a `MESSAGE_UPDATE` event.
|
215
263
|
#
|
@@ -271,8 +319,7 @@ module Discorb
|
|
271
319
|
end
|
272
320
|
|
273
321
|
# Fetch the message.
|
274
|
-
# @
|
275
|
-
# @macro http
|
322
|
+
# @async
|
276
323
|
#
|
277
324
|
# @return [Async::Task<Discorb::Message>] The message.
|
278
325
|
def fetch_message
|
@@ -481,14 +528,14 @@ module Discorb
|
|
481
528
|
module Handler
|
482
529
|
private
|
483
530
|
|
484
|
-
def connect_gateway(reconnect)
|
531
|
+
def connect_gateway(reconnect, no_close: false)
|
485
532
|
if reconnect
|
486
533
|
@log.info "Reconnecting to gateway..."
|
487
534
|
else
|
488
535
|
@log.info "Connecting to gateway..."
|
489
536
|
end
|
490
537
|
Async do
|
491
|
-
@connection&.close
|
538
|
+
@connection&.close rescue nil unless no_close
|
492
539
|
@http = HTTP.new(self)
|
493
540
|
_, gateway_response = @http.get("/gateway").wait
|
494
541
|
gateway_url = gateway_response[:url]
|
@@ -515,9 +562,9 @@ module Discorb
|
|
515
562
|
end
|
516
563
|
end
|
517
564
|
end
|
518
|
-
rescue Async::Wrapper::Cancelled, OpenSSL::SSL::SSLError, Async::Wrapper::WaitError, EOFError => e
|
519
|
-
@log.error "Gateway connection closed: #{e.class}: #{e.message}"
|
520
|
-
connect_gateway(true)
|
565
|
+
rescue Async::Wrapper::Cancelled, OpenSSL::SSL::SSLError, Async::Wrapper::WaitError, EOFError, Errno::EPIPE => e
|
566
|
+
@log.error "Gateway connection closed accidentally: #{e.class}: #{e.message}"
|
567
|
+
connect_gateway(true, no_close: true)
|
521
568
|
else # should never happen
|
522
569
|
connect_gateway(true)
|
523
570
|
end
|
@@ -848,9 +895,8 @@ module Discorb
|
|
848
895
|
dispatch(:integration_update, integration)
|
849
896
|
when "INTEGRATION_DELETE"
|
850
897
|
return @log.warn "Unknown guild id #{data[:guild_id]}, ignoring" unless (guild = @guilds[data[:guild_id]])
|
851
|
-
return @log.warn "Unknown integration id #{data[:id]}, ignoring" unless (integration = guild.integrations.delete(data[:id]))
|
852
898
|
|
853
|
-
dispatch(:integration_delete,
|
899
|
+
dispatch(:integration_delete, IntegrationDeleteEvent.new(self, data))
|
854
900
|
when "WEBHOOKS_UPDATE"
|
855
901
|
dispatch(:webhooks_update, WebhooksUpdateEvent.new(self, data))
|
856
902
|
when "INVITE_CREATE"
|
@@ -866,6 +912,7 @@ module Discorb
|
|
866
912
|
current = VoiceState.new(self, data)
|
867
913
|
guild.voice_states[data[:user_id]] = current
|
868
914
|
else
|
915
|
+
guild.voice_states.remove(data[:user_id]) if data[:channel_id].nil?
|
869
916
|
old = VoiceState.new(self, current.instance_variable_get(:@data))
|
870
917
|
current.send(:_set_data, data)
|
871
918
|
end
|
@@ -989,7 +1036,7 @@ module Discorb
|
|
989
1036
|
message.instance_variable_set(:@deleted, true)
|
990
1037
|
messages.push(message)
|
991
1038
|
else
|
992
|
-
messages.push(UnknownDeleteBulkMessage.new(self, id))
|
1039
|
+
messages.push(UnknownDeleteBulkMessage.new(self, id, data))
|
993
1040
|
end
|
994
1041
|
end
|
995
1042
|
dispatch(:message_delete_bulk, messages)
|
@@ -1042,11 +1089,44 @@ module Discorb
|
|
1042
1089
|
@log.info("Successfully resumed connection")
|
1043
1090
|
@tasks << handle_heartbeat
|
1044
1091
|
dispatch(:resumed)
|
1092
|
+
when "GUILD_SCHEDULED_EVENT_CREATE"
|
1093
|
+
@log.warn("Unknown guild id #{data[:guild_id]}, ignoring") unless (guild = @guilds[data[:guild_id]])
|
1094
|
+
event = ScheduledEvent.new(self, data)
|
1095
|
+
guild.scheduled_events[data[:id]] = event
|
1096
|
+
dispatch(:scheduled_event_create, event)
|
1097
|
+
when "GUILD_SCHEDULED_EVENT_UPDATE"
|
1098
|
+
@log.warn("Unknown guild id #{data[:guild_id]}, ignoring") unless (guild = @guilds[data[:guild_id]])
|
1099
|
+
@log.warn("Unknown scheduled event id #{data[:id]}, ignoring") unless (event = guild.scheduled_events[data[:id]])
|
1100
|
+
old = event.dup
|
1101
|
+
event.send(:_set_data, data)
|
1102
|
+
dispatch(:scheduled_event_update, old, event)
|
1103
|
+
if old.status != event.status
|
1104
|
+
case event.status
|
1105
|
+
when :active
|
1106
|
+
dispatch(:scheduled_event_start, event)
|
1107
|
+
when :completed
|
1108
|
+
dispatch(:scheduled_event_end, event)
|
1109
|
+
end
|
1110
|
+
else
|
1111
|
+
dispatch(:scheduled_event_edit, old, event)
|
1112
|
+
end
|
1113
|
+
when "GUILD_SCHEDULED_EVENT_DELETE"
|
1114
|
+
@log.warn("Unknown guild id #{data[:guild_id]}, ignoring") unless (guild = @guilds[data[:guild_id]])
|
1115
|
+
@log.warn("Unknown scheduled event id #{data[:id]}, ignoring") unless (event = guild.scheduled_events[data[:id]])
|
1116
|
+
guild.scheduled_events.remove(data[:id])
|
1117
|
+
dispatch(:scheduled_event_delete, event)
|
1118
|
+
dispatch(:scheduled_event_cancel, event)
|
1119
|
+
when "GUILD_SCHEDULED_EVENT_USER_ADD"
|
1120
|
+
@log.warn("Unknown guild id #{data[:guild_id]}, ignoring") unless (guild = @guilds[data[:guild_id]])
|
1121
|
+
dispatch(:scheduled_event_user_add, ScheduledEventUserEvent.new(self, data))
|
1122
|
+
when "GUILD_SCHEDULED_EVENT_USER_REMOVE"
|
1123
|
+
@log.warn("Unknown guild id #{data[:guild_id]}, ignoring") unless (guild = @guilds[data[:guild_id]])
|
1124
|
+
dispatch(:scheduled_event_user_remove, ScheduledEventUserEvent.new(self, data))
|
1045
1125
|
else
|
1046
1126
|
if respond_to?("event_" + event_name.downcase)
|
1047
1127
|
__send__("event_" + event_name.downcase, data)
|
1048
1128
|
else
|
1049
|
-
@log.debug "#{event_name}\n#{data.inspect}"
|
1129
|
+
@log.debug "Unhandled event: #{event_name}\n#{data.inspect}"
|
1050
1130
|
end
|
1051
1131
|
end
|
1052
1132
|
end
|