discorb 0.5.0 → 0.5.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/Changelog.md +7 -1
- data/Gemfile.lock +1 -1
- data/Rakefile +1 -5
- data/docs/application_command.md +52 -25
- data/lib/discorb/client.rb +1 -1
- data/lib/discorb/command.rb +23 -15
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/gateway.rb +1 -1
- data/lib/discorb/http.rb +1 -1
- data/lib/discorb/interaction.rb +1 -1
- data/lib/discorb/rate_limit.rb +15 -0
- data/template-replace/files/css/common.css +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c64c3d8d4c8293ba42d1c6ab6042b9c03b12f52b2cbdd92afb3ab483e82b8b
|
4
|
+
data.tar.gz: ad9c479984defc53a872cf196bd7476f7838fe9f004be6d817e78b4b5ebf3fbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc9a269f561e1a53ce46dbf0a026ae34999633e966bc7f286383cb0583160a85e6aaf5a1d2ee8596e72a7454052a119e7db24394abdf689f744c0cef85b5e2a4
|
7
|
+
data.tar.gz: f0d14f5f858848e3a3d4877a505e998da9a76b12d57b31000d28b827d3acb47c1a1025214315abe900fcce6cf043632af563f4e43c4f6e942020c6f1bf059145
|
data/Changelog.md
CHANGED
@@ -105,4 +105,10 @@
|
|
105
105
|
- Change: Use zlib stream instead
|
106
106
|
- Add: Add tutorials
|
107
107
|
- Add: Add ratelimit handler
|
108
|
-
- Change: Make `--git` option in `discorb init` false
|
108
|
+
- Change: Make `--git` option in `discorb init` false
|
109
|
+
|
110
|
+
## 0.5.1
|
111
|
+
|
112
|
+
- Add: Can use block for defining group commands
|
113
|
+
- Fix: Fix bug in subcommands
|
114
|
+
- Fix: Fix bug in receiving commands
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -163,13 +163,9 @@ namespace :document do
|
|
163
163
|
FileUtils.cp_r("./doc/.", "./tmp-doc")
|
164
164
|
FileUtils.rm_rf("doc")
|
165
165
|
end
|
166
|
-
version = "."
|
167
|
-
Rake::Task["document:yard"].execute
|
168
|
-
Rake::Task["document:replace:html"].execute
|
169
|
-
Rake::Task["document:replace:css"].execute
|
170
|
-
Rake::Task["document:replace:eol"].execute
|
171
166
|
sh "git switch main -f"
|
172
167
|
FileUtils.cp_r("./tmp-doc/.", "./doc")
|
168
|
+
FileUtils.cp_r("./doc/#{tags.last.delete_prefix("v")}/.", "./doc")
|
173
169
|
sputs "Successfully built all versions"
|
174
170
|
rescue => e
|
175
171
|
sh "git switch main -f"
|
data/docs/application_command.md
CHANGED
@@ -53,11 +53,11 @@ In `options`, hash should be like this:
|
|
53
53
|
|
54
54
|
```ruby
|
55
55
|
{
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
"Name" => {
|
57
|
+
type: :string,
|
58
|
+
required: true,
|
59
|
+
description: "The description of the command."
|
60
|
+
}
|
61
61
|
}
|
62
62
|
```
|
63
63
|
|
@@ -73,19 +73,19 @@ In `options`, hash should be like this:
|
|
73
73
|
|
74
74
|
```ruby
|
75
75
|
{
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
}
|
76
|
+
"vocaloid" => {
|
77
|
+
required: true,
|
78
|
+
description: "The vocaloid which you like.",
|
79
|
+
type: :string,
|
80
|
+
choices: {
|
81
|
+
"Hatsune Miku" => "miku",
|
82
|
+
"Kagamine Rin" => "rin",
|
83
|
+
"Kagamine Len" => "len",
|
84
|
+
"Megurine Luka" => "luka",
|
85
|
+
"MEIKO" => "meiko",
|
86
|
+
"KAITO" => "kaito",
|
88
87
|
}
|
88
|
+
}
|
89
89
|
}
|
90
90
|
|
91
91
|
# Note: This aritcle is written in 8/31.
|
@@ -113,22 +113,47 @@ To register a group of slash commands, use {Discorb::Command::Handler#slash_grou
|
|
113
113
|
group = client.slash_group("settings", "Set settings of bot.")
|
114
114
|
|
115
115
|
group.slash("message_expand", "Whether bot should expand message.", {
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
"enabled" => {
|
117
|
+
type: :boolean,
|
118
|
+
description: "Whether bot should expand message."
|
119
|
+
}
|
120
120
|
}) do |interaction|
|
121
121
|
# ...
|
122
122
|
end
|
123
123
|
|
124
124
|
group.slash("bump_alert", "Whether bot should notify DISBOARD bump.", {
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
125
|
+
"enabled" => {
|
126
|
+
type: :boolean,
|
127
|
+
description: "Whether bot should notify DISBOARD bump."
|
128
|
+
}
|
129
129
|
}) do |interaction|
|
130
130
|
# ...
|
131
131
|
end
|
132
|
+
|
133
|
+
```
|
134
|
+
|
135
|
+
Since v0.5.1, You can use block for register commands.
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
|
139
|
+
client.slash_group("settings", "Set settings of bot.") do
|
140
|
+
slash("message_expand", "Whether bot should expand message.", {
|
141
|
+
"enabled" => {
|
142
|
+
type: :boolean,
|
143
|
+
description: "Whether bot should expand message."
|
144
|
+
}
|
145
|
+
}) do |interaction|
|
146
|
+
# ...
|
147
|
+
end
|
148
|
+
slash("bump_alert", "Whether bot should notify DISBOARD bump.", {
|
149
|
+
"enabled" => {
|
150
|
+
type: :boolean,
|
151
|
+
description: "Whether bot should notify DISBOARD bump."
|
152
|
+
}
|
153
|
+
}) do |interaction|
|
154
|
+
# ...
|
155
|
+
end
|
156
|
+
end
|
132
157
|
```
|
133
158
|
|
134
159
|
You can make subcommand group by using {Discorb::Command::Command::GroupCommand#group}.
|
@@ -210,6 +235,8 @@ end
|
|
210
235
|
|
211
236
|
```
|
212
237
|
|
238
|
+
Same as above, you can use block for register commands since v0.5.1.
|
239
|
+
|
213
240
|
### Register User Context Menu Command
|
214
241
|
|
215
242
|
```ruby
|
data/lib/discorb/client.rb
CHANGED
data/lib/discorb/command.rb
CHANGED
@@ -44,13 +44,16 @@ module Discorb
|
|
44
44
|
# @param [String] description Command description.
|
45
45
|
# @param [Array<#to_s>] guild_ids Guild IDs to restrict the command to.
|
46
46
|
#
|
47
|
+
# @yield Block to execute as the command. It can be used to define sub-commands.
|
48
|
+
# @yieldself [Discorb::Command::Command::GroupCommand] Group command.
|
49
|
+
#
|
47
50
|
# @return [Discorb::Command::Command::GroupCommand] Command object.
|
48
51
|
#
|
49
52
|
# @see file:docs/slash_command.md
|
50
53
|
#
|
51
|
-
def slash_group(command_name, description, guild_ids: [])
|
52
|
-
command = Discorb::Command::Command::GroupCommand.new(command_name, description, guild_ids, nil)
|
53
|
-
|
54
|
+
def slash_group(command_name, description, guild_ids: [], &block)
|
55
|
+
command = Discorb::Command::Command::GroupCommand.new(command_name, description, guild_ids, nil, self)
|
56
|
+
command.instance_eval(&block) if block_given?
|
54
57
|
command
|
55
58
|
end
|
56
59
|
|
@@ -174,6 +177,7 @@ module Discorb
|
|
174
177
|
@guild_ids = guild_ids.map(&:to_s)
|
175
178
|
@block = block
|
176
179
|
@type = Discorb::Command::Command.types[type]
|
180
|
+
@type_raw = 1
|
177
181
|
@options = options
|
178
182
|
@id = nil
|
179
183
|
@parent = parent
|
@@ -241,10 +245,11 @@ module Discorb
|
|
241
245
|
attr_reader :description
|
242
246
|
|
243
247
|
# @!visibility private
|
244
|
-
def initialize(name, description, guild_ids, type)
|
248
|
+
def initialize(name, description, guild_ids, type, client)
|
245
249
|
super(name, guild_ids, block, type)
|
246
250
|
@description = description
|
247
|
-
@commands =
|
251
|
+
@commands = client.commands
|
252
|
+
@client = client
|
248
253
|
@id_map = Discorb::Dictionary.new
|
249
254
|
end
|
250
255
|
|
@@ -302,13 +307,16 @@ module Discorb
|
|
302
307
|
# @param [String] command_name Group name.
|
303
308
|
# @param [String] description Group description.
|
304
309
|
#
|
310
|
+
# @yield Block to execute as the command. It can be used to define sub-commands.
|
311
|
+
# @yieldself [Discorb::Command::Command::SubcommandGroup] Group command.
|
312
|
+
#
|
305
313
|
# @return [Discorb::Command::Command::SubcommandGroup] Command object.
|
306
314
|
#
|
307
315
|
# @see file:docs/slash_command.md
|
308
316
|
#
|
309
|
-
def group(command_name, description)
|
310
|
-
command = Discorb::Command::Command::SubcommandGroup.new(command_name, description, @name)
|
311
|
-
|
317
|
+
def group(command_name, description, &block)
|
318
|
+
command = Discorb::Command::Command::SubcommandGroup.new(command_name, description, @name, @client)
|
319
|
+
command.instance_eval(&block) if block_given?
|
312
320
|
command
|
313
321
|
end
|
314
322
|
|
@@ -328,7 +336,7 @@ module Discorb
|
|
328
336
|
{
|
329
337
|
name: command.name,
|
330
338
|
description: command.description,
|
331
|
-
default_permission:
|
339
|
+
default_permission: true,
|
332
340
|
type: 1,
|
333
341
|
options: command.to_hash[:options],
|
334
342
|
}
|
@@ -336,7 +344,7 @@ module Discorb
|
|
336
344
|
{
|
337
345
|
name: command.name,
|
338
346
|
description: command.description,
|
339
|
-
default_permission:
|
347
|
+
default_permission: true,
|
340
348
|
type: 2,
|
341
349
|
options: command.commands.map { |c| c.to_hash.merge(type: 1) },
|
342
350
|
}
|
@@ -360,10 +368,10 @@ module Discorb
|
|
360
368
|
attr_reader :commands
|
361
369
|
|
362
370
|
# @!visibility private
|
363
|
-
def initialize(name, description,
|
364
|
-
super(name, description, [],
|
371
|
+
def initialize(name, description, parent, client)
|
372
|
+
super(name, description, [], 1, client)
|
365
373
|
|
366
|
-
@commands =
|
374
|
+
@commands = client.commands
|
367
375
|
@parent = parent
|
368
376
|
end
|
369
377
|
|
@@ -376,8 +384,8 @@ module Discorb
|
|
376
384
|
# @param (see Discorb::Command::Handler#slash)
|
377
385
|
# @return [Discorb::Command::Command::SlashCommand] The added subcommand.
|
378
386
|
#
|
379
|
-
def slash(command_name, description, options = {},
|
380
|
-
command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [],
|
387
|
+
def slash(command_name, description, options = {}, &block)
|
388
|
+
command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], block, 1, @parent + " " + @name)
|
381
389
|
@commands << command
|
382
390
|
command
|
383
391
|
end
|
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.5.
|
7
|
+
VERSION = "0.5.1"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://github.com/discorb-lib/discorb #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
data/lib/discorb/gateway.rb
CHANGED
data/lib/discorb/http.rb
CHANGED
data/lib/discorb/interaction.rb
CHANGED
@@ -297,7 +297,7 @@ module Discorb
|
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
|
-
unless (command = @client.commands.find { |c| c.to_s == name })
|
300
|
+
unless (command = @client.commands.find { |c| c.to_s == name && c.type_raw == 1 })
|
301
301
|
@client.log.warn "Unknown command name #{name}, ignoreing"
|
302
302
|
next
|
303
303
|
end
|
data/lib/discorb/rate_limit.rb
CHANGED
@@ -3,14 +3,22 @@
|
|
3
3
|
module Discorb
|
4
4
|
#
|
5
5
|
# Class to handle rate limiting.
|
6
|
+
# @private
|
6
7
|
#
|
7
8
|
class RatelimitHandler
|
9
|
+
# @!visibility private
|
8
10
|
def initialize(client)
|
9
11
|
@client = client
|
10
12
|
@ratelimit_hash = {}
|
11
13
|
@path_ratelimit_hash = {}
|
12
14
|
end
|
13
15
|
|
16
|
+
#
|
17
|
+
# Wait for the rate limit to reset.
|
18
|
+
#
|
19
|
+
# @param [String] method The HTTP method.
|
20
|
+
# @param [String] path The path.
|
21
|
+
#
|
14
22
|
def wait(method, path)
|
15
23
|
return if path.start_with?("https://")
|
16
24
|
|
@@ -28,6 +36,13 @@ module Discorb
|
|
28
36
|
sleep(b[:reset_at] - Time.now.to_i)
|
29
37
|
end
|
30
38
|
|
39
|
+
#
|
40
|
+
# Save the rate limit.
|
41
|
+
#
|
42
|
+
# @param [String] method The HTTP method.
|
43
|
+
# @param [String] path The path.
|
44
|
+
# @param [Net::HTTPResponse] resp The response.
|
45
|
+
#
|
31
46
|
def save(method, path, resp)
|
32
47
|
return unless resp["X-RateLimit-Remaining"]
|
33
48
|
|