discorb 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +57 -0
- data/.github/ISSUE_TEMPLATE/config.yml +8 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +38 -0
- data/Changelog.md +6 -1
- data/Gemfile.lock +1 -1
- data/docs/application_command.md +8 -8
- data/docs/events.md +29 -0
- data/docs/extension.md +1 -1
- data/lib/discorb/{command.rb → app_command.rb} +25 -25
- data/lib/discorb/client.rb +13 -14
- data/lib/discorb/color.rb +59 -29
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/error.rb +1 -1
- data/lib/discorb/event.rb +5 -5
- data/lib/discorb/extension.rb +9 -9
- data/lib/discorb/intents.rb +2 -2
- data/lib/discorb.rb +1 -1
- data/po/yard.pot +37 -37
- data/sig/discorb.rbs +40 -40
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d2ef47227e1e5895bdcaf6a67641d22319909c0f6a461d72ab35be1e0c9a42b
|
4
|
+
data.tar.gz: 688a952b571421e8c43ca53b10f9404f6ba2abf8b9071222c35d3a10e34c5b7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fd5eb78a1acda90e3c673a8745a2a9954ff8b8817c38210c5c609e6a85b16e4074b59bf8ae7bcc7725f7f45f22dfd785fb5edd321e9f61994bb071e4aa25a43
|
7
|
+
data.tar.gz: 4bee75498af33d4716e033f51103382d8931c079495d27234cf07cf5e5b288891b40fb7e00902d3c1d7150249d0c820701d9962130890005bea5378e46af5ac8
|
@@ -0,0 +1,57 @@
|
|
1
|
+
---
|
2
|
+
name: Bug Report
|
3
|
+
about: A bug report for discorb.
|
4
|
+
labels:
|
5
|
+
- bug
|
6
|
+
---
|
7
|
+
|
8
|
+
<!--
|
9
|
+
Before submitting a bug report, please check that it is not already being, or has been, reported.
|
10
|
+
Don't forget to find closed issues and check if the bug is already fixed.
|
11
|
+
-->
|
12
|
+
|
13
|
+
## What is the bug?
|
14
|
+
|
15
|
+
<!--
|
16
|
+
Please describe the bug in detail.
|
17
|
+
Ex:
|
18
|
+
I want to sleep, but I can't.
|
19
|
+
-->
|
20
|
+
|
21
|
+
## What steps did you take to reproduce the bug?
|
22
|
+
|
23
|
+
<!--
|
24
|
+
Please describe the steps you took to reproduce the bug.
|
25
|
+
Ex:
|
26
|
+
1. Go to bed
|
27
|
+
2. Count sheeps
|
28
|
+
3. Observe
|
29
|
+
-->
|
30
|
+
|
31
|
+
## What did you expect to see?
|
32
|
+
|
33
|
+
<!--
|
34
|
+
Please describe what you expected to see.
|
35
|
+
Ex:
|
36
|
+
I can sleep.
|
37
|
+
-->
|
38
|
+
|
39
|
+
## What did you see instead?
|
40
|
+
|
41
|
+
<!--
|
42
|
+
Please describe what you saw instead.
|
43
|
+
Ex:
|
44
|
+
I can't sleep.
|
45
|
+
-->
|
46
|
+
|
47
|
+
## Environment information
|
48
|
+
|
49
|
+
<!--
|
50
|
+
Use `discorb show` to get the current machine.
|
51
|
+
-->
|
52
|
+
|
53
|
+
## Other information
|
54
|
+
|
55
|
+
<!--
|
56
|
+
Please describe any other information you want to include as such as the screenshots you took, or the logs you generated.
|
57
|
+
-->
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
name: Feature Request
|
3
|
+
labels:
|
4
|
+
- Feature Request
|
5
|
+
- Enhancement
|
6
|
+
about: Feature request for discorb's future.
|
7
|
+
---
|
8
|
+
<!--
|
9
|
+
Before submitting a feature request, please check there is no existing feature request for the feature you are requesting.
|
10
|
+
-->
|
11
|
+
|
12
|
+
|
13
|
+
## What is the feature you are requesting?
|
14
|
+
|
15
|
+
<!--
|
16
|
+
Please describe the feature you are requesting.
|
17
|
+
Ex: Create discorb-chan
|
18
|
+
-->
|
19
|
+
|
20
|
+
## Why do you need the feature?
|
21
|
+
|
22
|
+
<!--
|
23
|
+
Please describe the reason for the feature you are requesting.
|
24
|
+
Ex: She's cute.
|
25
|
+
-->
|
26
|
+
|
27
|
+
## Alternative considerations?
|
28
|
+
|
29
|
+
<!--
|
30
|
+
Please describe alternative considerations for the feature you are requesting.
|
31
|
+
Ex: Add discorb-kun
|
32
|
+
-->
|
33
|
+
|
34
|
+
## Additional context
|
35
|
+
|
36
|
+
<!--
|
37
|
+
Please describe any additional context you have for the feature you are requesting.
|
38
|
+
-->
|
data/Changelog.md
CHANGED
@@ -144,4 +144,9 @@
|
|
144
144
|
- Add: Add rbs (experimental)
|
145
145
|
- Add: Add `-t`, `--token` option to `discorb run`
|
146
146
|
- Add: Add `-g`, `--guild` option to `discorb setup`
|
147
|
-
- Change: Use `Async::Task<R>` instead of `R` in return value
|
147
|
+
- Change: Use `Async::Task<R>` instead of `R` in return value
|
148
|
+
|
149
|
+
## 0.6.1
|
150
|
+
|
151
|
+
- Change: Rename `Event#discriminator` to `Event#metadata`
|
152
|
+
- Add: Add `:override` to `Client#on`
|
data/Gemfile.lock
CHANGED
data/docs/application_command.md
CHANGED
@@ -11,9 +11,9 @@ From: [Discord API docs](https://discord.com/developers/docs/interactions/applic
|
|
11
11
|
## How do I register an application command?
|
12
12
|
|
13
13
|
Write to a your script:
|
14
|
-
- {Discorb::
|
15
|
-
- {Discorb::
|
16
|
-
- {Discorb::
|
14
|
+
- {Discorb::ApplicationCommand::Handler.slash}, {Discorb::ApplicationCommand::Handler.slash_group} for slash commands,
|
15
|
+
- {Discorb::ApplicationCommand::Handler.user_command} for user menu commands,
|
16
|
+
- {Discorb::ApplicationCommand::Handler.message_command} for message menu commands.
|
17
17
|
|
18
18
|
And then run `discorb setup` to register your application commands.
|
19
19
|
{file:docs/cli/setup.md Learn more about `discorb setup`}.
|
@@ -39,7 +39,7 @@ end
|
|
39
39
|
client.run(ENV["DISCORD_BOT_TOKEN"])
|
40
40
|
```
|
41
41
|
|
42
|
-
{Discorb::
|
42
|
+
{Discorb::ApplicationCommand::Handler#slash} takes 5 arguments:
|
43
43
|
|
44
44
|
| Argument | Description |
|
45
45
|
|---------|-------------|
|
@@ -107,7 +107,7 @@ In `type`, You must use one of the following:
|
|
107
107
|
|
108
108
|
### Group Slash Commands
|
109
109
|
|
110
|
-
To register a group of slash commands, use {Discorb::
|
110
|
+
To register a group of slash commands, use {Discorb::ApplicationCommand::Handler#slash_group}.
|
111
111
|
|
112
112
|
```ruby
|
113
113
|
group = client.slash_group("settings", "Set settings of bot.")
|
@@ -156,7 +156,7 @@ client.slash_group("settings", "Set settings of bot.") do
|
|
156
156
|
end
|
157
157
|
```
|
158
158
|
|
159
|
-
You can make subcommand group by using {Discorb::
|
159
|
+
You can make subcommand group by using {Discorb::ApplicationCommand::Command::GroupCommand#group}.
|
160
160
|
|
161
161
|
```ruby
|
162
162
|
group = client.slash_group("permission", "Set/Get command permissions.")
|
@@ -244,7 +244,7 @@ client.user_command("hello") do |interaction, user|
|
|
244
244
|
interaction.post("Hello, #{user.name}!")
|
245
245
|
end
|
246
246
|
```
|
247
|
-
{Discorb::
|
247
|
+
{Discorb::ApplicationCommand::Handler.user_command} takes 3 arguments:
|
248
248
|
|
249
249
|
| Parameter | Description |
|
250
250
|
| --- | --- |
|
@@ -268,7 +268,7 @@ client.message_command("Bookmark") do |interaction, message|
|
|
268
268
|
end
|
269
269
|
```
|
270
270
|
|
271
|
-
{Discorb::
|
271
|
+
{Discorb::ApplicationCommand::Handler.message_command} takes 3 arguments:
|
272
272
|
|
273
273
|
| Parameter | Description |
|
274
274
|
| --- | --- |
|
data/docs/events.md
CHANGED
@@ -30,6 +30,35 @@ end
|
|
30
30
|
|
31
31
|
If you want to seperate event handlers from the client, consider using {Discorb::Extension}. {file:docs/extension.md Learn more about extensions}.
|
32
32
|
|
33
|
+
Since v0.6.1, you can set `:override` to `true` to register overridable event handlers.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
client.on :message, override: true do |event|
|
37
|
+
puts "This event handler is overrideable!"
|
38
|
+
end
|
39
|
+
|
40
|
+
client.on :message do |event|
|
41
|
+
puts "Override!"
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
This example will print `Override!`, but not `This event handler is overrideable!`.
|
46
|
+
This is useful for registering event handlers for default behaviour on errors.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# In the library...
|
50
|
+
|
51
|
+
client.on :command_error, override: true do |event, error|
|
52
|
+
$stderr.puts "Command error:\n#{error.full_message}"
|
53
|
+
end
|
54
|
+
|
55
|
+
# In your code...
|
56
|
+
|
57
|
+
client.on :command_error do |event, error|
|
58
|
+
event.message.reply "An error occurred while executing that command!\n#{error.full_message}"
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
33
62
|
## Event reference
|
34
63
|
|
35
64
|
### Client events
|
data/docs/extension.md
CHANGED
@@ -36,7 +36,7 @@ end
|
|
36
36
|
|
37
37
|
## Register Command
|
38
38
|
|
39
|
-
Since v0.5.2, {Discorb::Extension} includes {Discorb::
|
39
|
+
Since v0.5.2, {Discorb::Extension} includes {Discorb::ApplicationCommand::Handler} module, so you can register command with {Discorb::ApplicationCommand::Handler#slash} and {Discorb::ApplicationCommand::Handler#slash_group}.
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
module MyExtension
|
@@ -4,9 +4,9 @@ module Discorb
|
|
4
4
|
#
|
5
5
|
# Handles application commands.
|
6
6
|
#
|
7
|
-
module
|
7
|
+
module ApplicationCommand
|
8
8
|
#
|
9
|
-
# Module to handle commands.
|
9
|
+
# Module to handle application commands.
|
10
10
|
#
|
11
11
|
module Handler
|
12
12
|
#
|
@@ -27,13 +27,13 @@ module Discorb
|
|
27
27
|
# @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
28
28
|
# @param [Proc] block Command block.
|
29
29
|
#
|
30
|
-
# @return [Discorb::
|
30
|
+
# @return [Discorb::ApplicationCommand::Command::SlashCommand] Command object.
|
31
31
|
#
|
32
32
|
# @see file:docs/application_command.md#register-slash-command
|
33
33
|
# @see file:docs/cli/setup.md
|
34
34
|
#
|
35
35
|
def slash(command_name, description, options = {}, guild_ids: nil, &block)
|
36
|
-
command = Discorb::
|
36
|
+
command = Discorb::ApplicationCommand::Command::SlashCommand.new(command_name, description, options, guild_ids, block, 1, "")
|
37
37
|
@commands << command
|
38
38
|
@bottom_commands << command
|
39
39
|
command
|
@@ -47,15 +47,15 @@ module Discorb
|
|
47
47
|
# @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
48
48
|
#
|
49
49
|
# @yield Block to execute as the command. It can be used to define sub-commands.
|
50
|
-
# @yieldself [Discorb::
|
50
|
+
# @yieldself [Discorb::ApplicationCommand::Command::GroupCommand] Group command.
|
51
51
|
#
|
52
|
-
# @return [Discorb::
|
52
|
+
# @return [Discorb::ApplicationCommand::Command::GroupCommand] Command object.
|
53
53
|
#
|
54
54
|
# @see file:docs/slash_command.md
|
55
55
|
# @see file:docs/cli/setup.md
|
56
56
|
#
|
57
57
|
def slash_group(command_name, description, guild_ids: nil, &block)
|
58
|
-
command = Discorb::
|
58
|
+
command = Discorb::ApplicationCommand::Command::GroupCommand.new(command_name, description, guild_ids, nil, self)
|
59
59
|
command.instance_eval(&block) if block_given?
|
60
60
|
@commands << command
|
61
61
|
command
|
@@ -68,13 +68,13 @@ module Discorb
|
|
68
68
|
# @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
69
69
|
# @param [Proc] block Command block.
|
70
70
|
# @yield [interaction, message] Block to execute.
|
71
|
-
# @yieldparam [Discorb::
|
71
|
+
# @yieldparam [Discorb::ApplicationCommandInteraction::UserMenuCommand] interaction Interaction object.
|
72
72
|
# @yieldparam [Discorb::Message] message Message object.
|
73
73
|
#
|
74
|
-
# @return [Discorb::
|
74
|
+
# @return [Discorb::ApplicationCommand::Command] Command object.
|
75
75
|
#
|
76
76
|
def message_command(command_name, guild_ids: nil, &block)
|
77
|
-
command = Discorb::
|
77
|
+
command = Discorb::ApplicationCommand::Command.new(command_name, guild_ids, block, 3)
|
78
78
|
@commands << command
|
79
79
|
command
|
80
80
|
end
|
@@ -86,13 +86,13 @@ module Discorb
|
|
86
86
|
# @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
87
87
|
# @param [Proc] block Command block.
|
88
88
|
# @yield [interaction, user] Block to execute.
|
89
|
-
# @yieldparam [Discorb::
|
89
|
+
# @yieldparam [Discorb::ApplicationCommandInteraction::UserMenuCommand] interaction Interaction object.
|
90
90
|
# @yieldparam [Discorb::User] user User object.
|
91
91
|
#
|
92
|
-
# @return [Discorb::
|
92
|
+
# @return [Discorb::ApplicationCommand::Command] Command object.
|
93
93
|
#
|
94
94
|
def user_command(command_name, guild_ids: nil, &block)
|
95
|
-
command = Discorb::
|
95
|
+
command = Discorb::ApplicationCommand::Command.new(command_name, guild_ids, block, 2)
|
96
96
|
@commands << command
|
97
97
|
command
|
98
98
|
end
|
@@ -163,7 +163,7 @@ module Discorb
|
|
163
163
|
@guild_ids = guild_ids&.map(&:to_s)
|
164
164
|
@block = block
|
165
165
|
@raw_type = type
|
166
|
-
@type = Discorb::
|
166
|
+
@type = Discorb::ApplicationCommand::Command.types[type]
|
167
167
|
@type_raw = type
|
168
168
|
@id_map = Discorb::Dictionary.new
|
169
169
|
end
|
@@ -251,7 +251,7 @@ module Discorb
|
|
251
251
|
# Represents the command with subcommands.
|
252
252
|
#
|
253
253
|
class GroupCommand < Command
|
254
|
-
# @return [Array<Discorb::
|
254
|
+
# @return [Array<Discorb::ApplicationCommand::Command::SlashCommand, Discorb::ApplicationCommand::Command::SubcommandGroup>] The subcommands of the command.
|
255
255
|
attr_reader :commands
|
256
256
|
# @return [String] The description of the command.
|
257
257
|
attr_reader :description
|
@@ -268,11 +268,11 @@ module Discorb
|
|
268
268
|
#
|
269
269
|
# Add new subcommand.
|
270
270
|
#
|
271
|
-
# @param (see Discorb::
|
272
|
-
# @return [Discorb::
|
271
|
+
# @param (see Discorb::ApplicationCommand::Handler#slash)
|
272
|
+
# @return [Discorb::ApplicationCommand::Command::SlashCommand] The added subcommand.
|
273
273
|
#
|
274
274
|
def slash(command_name, description, options = {}, &block)
|
275
|
-
command = Discorb::
|
275
|
+
command = Discorb::ApplicationCommand::Command::SlashCommand.new(command_name, description, options, [], block, 1, @name)
|
276
276
|
@client.bottom_commands << command
|
277
277
|
@commands << command
|
278
278
|
command
|
@@ -285,14 +285,14 @@ module Discorb
|
|
285
285
|
# @param [String] description Group description.
|
286
286
|
#
|
287
287
|
# @yield Block to execute as the command. It can be used to define sub-commands.
|
288
|
-
# @yieldself [Discorb::
|
288
|
+
# @yieldself [Discorb::ApplicationCommand::Command::SubcommandGroup] Group command.
|
289
289
|
#
|
290
|
-
# @return [Discorb::
|
290
|
+
# @return [Discorb::ApplicationCommand::Command::SubcommandGroup] Command object.
|
291
291
|
#
|
292
292
|
# @see file:docs/slash_command.md
|
293
293
|
#
|
294
294
|
def group(command_name, description, &block)
|
295
|
-
command = Discorb::
|
295
|
+
command = Discorb::ApplicationCommand::Command::SubcommandGroup.new(command_name, description, @name, @client)
|
296
296
|
command.instance_eval(&block) if block_given?
|
297
297
|
@commands << command
|
298
298
|
command
|
@@ -342,7 +342,7 @@ module Discorb
|
|
342
342
|
# Represents the subcommand group.
|
343
343
|
#
|
344
344
|
class SubcommandGroup < GroupCommand
|
345
|
-
# @return [Array<Discorb::
|
345
|
+
# @return [Array<Discorb::ApplicationCommand::Command::SlashCommand>] The subcommands of the command.
|
346
346
|
attr_reader :commands
|
347
347
|
|
348
348
|
# @!visibility private
|
@@ -359,11 +359,11 @@ module Discorb
|
|
359
359
|
|
360
360
|
#
|
361
361
|
# Add new subcommand.
|
362
|
-
# @param (see Discorb::
|
363
|
-
# @return [Discorb::
|
362
|
+
# @param (see Discorb::ApplicationCommand::Handler#slash)
|
363
|
+
# @return [Discorb::ApplicationCommand::Command::SlashCommand] The added subcommand.
|
364
364
|
#
|
365
365
|
def slash(command_name, description, options = {}, &block)
|
366
|
-
command = Discorb::
|
366
|
+
command = Discorb::ApplicationCommand::Command::SlashCommand.new(command_name, description, options, [], block, 1, @parent + " " + @name)
|
367
367
|
@commands << command
|
368
368
|
@client.bottom_commands << command
|
369
369
|
command
|
data/lib/discorb/client.rb
CHANGED
@@ -41,7 +41,7 @@ module Discorb
|
|
41
41
|
attr_reader :messages
|
42
42
|
# @return [Discorb::Logger] The logger.
|
43
43
|
attr_reader :log
|
44
|
-
# @return [Array<Discorb::
|
44
|
+
# @return [Array<Discorb::ApplicationCommand::Command>] The commands that the client is using.
|
45
45
|
attr_reader :commands
|
46
46
|
# @return [Float] The ping of the client.
|
47
47
|
# @note This will be calculated from heartbeat and heartbeat_ack.
|
@@ -99,14 +99,15 @@ module Discorb
|
|
99
99
|
#
|
100
100
|
# @param [Symbol] event_name The name of the event.
|
101
101
|
# @param [Symbol] id Custom ID of the event.
|
102
|
-
# @param [Hash]
|
102
|
+
# @param [Hash] metadata The metadata of the event.
|
103
103
|
# @param [Proc] block The block to execute when the event is triggered.
|
104
104
|
#
|
105
105
|
# @return [Discorb::Event] The event.
|
106
106
|
#
|
107
|
-
def on(event_name, id: nil, **
|
108
|
-
ne = Event.new(block, id,
|
107
|
+
def on(event_name, id: nil, **metadata, &block)
|
108
|
+
ne = Event.new(block, id, metadata)
|
109
109
|
@events[event_name] ||= []
|
110
|
+
@events[event_name].delete_if { |e| e.metadata[:override] }
|
110
111
|
@events[event_name] << ne
|
111
112
|
ne
|
112
113
|
end
|
@@ -118,12 +119,9 @@ module Discorb
|
|
118
119
|
#
|
119
120
|
# @return [Discorb::Event] The event.
|
120
121
|
#
|
121
|
-
def once(event_name, id: nil, **
|
122
|
-
|
123
|
-
|
124
|
-
@events[event_name] ||= []
|
125
|
-
@events[event_name] << ne
|
126
|
-
ne
|
122
|
+
def once(event_name, id: nil, **metadata, &block)
|
123
|
+
metadata[:once] = true
|
124
|
+
on(event_name, id: id, **metadata, &block)
|
127
125
|
end
|
128
126
|
|
129
127
|
#
|
@@ -177,7 +175,7 @@ module Discorb
|
|
177
175
|
lambda { |event_args|
|
178
176
|
Async(annotation: "Discorb event: #{event_name}") do |task|
|
179
177
|
if block.is_a?(Discorb::Event)
|
180
|
-
@events[event_name].delete(block) if block.
|
178
|
+
@events[event_name].delete(block) if block.metadata[:once]
|
181
179
|
end
|
182
180
|
block.call(*event_args)
|
183
181
|
@log.debug "Dispatched proc with ID #{block.id.inspect}"
|
@@ -369,10 +367,11 @@ module Discorb
|
|
369
367
|
def extend(mod)
|
370
368
|
if mod.respond_to?(:events)
|
371
369
|
@events.each_value do |event|
|
372
|
-
event.delete_if { |c| c.
|
370
|
+
event.delete_if { |c| c.metadata[:extension] == mod.name }
|
373
371
|
end
|
374
372
|
mod.events.each do |name, events|
|
375
|
-
@events[name]
|
373
|
+
@events[name] ||= []
|
374
|
+
@events[name].delete_if { |c| c.metadata[:override] }
|
376
375
|
events.each do |event|
|
377
376
|
@events[name] << event
|
378
377
|
end
|
@@ -391,7 +390,7 @@ module Discorb
|
|
391
390
|
end
|
392
391
|
|
393
392
|
include Discorb::Gateway::Handler
|
394
|
-
include Discorb::
|
393
|
+
include Discorb::ApplicationCommand::Handler
|
395
394
|
|
396
395
|
#
|
397
396
|
# Starts the client.
|