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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26ef2cd9945ad11a9816b4ece328391c265b8f59f8b9a67e66326e21414f083c
4
- data.tar.gz: 06662ff1518386e95e615afffc6b8338cb9e337bb0dc36c66f6d1d79fd7a01e8
3
+ metadata.gz: 54c64c3d8d4c8293ba42d1c6ab6042b9c03b12f52b2cbdd92afb3ab483e82b8b
4
+ data.tar.gz: ad9c479984defc53a872cf196bd7476f7838fe9f004be6d817e78b4b5ebf3fbd
5
5
  SHA512:
6
- metadata.gz: 83ddc5818285d4ed50e08998446a5fa9763cffe9c0a1992a70085af38a323e304851ca4dd77f43a8108e4ece850f097eaca9dc119b83c9bdb9a66e5c32b40f5a
7
- data.tar.gz: 8a409f031d896344586bb2001019b9431299683a99df36f090f3a0da748d08bd6b4f2191c0a32823106d5b3b0cd6d22624106367d8e4adc400acf430ddb60370
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- discorb (0.5.0)
4
+ discorb (0.5.1)
5
5
  async (~> 1.30.1)
6
6
  async-http (~> 0.56.5)
7
7
  async-websocket (~> 0.19.0)
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"
@@ -53,11 +53,11 @@ In `options`, hash should be like this:
53
53
 
54
54
  ```ruby
55
55
  {
56
- "Name" => {
57
- type: :string,
58
- required: true,
59
- description: "The description of the command."
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
- "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",
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
- "enabled" => {
117
- type: :boolean,
118
- description: "Whether bot should expand message."
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
- "enabled" => {
126
- type: :boolean,
127
- description: "Whether bot should notify DISBOARD bump."
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
@@ -422,7 +422,7 @@ module Discorb
422
422
  end
423
423
  end
424
424
  start_client(token)
425
- when "setup_command"
425
+ when "setup"
426
426
  setup_commands(token)
427
427
  end
428
428
  end
@@ -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
- @commands << command
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
- @commands << command
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: command.enabled,
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: command.enabled,
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, enabled, parent)
364
- super(name, description, [], enabled, 1)
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 = {}, enabled: true, &block)
380
- command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], enabled, block, 1, @parent + " " + @name)
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
@@ -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.0"
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
 
@@ -545,7 +545,7 @@ module Discorb
545
545
  connect_gateway(true)
546
546
  end
547
547
  when 11
548
- @log.info "Received opcode 11"
548
+ @log.debug "Received opcode 11"
549
549
  @ping = Time.now.to_f - @heartbeat_before
550
550
  when 0
551
551
  handle_event(payload[:t], data)
data/lib/discorb/http.rb CHANGED
@@ -5,7 +5,7 @@ require "net/https"
5
5
  module Discorb
6
6
  #
7
7
  # A class to handle http requests.
8
- # This class is internal use only.
8
+ # @private
9
9
  #
10
10
  class HTTP
11
11
  @nil_body = nil
@@ -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
@@ -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
 
@@ -421,7 +421,7 @@ code[class=""] {
421
421
 
422
422
  .docstring .abstract {
423
423
  --dstr-back: var(--background-modifier-hover);
424
- --dstr-fore: var(--interactive-hover);
424
+ --dstr-fore: var(--interactive-muted);
425
425
  }
426
426
 
427
427
  .docstring .note {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discorb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sevenc-nanashi