discorb 0.13.0 → 0.13.4
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/.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/CODE_OF_CONDUCT.md +128 -0
- data/Changelog.md +420 -388
- 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 +7 -5
- 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 +6 -4
- 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 +32 -9
- data/lib/discorb/application.rb +1 -1
- data/lib/discorb/asset.rb +1 -1
- data/lib/discorb/channel.rb +170 -125
- data/lib/discorb/client.rb +20 -22
- data/lib/discorb/common.rb +32 -1
- data/lib/discorb/dictionary.rb +10 -2
- data/lib/discorb/emoji.rb +7 -9
- data/lib/discorb/emoji_table.rb +3891 -3891
- data/lib/discorb/event.rb +12 -11
- data/lib/discorb/exe/show.rb +2 -0
- data/lib/discorb/extension.rb +1 -1
- data/lib/discorb/flag.rb +1 -1
- data/lib/discorb/gateway.rb +63 -17
- data/lib/discorb/guild.rb +110 -156
- data/lib/discorb/guild_template.rb +15 -12
- data/lib/discorb/http.rb +41 -136
- data/lib/discorb/integration.rb +34 -2
- data/lib/discorb/interaction/autocomplete.rb +1 -1
- data/lib/discorb/interaction/response.rb +34 -32
- data/lib/discorb/interaction/root.rb +8 -0
- data/lib/discorb/invite.rb +4 -3
- data/lib/discorb/log.rb +3 -2
- data/lib/discorb/member.rb +44 -15
- data/lib/discorb/message.rb +33 -22
- data/lib/discorb/modules.rb +28 -35
- data/lib/discorb/presence.rb +2 -2
- data/lib/discorb/rate_limit.rb +14 -18
- data/lib/discorb/role.rb +18 -14
- data/lib/discorb/sticker.rb +10 -14
- data/lib/discorb/user.rb +10 -10
- data/lib/discorb/voice_state.rb +12 -7
- data/lib/discorb/webhook.rb +44 -50
- data/lib/discorb.rb +1 -1
- data/po/yard.pot +7772 -5154
- data/sig/discorb.rbs +3316 -3819
- data/template-replace/scripts/locale_ja.rb +62 -0
- metadata +18 -5
data/lib/discorb/event.rb
CHANGED
@@ -90,8 +90,7 @@ module Discorb
|
|
90
90
|
|
91
91
|
#
|
92
92
|
# Create a scheduled event for the guild.
|
93
|
-
# @
|
94
|
-
# @macro http
|
93
|
+
# @async
|
95
94
|
#
|
96
95
|
# @param [:stage_instance, :voice, :external] type The type of event to create.
|
97
96
|
# @param [String] name The name of the event.
|
@@ -103,6 +102,8 @@ module Discorb
|
|
103
102
|
# @param [:guild_only] privacy_level The privacy level of the event. This must be `:guild_only`.
|
104
103
|
# @param [:active, :completed, :canceled] status The status of the event.
|
105
104
|
#
|
105
|
+
# @return [Async::Task<Discorb::ScheduledEvent>] The event that was created.
|
106
|
+
#
|
106
107
|
# @see Event#start
|
107
108
|
# @see Event#cancel
|
108
109
|
# @see Event#complete
|
@@ -163,7 +164,7 @@ module Discorb
|
|
163
164
|
else
|
164
165
|
raise ArgumentError, "Invalid scheduled event type: #{type}"
|
165
166
|
end
|
166
|
-
@client.http.
|
167
|
+
@client.http.request(Route.new("/guilds/#{@guild_id}/scheduled-events/#{@id}", "//guilds/:guild_id/scheduled-events/:scheduled_event_id", :patch), payload).wait
|
167
168
|
end
|
168
169
|
end
|
169
170
|
|
@@ -194,12 +195,13 @@ module Discorb
|
|
194
195
|
|
195
196
|
#
|
196
197
|
# Deletes the event.
|
197
|
-
# @
|
198
|
-
#
|
198
|
+
# @async
|
199
|
+
#
|
200
|
+
# @return [Async::Task<void>] The task.
|
199
201
|
#
|
200
202
|
def delete!
|
201
203
|
Async do
|
202
|
-
@client.http.
|
204
|
+
@client.http.request(Route.new("/guilds/#{@guild_id}/scheduled-events/#{@id}", "//guilds/:guild_id/scheduled-events/:scheduled_event_id", :delete)).wait
|
203
205
|
end
|
204
206
|
end
|
205
207
|
|
@@ -207,8 +209,7 @@ module Discorb
|
|
207
209
|
|
208
210
|
#
|
209
211
|
# Fetches the event users.
|
210
|
-
# @
|
211
|
-
# @macro http
|
212
|
+
# @async
|
212
213
|
#
|
213
214
|
# @note You can fetch all of members by not specifying a parameter.
|
214
215
|
#
|
@@ -218,7 +219,7 @@ module Discorb
|
|
218
219
|
# @param [Boolean] with_member Whether to include the member object of the event. Defaults to `false`.
|
219
220
|
# This should be used for manual fetching of members.
|
220
221
|
#
|
221
|
-
# @return [Array<Discorb::Member
|
222
|
+
# @return [Async::Task<Array<Discorb::Member>>] The event users.
|
222
223
|
#
|
223
224
|
def fetch_users(limit = nil, before: nil, after: nil, with_member: true)
|
224
225
|
Async do
|
@@ -226,7 +227,7 @@ module Discorb
|
|
226
227
|
after = 0
|
227
228
|
res = []
|
228
229
|
while true
|
229
|
-
_resp, users = @client.http.
|
230
|
+
_resp, users = @client.http.request(Route.new("/guilds/#{@guild_id}/scheduled-events/#{@id}/users?limit=100&after=#{after}&with_member=true", "//guilds/:guild_id/scheduled-events/:scheduled_event_id/users", :get)).wait
|
230
231
|
if users.empty?
|
231
232
|
break
|
232
233
|
end
|
@@ -241,7 +242,7 @@ module Discorb
|
|
241
242
|
after: Discorb::Utils.try(around, :id),
|
242
243
|
with_member: with_member,
|
243
244
|
}.filter { |_k, v| !v.nil? }.to_h
|
244
|
-
_resp, messages = @client.http.
|
245
|
+
_resp, messages = @client.http.request(Route.new("/channels/#{channel_id.wait}/messages?#{URI.encode_www_form(params)}", "//channels/:channel_id/messages", :get)).wait
|
245
246
|
messages.map { |m| Message.new(@client, m.merge({ guild_id: @guild_id.to_s })) }
|
246
247
|
end
|
247
248
|
end
|
data/lib/discorb/exe/show.rb
CHANGED
data/lib/discorb/extension.rb
CHANGED
data/lib/discorb/flag.rb
CHANGED
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
|
#
|
@@ -293,8 +319,7 @@ module Discorb
|
|
293
319
|
end
|
294
320
|
|
295
321
|
# Fetch the message.
|
296
|
-
# @
|
297
|
-
# @macro http
|
322
|
+
# @async
|
298
323
|
#
|
299
324
|
# @return [Async::Task<Discorb::Message>] The message.
|
300
325
|
def fetch_message
|
@@ -503,16 +528,24 @@ module Discorb
|
|
503
528
|
module Handler
|
504
529
|
private
|
505
530
|
|
506
|
-
def connect_gateway(reconnect)
|
531
|
+
def connect_gateway(reconnect, force_close: false)
|
507
532
|
if reconnect
|
508
533
|
@log.info "Reconnecting to gateway..."
|
509
534
|
else
|
510
535
|
@log.info "Connecting to gateway..."
|
511
536
|
end
|
512
537
|
Async do
|
513
|
-
@connection
|
538
|
+
if @connection
|
539
|
+
Async do
|
540
|
+
if force_close
|
541
|
+
@connection.force_close
|
542
|
+
else
|
543
|
+
@connection.close
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
514
547
|
@http = HTTP.new(self)
|
515
|
-
_, gateway_response = @http.
|
548
|
+
_, gateway_response = @http.request(Route.new("/gateway", "//gateway", :get)).wait
|
516
549
|
gateway_url = gateway_response[:url]
|
517
550
|
endpoint = Async::HTTP::Endpoint.parse("#{gateway_url}?v=9&encoding=json&compress=zlib-stream",
|
518
551
|
alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
|
@@ -537,9 +570,15 @@ module Discorb
|
|
537
570
|
end
|
538
571
|
end
|
539
572
|
end
|
540
|
-
rescue Async::Wrapper::Cancelled,
|
541
|
-
|
542
|
-
|
573
|
+
rescue Async::Wrapper::Cancelled,
|
574
|
+
OpenSSL::SSL::SSLError,
|
575
|
+
Async::Wrapper::WaitError,
|
576
|
+
EOFError,
|
577
|
+
Errno::EPIPE,
|
578
|
+
Errno::ECONNRESET,
|
579
|
+
IOError => e
|
580
|
+
@log.error "Gateway connection closed accidentally: #{e.class}: #{e.message}"
|
581
|
+
connect_gateway(true, force_close: true)
|
543
582
|
else # should never happen
|
544
583
|
connect_gateway(true)
|
545
584
|
end
|
@@ -870,9 +909,8 @@ module Discorb
|
|
870
909
|
dispatch(:integration_update, integration)
|
871
910
|
when "INTEGRATION_DELETE"
|
872
911
|
return @log.warn "Unknown guild id #{data[:guild_id]}, ignoring" unless (guild = @guilds[data[:guild_id]])
|
873
|
-
return @log.warn "Unknown integration id #{data[:id]}, ignoring" unless (integration = guild.integrations.delete(data[:id]))
|
874
912
|
|
875
|
-
dispatch(:integration_delete,
|
913
|
+
dispatch(:integration_delete, IntegrationDeleteEvent.new(self, data))
|
876
914
|
when "WEBHOOKS_UPDATE"
|
877
915
|
dispatch(:webhooks_update, WebhooksUpdateEvent.new(self, data))
|
878
916
|
when "INVITE_CREATE"
|
@@ -888,6 +926,7 @@ module Discorb
|
|
888
926
|
current = VoiceState.new(self, data)
|
889
927
|
guild.voice_states[data[:user_id]] = current
|
890
928
|
else
|
929
|
+
guild.voice_states.remove(data[:user_id]) if data[:channel_id].nil?
|
891
930
|
old = VoiceState.new(self, current.instance_variable_get(:@data))
|
892
931
|
current.send(:_set_data, data)
|
893
932
|
end
|
@@ -1011,7 +1050,7 @@ module Discorb
|
|
1011
1050
|
message.instance_variable_set(:@deleted, true)
|
1012
1051
|
messages.push(message)
|
1013
1052
|
else
|
1014
|
-
messages.push(UnknownDeleteBulkMessage.new(self, id))
|
1053
|
+
messages.push(UnknownDeleteBulkMessage.new(self, id, data))
|
1015
1054
|
end
|
1016
1055
|
end
|
1017
1056
|
dispatch(:message_delete_bulk, messages)
|
@@ -1143,6 +1182,13 @@ module Discorb
|
|
1143
1182
|
def close
|
1144
1183
|
super
|
1145
1184
|
@closed = true
|
1185
|
+
rescue
|
1186
|
+
force_close
|
1187
|
+
end
|
1188
|
+
|
1189
|
+
def force_close
|
1190
|
+
@framer.instance_variable_get(:@stream).close
|
1191
|
+
@closed = true
|
1146
1192
|
end
|
1147
1193
|
|
1148
1194
|
def parse(buffer)
|