discorb 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/docs/events.md +1 -2
- data/docs/extension.md +27 -0
- data/lib/discorb/client.rb +11 -0
- data/lib/discorb/command.rb +7 -38
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/extension.rb +9 -0
- data/lib/discorb/gateway.rb +2 -4
- data/lib/discorb/interaction.rb +1 -1
- data/lib/discorb.rb +2 -2
- 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: 3d17006d6ca103247dcf304581c61104054722b1af32bc8b3ec3d23b7f5e8680
|
4
|
+
data.tar.gz: 92c481e5532d3e990ca73b891c71a87f5a4a2e6217ff7d7c5677519dbeaf4259
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b305d2f608c0506b7c84f53d16e4384710d454d5deacc69d51a55dbf81fe25d80ab7226717cb12480e07ba25f069a59a49a50608826d711c2a84edb4ec67258c
|
7
|
+
data.tar.gz: c40281fb460527163504b8fe999f02a57db3190532a47c78ee25d71871372ff4c720a7ec0e17c70853083ad7327ae574e418b080d7379c98d683fcc1ccb0169e
|
data/Changelog.md
CHANGED
@@ -111,4 +111,9 @@
|
|
111
111
|
|
112
112
|
- Add: Can use block for defining group commands
|
113
113
|
- Fix: Fix bug in subcommands
|
114
|
-
- Fix: Fix bug in receiving commands
|
114
|
+
- Fix: Fix bug in receiving commands
|
115
|
+
|
116
|
+
## 0.5.2
|
117
|
+
|
118
|
+
- Fix: Fix bug of registering commands
|
119
|
+
- Add: Add way to register commands in Extension
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
[![Document](https://img.shields.io/badge/Document-discord--lib.github.io-blue.svg)](https://discorb-lib.github.io/)
|
3
3
|
[![Gem](https://img.shields.io/gem/dt/discorb?logo=rubygems&logoColor=fff)](https://rubygems.org/gems/discorb)
|
4
4
|
[![Gem](https://img.shields.io/gem/v/discorb?logo=rubygems&logoColor=fff)](https://rubygems.org/gems/discorb)
|
5
|
-
[![Discord](https://img.shields.io/discord/863581274916913193?logo=discord&logoColor=fff&color=5865f2&label=Discord)](https://discord.gg/hCP6zq8Vpj)
|
5
|
+
[![Discord](https://img.shields.io/discord/863581274916913193?logo=discord&logoColor=fff&color=5865f2&label=Discord)](https://discord.gg/hCP6zq8Vpj)
|
6
|
+
[![GitHub](https://img.shields.io/github/stars/discorb-lib/discorb?color=24292e&label=Stars&logo=GitHub&logoColor=fff)](https://github.com/discorb-lib/discorb)
|
6
7
|
|
7
8
|
discorb is a Discord API wrapper for Ruby.
|
8
9
|
|
data/docs/events.md
CHANGED
@@ -219,14 +219,13 @@ Fires when a guild integration is created.
|
|
219
219
|
| ---------- | ----- | ----------- |
|
220
220
|
|`integration`| {Discorb::Integration}| The created integration. |
|
221
221
|
|
222
|
-
#### `integration_update(
|
222
|
+
#### `integration_update(after)`
|
223
223
|
|
224
224
|
Fires when a guild integration is updated.
|
225
225
|
|
226
226
|
|
227
227
|
| Parameter | Type | Description |
|
228
228
|
| ---------- | ----- | ----------- |
|
229
|
-
|`before` | {Discorb::Integration}| The integration before the update. |
|
230
229
|
|`after` | {Discorb::Integration}| The integration after the update. |
|
231
230
|
|
232
231
|
#### `integration_delete(integration)`
|
data/docs/extension.md
CHANGED
@@ -34,6 +34,33 @@ module MyExtension
|
|
34
34
|
end
|
35
35
|
```
|
36
36
|
|
37
|
+
## Register Command
|
38
|
+
|
39
|
+
Since v0.5.2, {Discorb::Extension} includes {Discorb::Command::Handler} module, so you can register command with {Discorb::Command::Handler#slash} and {Discorb::Command::Handler#slash_group}.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
module MyExtension
|
43
|
+
extend Discorb::Extension
|
44
|
+
|
45
|
+
slash("command", "Command") do |interaction|
|
46
|
+
# ...
|
47
|
+
end
|
48
|
+
|
49
|
+
slash_group("group", "Group") do
|
50
|
+
slash("subcommand", "Subcommand") do |interaction|
|
51
|
+
# ...
|
52
|
+
end
|
53
|
+
|
54
|
+
group("subgroup", "Subcommand group") do
|
55
|
+
slash("group_subcommand", "Command in Subcommand group") do |interaction|
|
56
|
+
# ...
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
|
37
64
|
## Load extension
|
38
65
|
|
39
66
|
Use {Discorb::Client#extend} to load extension.
|
data/lib/discorb/client.rb
CHANGED
@@ -49,6 +49,8 @@ module Discorb
|
|
49
49
|
attr_reader :ping
|
50
50
|
# @return [:initialized, :running, :closed] The status of the client.
|
51
51
|
attr_reader :status
|
52
|
+
# @private
|
53
|
+
attr_reader :bottom_commands
|
52
54
|
|
53
55
|
#
|
54
56
|
# Initializes a new client.
|
@@ -85,6 +87,7 @@ module Discorb
|
|
85
87
|
@tasks = []
|
86
88
|
@conditions = {}
|
87
89
|
@commands = []
|
90
|
+
@bottom_commands = []
|
88
91
|
@status = :initialized
|
89
92
|
end
|
90
93
|
|
@@ -372,6 +375,14 @@ module Discorb
|
|
372
375
|
@events[name] << event
|
373
376
|
end
|
374
377
|
end
|
378
|
+
@commands.delete_if do |cmd|
|
379
|
+
cmd.respond_to? :extension and cmd.extension == mod.name
|
380
|
+
end
|
381
|
+
mod.commands.each do |cmd|
|
382
|
+
cmd.define_singleton_method(:extension) { mod.name }
|
383
|
+
@commands << cmd
|
384
|
+
end
|
385
|
+
@bottom_commands += mod.bottom_commands
|
375
386
|
mod.client = self
|
376
387
|
end
|
377
388
|
super(mod)
|
data/lib/discorb/command.rb
CHANGED
@@ -34,6 +34,7 @@ module Discorb
|
|
34
34
|
def slash(command_name, description, options = {}, guild_ids: [], &block)
|
35
35
|
command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, guild_ids, block, 1, "")
|
36
36
|
@commands << command
|
37
|
+
@bottom_commands << command
|
37
38
|
command
|
38
39
|
end
|
39
40
|
|
@@ -54,6 +55,7 @@ module Discorb
|
|
54
55
|
def slash_group(command_name, description, guild_ids: [], &block)
|
55
56
|
command = Discorb::Command::Command::GroupCommand.new(command_name, description, guild_ids, nil, self)
|
56
57
|
command.instance_eval(&block) if block_given?
|
58
|
+
@commands << command
|
57
59
|
command
|
58
60
|
end
|
59
61
|
|
@@ -248,7 +250,7 @@ module Discorb
|
|
248
250
|
def initialize(name, description, guild_ids, type, client)
|
249
251
|
super(name, guild_ids, block, type)
|
250
252
|
@description = description
|
251
|
-
@commands =
|
253
|
+
@commands = []
|
252
254
|
@client = client
|
253
255
|
@id_map = Discorb::Dictionary.new
|
254
256
|
end
|
@@ -261,42 +263,7 @@ module Discorb
|
|
261
263
|
#
|
262
264
|
def slash(command_name, description, options = {}, &block)
|
263
265
|
command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], block, 1, @name)
|
264
|
-
|
265
|
-
ret = {
|
266
|
-
type: case (value[:type].is_a?(Array) ? value[:type].first : value[:type])
|
267
|
-
when String, :string
|
268
|
-
3
|
269
|
-
when Integer
|
270
|
-
4
|
271
|
-
when TrueClass, FalseClass, :boolean
|
272
|
-
5
|
273
|
-
when Discorb::User, Discorb::Member, :user, :member
|
274
|
-
6
|
275
|
-
when Discorb::Channel, :channel
|
276
|
-
7
|
277
|
-
when Discorb::Role, :role
|
278
|
-
8
|
279
|
-
when :mentionable
|
280
|
-
9
|
281
|
-
when Float
|
282
|
-
10
|
283
|
-
end,
|
284
|
-
name: name,
|
285
|
-
description: value[:description],
|
286
|
-
required: !value[:optional],
|
287
|
-
}
|
288
|
-
if value[:type].is_a?(Array)
|
289
|
-
ret[:choices] = value[:type]
|
290
|
-
end
|
291
|
-
|
292
|
-
ret
|
293
|
-
end
|
294
|
-
{
|
295
|
-
name: @name,
|
296
|
-
default_permission: true,
|
297
|
-
description: @description,
|
298
|
-
options: options_payload,
|
299
|
-
}
|
266
|
+
@client.bottom_commands << command
|
300
267
|
@commands << command
|
301
268
|
command
|
302
269
|
end
|
@@ -317,6 +284,7 @@ module Discorb
|
|
317
284
|
def group(command_name, description, &block)
|
318
285
|
command = Discorb::Command::Command::SubcommandGroup.new(command_name, description, @name, @client)
|
319
286
|
command.instance_eval(&block) if block_given?
|
287
|
+
@commands << command
|
320
288
|
command
|
321
289
|
end
|
322
290
|
|
@@ -371,7 +339,7 @@ module Discorb
|
|
371
339
|
def initialize(name, description, parent, client)
|
372
340
|
super(name, description, [], 1, client)
|
373
341
|
|
374
|
-
@commands =
|
342
|
+
@commands = []
|
375
343
|
@parent = parent
|
376
344
|
end
|
377
345
|
|
@@ -387,6 +355,7 @@ module Discorb
|
|
387
355
|
def slash(command_name, description, options = {}, &block)
|
388
356
|
command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], block, 1, @parent + " " + @name)
|
389
357
|
@commands << command
|
358
|
+
@client.bottom_commands << command
|
390
359
|
command
|
391
360
|
end
|
392
361
|
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.2"
|
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/extension.rb
CHANGED
@@ -8,6 +8,9 @@ module Discorb
|
|
8
8
|
# @abstract
|
9
9
|
#
|
10
10
|
module Extension
|
11
|
+
include Discorb::Command::Handler
|
12
|
+
undef setup_commands
|
13
|
+
|
11
14
|
@events = {}
|
12
15
|
@client = nil
|
13
16
|
|
@@ -46,12 +49,18 @@ module Discorb
|
|
46
49
|
|
47
50
|
# @return [Hash{Symbol => Array<Discorb::Event>}] The events of the extension.
|
48
51
|
attr_reader :events
|
52
|
+
# @return [Array<Discorb::Command::Command] The commands of the extension.
|
53
|
+
attr_reader :commands
|
54
|
+
# @private
|
55
|
+
attr_reader :bottom_commands
|
49
56
|
|
50
57
|
# @!visibility private
|
51
58
|
attr_accessor :client
|
52
59
|
|
53
60
|
def self.extended(obj)
|
54
61
|
obj.instance_variable_set(:@events, {})
|
62
|
+
obj.instance_variable_set(:@commands, [])
|
63
|
+
obj.instance_variable_set(:@bottom_commands, [])
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
data/lib/discorb/gateway.rb
CHANGED
@@ -778,11 +778,9 @@ module Discorb
|
|
778
778
|
dispatch(:integration_create, Integration.new(self, data, data[:guild_id]))
|
779
779
|
when "INTEGRATION_UPDATE"
|
780
780
|
return @log.warn "Unknown guild id #{data[:guild_id]}, ignoring" unless (guild = @guilds[data[:guild_id]])
|
781
|
-
return @log.warn "Unknown integration id #{data[:id]}, ignoring" unless (integration = guild.integrations[data[:id]])
|
782
781
|
|
783
|
-
before = Integration.new(self,
|
784
|
-
|
785
|
-
dispatch(:integration_update, before, integration)
|
782
|
+
before = Integration.new(self, data, data[:guild_id])
|
783
|
+
dispatch(:integration_update, integration)
|
786
784
|
when "INTEGRATION_DELETE"
|
787
785
|
return @log.warn "Unknown guild id #{data[:guild_id]}, ignoring" unless (guild = @guilds[data[:guild_id]])
|
788
786
|
return @log.warn "Unknown integration id #{data[:id]}, ignoring" unless (integration = guild.integrations.delete(data[:id]))
|
data/lib/discorb/interaction.rb
CHANGED
@@ -297,7 +297,7 @@ module Discorb
|
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
|
-
unless (command = @client.
|
300
|
+
unless (command = @client.bottom_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.rb
CHANGED
@@ -41,11 +41,11 @@ end
|
|
41
41
|
|
42
42
|
require_order = %w[common flag dictionary error rate_limit http intents emoji_table modules] +
|
43
43
|
%w[user member guild emoji channel embed message] +
|
44
|
-
%w[application audit_logs color components event
|
44
|
+
%w[application audit_logs color components event] +
|
45
45
|
%w[file guild_template image integration interaction invite log permission] +
|
46
46
|
%w[presence reaction role sticker utils voice_state webhook] +
|
47
47
|
%w[gateway_requests gateway command] +
|
48
|
-
%w[asset client extend]
|
48
|
+
%w[asset extension client extend]
|
49
49
|
require_order.each do |name|
|
50
50
|
require_relative "discorb/#{name}.rb"
|
51
51
|
end
|