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/client.rb
CHANGED
@@ -105,17 +105,17 @@ module Discorb
|
|
105
105
|
|
106
106
|
#
|
107
107
|
# Registers an event handler.
|
108
|
-
# @see file:docs/Events.md
|
108
|
+
# @see file:docs/Events.md Events Documentation
|
109
109
|
#
|
110
110
|
# @param [Symbol] event_name The name of the event.
|
111
111
|
# @param [Symbol] id Custom ID of the event.
|
112
112
|
# @param [Hash] metadata The metadata of the event.
|
113
113
|
# @param [Proc] block The block to execute when the event is triggered.
|
114
114
|
#
|
115
|
-
# @return [Discorb::
|
115
|
+
# @return [Discorb::EventHandler] The event.
|
116
116
|
#
|
117
117
|
def on(event_name, id: nil, **metadata, &block)
|
118
|
-
ne =
|
118
|
+
ne = EventHandler.new(block, id, metadata)
|
119
119
|
@events[event_name] ||= []
|
120
120
|
@events[event_name].delete_if { |e| e.metadata[:override] }
|
121
121
|
@events[event_name] << ne
|
@@ -127,7 +127,7 @@ module Discorb
|
|
127
127
|
#
|
128
128
|
# @param (see #on)
|
129
129
|
#
|
130
|
-
# @return [Discorb::
|
130
|
+
# @return [Discorb::EventHandler] The event.
|
131
131
|
#
|
132
132
|
def once(event_name, id: nil, **metadata, &block)
|
133
133
|
metadata[:once] = true
|
@@ -146,10 +146,13 @@ module Discorb
|
|
146
146
|
|
147
147
|
#
|
148
148
|
# Dispatch an event.
|
149
|
+
# @async
|
149
150
|
#
|
150
151
|
# @param [Symbol] event_name The name of the event.
|
151
152
|
# @param [Object] args The arguments to pass to the event.
|
152
153
|
#
|
154
|
+
# @return [Async::Task<void>] The task.
|
155
|
+
#
|
153
156
|
def dispatch(event_name, *args)
|
154
157
|
Async do
|
155
158
|
if (conditions = @conditions[event_name])
|
@@ -184,7 +187,7 @@ module Discorb
|
|
184
187
|
events.each do |block|
|
185
188
|
Async do
|
186
189
|
Async(annotation: "Discorb event: #{event_name}") do |task|
|
187
|
-
if block.is_a?(Discorb::
|
190
|
+
if block.is_a?(Discorb::EventHandler)
|
188
191
|
@events[event_name].delete(block) if block.metadata[:once]
|
189
192
|
end
|
190
193
|
block.call(*args)
|
@@ -199,8 +202,7 @@ module Discorb
|
|
199
202
|
|
200
203
|
#
|
201
204
|
# Fetch user from ID.
|
202
|
-
# @
|
203
|
-
# @macro http
|
205
|
+
# @async
|
204
206
|
#
|
205
207
|
# @param [#to_s] id <description>
|
206
208
|
#
|
@@ -217,8 +219,7 @@ module Discorb
|
|
217
219
|
|
218
220
|
#
|
219
221
|
# Fetch channel from ID.
|
220
|
-
# @
|
221
|
-
# @macro http
|
222
|
+
# @async
|
222
223
|
#
|
223
224
|
# @param [#to_s] id The ID of the channel.
|
224
225
|
#
|
@@ -235,8 +236,7 @@ module Discorb
|
|
235
236
|
|
236
237
|
#
|
237
238
|
# Fetch guild from ID.
|
238
|
-
# @
|
239
|
-
# @macro http
|
239
|
+
# @async
|
240
240
|
#
|
241
241
|
# @param [#to_s] id <description>
|
242
242
|
#
|
@@ -253,8 +253,7 @@ module Discorb
|
|
253
253
|
|
254
254
|
#
|
255
255
|
# Fetch invite from code.
|
256
|
-
# @
|
257
|
-
# @macro http
|
256
|
+
# @async
|
258
257
|
#
|
259
258
|
# @param [String] code The code of the invite.
|
260
259
|
# @param [Boolean] with_count Whether to include the count of the invite.
|
@@ -272,8 +271,7 @@ module Discorb
|
|
272
271
|
#
|
273
272
|
# Fetch webhook from ID.
|
274
273
|
# If application was cached, it will be used.
|
275
|
-
# @
|
276
|
-
# @macro http
|
274
|
+
# @async
|
277
275
|
#
|
278
276
|
# @param [Boolean] force Whether to force the fetch.
|
279
277
|
#
|
@@ -291,8 +289,7 @@ module Discorb
|
|
291
289
|
|
292
290
|
#
|
293
291
|
# Fetch nitro sticker pack from ID.
|
294
|
-
# @
|
295
|
-
# @macro http
|
292
|
+
# @async
|
296
293
|
#
|
297
294
|
# @return [Async::Task<Array<Discorb::Sticker::Pack>>] The packs.
|
298
295
|
#
|
@@ -334,12 +331,13 @@ module Discorb
|
|
334
331
|
|
335
332
|
#
|
336
333
|
# Method to wait for a event.
|
334
|
+
# @async
|
337
335
|
#
|
338
336
|
# @param [Symbol] event The name of the event.
|
339
337
|
# @param [Integer] timeout The timeout in seconds.
|
340
338
|
# @param [Proc] check The check to use.
|
341
339
|
#
|
342
|
-
# @return [Object] The result of the event.
|
340
|
+
# @return [Async::Task<Object>] The result of the event.
|
343
341
|
#
|
344
342
|
# @raise [Discorb::TimeoutError] If the event didn't occur in time.
|
345
343
|
#
|
@@ -416,7 +414,7 @@ module Discorb
|
|
416
414
|
#
|
417
415
|
# Starts the client.
|
418
416
|
# @note This method behavior will change by CLI.
|
419
|
-
# @see file:docs/cli.md
|
417
|
+
# @see file:docs/cli.md CLI documentation
|
420
418
|
#
|
421
419
|
# @param [String, nil] token The token to use.
|
422
420
|
#
|
data/lib/discorb/common.rb
CHANGED
@@ -4,7 +4,7 @@ module Discorb
|
|
4
4
|
# @return [String] The API base URL.
|
5
5
|
API_BASE_URL = "https://discord.com/api/v9"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.13.3"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
@@ -110,6 +110,33 @@ module Discorb
|
|
110
110
|
@value & 0xFFF
|
111
111
|
end
|
112
112
|
|
113
|
+
def inspect
|
114
|
+
"#<#{self.class} #{to_s}>"
|
115
|
+
end
|
116
|
+
|
113
117
|
alias id to_s
|
114
118
|
end
|
119
|
+
|
120
|
+
# @return [Object] Object that represents nil.
|
121
|
+
# This is used as a default value for optional parameters.
|
122
|
+
Unset = Object.new
|
123
|
+
class << Unset
|
124
|
+
def method_missing(*)
|
125
|
+
self
|
126
|
+
end
|
127
|
+
|
128
|
+
def or(other)
|
129
|
+
other
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
module DefineOr
|
134
|
+
refine Object do
|
135
|
+
def or(other)
|
136
|
+
self
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
using DefineOr
|
115
142
|
end
|
data/lib/discorb/components.rb
CHANGED
@@ -6,6 +6,10 @@ module Discorb
|
|
6
6
|
# Represents a Discord component.
|
7
7
|
#
|
8
8
|
class Component
|
9
|
+
def inspect
|
10
|
+
"#<#{self.class}>"
|
11
|
+
end
|
12
|
+
|
9
13
|
class << self
|
10
14
|
#
|
11
15
|
# Create a new component from hash data.
|
@@ -142,6 +146,10 @@ module Discorb
|
|
142
146
|
end
|
143
147
|
end
|
144
148
|
|
149
|
+
def inspect
|
150
|
+
"#<#{self.class}: #{@custom_id || @url}>"
|
151
|
+
end
|
152
|
+
|
145
153
|
class << self
|
146
154
|
# @private
|
147
155
|
attr_reader :styles
|
@@ -218,6 +226,10 @@ module Discorb
|
|
218
226
|
}
|
219
227
|
end
|
220
228
|
|
229
|
+
def inspect
|
230
|
+
"#<#{self.class}: #{@custom_id}>"
|
231
|
+
end
|
232
|
+
|
221
233
|
#
|
222
234
|
# Represents an option of a select menu.
|
223
235
|
#
|
data/lib/discorb/dictionary.rb
CHANGED
data/lib/discorb/embed.rb
CHANGED
data/lib/discorb/emoji.rb
CHANGED
@@ -13,6 +13,10 @@ module Discorb
|
|
13
13
|
def ==(other)
|
14
14
|
eql?(other)
|
15
15
|
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
"#<#{self.class}>"
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
# Represents a custom emoji in discord.
|
@@ -78,8 +82,7 @@ module Discorb
|
|
78
82
|
|
79
83
|
#
|
80
84
|
# Edit the emoji.
|
81
|
-
# @
|
82
|
-
# @macro http
|
85
|
+
# @async
|
83
86
|
# @macro edit
|
84
87
|
#
|
85
88
|
# @param [String] name The new name of the emoji.
|
@@ -88,11 +91,11 @@ module Discorb
|
|
88
91
|
#
|
89
92
|
# @return [Async::Task<self>] The edited emoji.
|
90
93
|
#
|
91
|
-
def edit(name:
|
94
|
+
def edit(name: Discorb::Unset, roles: Discorb::Unset, reason: nil)
|
92
95
|
Async do
|
93
96
|
payload = {}
|
94
|
-
payload[:name] = name if name !=
|
95
|
-
payload[:roles] = roles.map { |r| Discorb::Utils.try(r, :id) } if roles !=
|
97
|
+
payload[:name] = name if name != Discorb::Unset
|
98
|
+
payload[:roles] = roles.map { |r| Discorb::Utils.try(r, :id) } if roles != Discorb::Unset
|
96
99
|
@client.http.patch("/guilds/#{@guild.id}/emojis/#{@id}", payload, audit_log_reason: reason)
|
97
100
|
self
|
98
101
|
end
|
@@ -102,8 +105,7 @@ module Discorb
|
|
102
105
|
|
103
106
|
#
|
104
107
|
# Delete the emoji.
|
105
|
-
# @
|
106
|
-
# @macro http
|
108
|
+
# @async
|
107
109
|
#
|
108
110
|
# @param [String] reason The reason for deleting the emoji.
|
109
111
|
#
|