discorb 0.16.0 → 0.17.0
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/.gitattributes +1 -0
- data/.github/workflows/build_main.yml +2 -2
- data/.github/workflows/build_version.yml +1 -1
- data/.github/workflows/codeql-analysis.yml +1 -1
- data/.github/workflows/lint-push.yml +3 -5
- data/.github/workflows/lint.yml +1 -1
- data/.github/workflows/spec.yml +30 -0
- data/.lefthook/commit-msg/validator.rb +5 -0
- data/.rspec +2 -0
- data/.rspec_parallel +2 -0
- data/.rubocop.yml +43 -6
- data/Changelog.md +14 -1
- data/Gemfile +14 -8
- data/Rakefile +41 -26
- data/bin/console +3 -3
- data/docs/Examples.md +1 -1
- data/docs/application_command.md +138 -46
- data/docs/cli/irb.md +2 -2
- data/docs/cli/new.md +14 -9
- data/docs/cli/run.md +7 -11
- data/docs/cli.md +17 -10
- data/docs/events.md +209 -211
- data/docs/extension.md +1 -2
- data/docs/faq.md +0 -1
- data/docs/tutorial.md +12 -12
- data/docs/voice_events.md +106 -106
- data/examples/commands/message.rb +63 -0
- data/examples/commands/permission.rb +18 -0
- data/examples/commands/slash.rb +44 -0
- data/examples/commands/user.rb +51 -0
- data/examples/components/authorization_button.rb +2 -2
- data/examples/components/select_menu.rb +2 -2
- data/examples/extension/main.rb +1 -1
- data/examples/extension/message_expander.rb +5 -2
- data/examples/simple/eval.rb +2 -2
- data/examples/simple/ping_pong.rb +1 -1
- data/examples/simple/rolepanel.rb +1 -1
- data/examples/simple/shard.rb +1 -1
- data/examples/simple/wait_for_message.rb +1 -1
- data/exe/discorb +31 -16
- data/lefthook.yml +45 -0
- data/lib/discorb/allowed_mentions.rb +1 -0
- data/lib/discorb/app_command/command.rb +127 -65
- data/lib/discorb/app_command/common.rb +25 -0
- data/lib/discorb/app_command/handler.rb +115 -33
- data/lib/discorb/app_command.rb +2 -1
- data/lib/discorb/application.rb +1 -0
- data/lib/discorb/asset.rb +1 -2
- data/lib/discorb/attachment.rb +1 -1
- data/lib/discorb/audit_logs.rb +11 -8
- data/lib/discorb/channel/base.rb +108 -0
- data/lib/discorb/channel/category.rb +32 -0
- data/lib/discorb/channel/container.rb +44 -0
- data/lib/discorb/channel/dm.rb +28 -0
- data/lib/discorb/channel/guild.rb +245 -0
- data/lib/discorb/channel/stage.rb +140 -0
- data/lib/discorb/channel/text.rb +345 -0
- data/lib/discorb/channel/thread.rb +321 -0
- data/lib/discorb/channel/voice.rb +79 -0
- data/lib/discorb/channel.rb +2 -1165
- data/lib/discorb/client.rb +38 -26
- data/lib/discorb/common.rb +2 -1
- data/lib/discorb/components/button.rb +2 -1
- data/lib/discorb/components/select_menu.rb +4 -2
- data/lib/discorb/components/text_input.rb +12 -2
- data/lib/discorb/components.rb +1 -1
- data/lib/discorb/embed.rb +22 -7
- data/lib/discorb/emoji.rb +30 -3
- data/lib/discorb/emoji_table.rb +4969 -3
- data/lib/discorb/event.rb +29 -4
- data/lib/discorb/exe/about.rb +1 -0
- data/lib/discorb/exe/irb.rb +2 -4
- data/lib/discorb/exe/new.rb +90 -23
- data/lib/discorb/exe/run.rb +8 -22
- data/lib/discorb/exe/setup.rb +25 -12
- data/lib/discorb/exe/show.rb +4 -3
- data/lib/discorb/extend.rb +1 -0
- data/lib/discorb/extension.rb +6 -3
- data/lib/discorb/flag.rb +11 -0
- data/lib/discorb/gateway.rb +67 -19
- data/lib/discorb/guild.rb +188 -56
- data/lib/discorb/guild_template.rb +10 -4
- data/lib/discorb/http.rb +16 -9
- data/lib/discorb/integration.rb +4 -1
- data/lib/discorb/intents.rb +1 -1
- data/lib/discorb/interaction/autocomplete.rb +28 -16
- data/lib/discorb/interaction/command.rb +36 -12
- data/lib/discorb/interaction/components.rb +5 -2
- data/lib/discorb/interaction/modal.rb +0 -1
- data/lib/discorb/interaction/response.rb +61 -22
- data/lib/discorb/interaction/root.rb +13 -13
- data/lib/discorb/interaction.rb +1 -0
- data/lib/discorb/invite.rb +5 -2
- data/lib/discorb/member.rb +25 -5
- data/lib/discorb/message.rb +47 -14
- data/lib/discorb/message_meta.rb +1 -0
- data/lib/discorb/modules.rb +56 -14
- data/lib/discorb/presence.rb +2 -2
- data/lib/discorb/rate_limit.rb +7 -2
- data/lib/discorb/reaction.rb +4 -4
- data/lib/discorb/role.rb +19 -4
- data/lib/discorb/shard.rb +1 -1
- data/lib/discorb/sticker.rb +8 -7
- data/lib/discorb/user.rb +2 -1
- data/lib/discorb/utils/colored_puts.rb +1 -0
- data/lib/discorb/voice_state.rb +10 -6
- data/lib/discorb/webhook.rb +36 -24
- data/lib/discorb.rb +5 -3
- data/po/yard.pot +9 -9
- data/sig/discorb.rbs +7232 -7235
- metadata +21 -5
- data/examples/commands/bookmarker.rb +0 -42
- data/examples/commands/hello.rb +0 -10
- data/examples/commands/inspect.rb +0 -25
data/docs/application_command.md
CHANGED
|
@@ -13,12 +13,13 @@ From: [Discord API docs](https://discord.com/developers/docs/interactions/applic
|
|
|
13
13
|
## How do I register an application command?
|
|
14
14
|
|
|
15
15
|
Write to your script:
|
|
16
|
+
|
|
16
17
|
- {Discorb::ApplicationCommand::Handler.slash}, {Discorb::ApplicationCommand::Handler.slash_group} for slash commands,
|
|
17
18
|
- {Discorb::ApplicationCommand::Handler.user_command} for user menu commands,
|
|
18
19
|
- {Discorb::ApplicationCommand::Handler.message_command} for message menu commands.
|
|
19
20
|
|
|
20
21
|
And then run `discorb setup` to register your application commands.
|
|
21
|
-
{file:docs/cli/setup.md Learn more about `discorb setup`}.
|
|
22
|
+
{file:docs/cli/setup.md Learn more about `discorb setup`}.
|
|
22
23
|
|
|
23
24
|
### Note
|
|
24
25
|
|
|
@@ -43,13 +44,13 @@ client.run(ENV["DISCORD_BOT_TOKEN"])
|
|
|
43
44
|
|
|
44
45
|
{Discorb::ApplicationCommand::Handler#slash} takes 5 arguments:
|
|
45
46
|
|
|
46
|
-
| Argument
|
|
47
|
-
|
|
48
|
-
| `command_name` | The name of the command.
|
|
49
|
-
| `description`
|
|
50
|
-
| `options`
|
|
51
|
-
| `guild_ids`
|
|
52
|
-
| `block`
|
|
47
|
+
| Argument | Description |
|
|
48
|
+
| -------------- | -------------------------------------------------------- |
|
|
49
|
+
| `command_name` | The name of the command. |
|
|
50
|
+
| `description` | The description of the command. |
|
|
51
|
+
| `options` | A hash of options. |
|
|
52
|
+
| `guild_ids` | The ID of the guild to register the command in. |
|
|
53
|
+
| `block` | A block that will be called when the command is invoked. |
|
|
53
54
|
|
|
54
55
|
Block will be called with a {Discorb::Interaction} object and specified options.
|
|
55
56
|
|
|
@@ -64,20 +65,22 @@ In `options`, hash should be like this:
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
```
|
|
67
|
-
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
| `:
|
|
71
|
-
| `:
|
|
72
|
-
| `:
|
|
73
|
-
| `:
|
|
74
|
-
| `:
|
|
75
|
-
| `:
|
|
76
|
-
| `:
|
|
77
|
-
| `:
|
|
68
|
+
|
|
69
|
+
| Key | Type | Description |
|
|
70
|
+
| ------------------------ | ---------------------------------------- | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
71
|
+
| `:description` | `String` | Description of the option. |
|
|
72
|
+
| `:required` | Boolean(true | false) | Whether the argument is required. `optional` will be used if not specified. |
|
|
73
|
+
| `:optional` | Boolean(true | false) | Whether the argument is optional. `required` will be used if not specified. |
|
|
74
|
+
| `:type` | `Object` | Type of the option. |
|
|
75
|
+
| `:choices` | `Hash{String => String, Integer, Float}` | Choice of the option. |
|
|
76
|
+
| `:choices_localizations` | `Hash{String => Hash{Symbol => String}}` | Localization of the choice. Key must be the name of a choice. (See below for example) |
|
|
77
|
+
| `:default` | `Object` | Default value of the option. |
|
|
78
|
+
| `:channel_types` | `Array<Class<Discorb::Channel>>` | Type of the channel option. |
|
|
79
|
+
| `:autocomplete` | `Proc` | Autocomplete function. |
|
|
80
|
+
| `:range` | `Range` | Range of the option. Only valid for numeric options. (`:int`, `:float`) |
|
|
78
81
|
|
|
79
82
|
`choices` should be unspecified if you don't want to use it.
|
|
80
|
-
`choices`
|
|
83
|
+
`choices` example:
|
|
81
84
|
|
|
82
85
|
```ruby
|
|
83
86
|
{
|
|
@@ -103,15 +106,15 @@ The key will be displayed in the user menu, and the value will be used as the ar
|
|
|
103
106
|
|
|
104
107
|
In `type`, You must use one of the following:
|
|
105
108
|
|
|
106
|
-
| Name
|
|
107
|
-
|
|
|
108
|
-
| `:string`
|
|
109
|
-
| `:integer` | Integer argument. | `:int`
|
|
110
|
-
| `:float`
|
|
111
|
-
| `:boolean` | Boolean argument. | `:bool`
|
|
112
|
-
| `:user`
|
|
113
|
-
| `:channel` | Channel argument. | None
|
|
114
|
-
| `:role`
|
|
109
|
+
| Name | Description | Aliases |
|
|
110
|
+
| ---------- | ----------------- | --------- |
|
|
111
|
+
| `:string` | String argument. | `:str` |
|
|
112
|
+
| `:integer` | Integer argument. | `:int` |
|
|
113
|
+
| `:float` | Float argument. | None |
|
|
114
|
+
| `:boolean` | Boolean argument. | `:bool` |
|
|
115
|
+
| `:user` | User argument. | `:member` |
|
|
116
|
+
| `:channel` | Channel argument. | None |
|
|
117
|
+
| `:role` | Role argument. | None |
|
|
115
118
|
|
|
116
119
|
#### Group Slash Commands
|
|
117
120
|
|
|
@@ -277,21 +280,21 @@ client.user_command("hello") do |interaction, user|
|
|
|
277
280
|
interaction.post("Hello, #{user.name}!")
|
|
278
281
|
end
|
|
279
282
|
```
|
|
283
|
+
|
|
280
284
|
{Discorb::ApplicationCommand::Handler.user_command} takes 3 arguments:
|
|
281
285
|
|
|
282
|
-
| Parameter
|
|
283
|
-
|
|
|
284
|
-
| `command_name` | The name of the command.
|
|
285
|
-
| `guild_ids`
|
|
286
|
-
| `block`
|
|
286
|
+
| Parameter | Description |
|
|
287
|
+
| -------------- | -------------------------------------------------------- |
|
|
288
|
+
| `command_name` | The name of the command. |
|
|
289
|
+
| `guild_ids` | The ID of the guild to register the command in. |
|
|
290
|
+
| `block` | A block that will be called when the command is invoked. |
|
|
287
291
|
|
|
288
292
|
`block` will be called with two arguments:
|
|
289
293
|
|
|
290
|
-
| Parameter
|
|
291
|
-
|
|
|
294
|
+
| Parameter | Description |
|
|
295
|
+
| ------------- | ----------------------- |
|
|
292
296
|
| `interaction` | The interaction object. |
|
|
293
|
-
| `user`
|
|
294
|
-
|
|
297
|
+
| `user` | The user object. |
|
|
295
298
|
|
|
296
299
|
### Register Message Context Menu Command
|
|
297
300
|
|
|
@@ -303,15 +306,104 @@ end
|
|
|
303
306
|
|
|
304
307
|
{Discorb::ApplicationCommand::Handler.message_command} takes 3 arguments:
|
|
305
308
|
|
|
306
|
-
| Parameter
|
|
307
|
-
|
|
|
308
|
-
| `command_name` | The name of the command.
|
|
309
|
-
| `guild_ids`
|
|
310
|
-
| `block`
|
|
309
|
+
| Parameter | Description |
|
|
310
|
+
| -------------- | -------------------------------------------------------- |
|
|
311
|
+
| `command_name` | The name of the command. |
|
|
312
|
+
| `guild_ids` | The ID of the guild to register the command in. |
|
|
313
|
+
| `block` | A block that will be called when the command is invoked. |
|
|
311
314
|
|
|
312
315
|
`block` will be called with two arguments:
|
|
313
316
|
|
|
314
|
-
| Parameter
|
|
315
|
-
|
|
|
317
|
+
| Parameter | Description |
|
|
318
|
+
| ------------- | ----------------------- |
|
|
316
319
|
| `interaction` | The interaction object. |
|
|
317
|
-
| `message`
|
|
320
|
+
| `message` | The message object. |
|
|
321
|
+
|
|
322
|
+
### Localizing command
|
|
323
|
+
|
|
324
|
+
You can localize commands with passing parameters, or setting Hash to name.
|
|
325
|
+
Also, you can change the text by checking `interaction.locale` and `interaction.guild_locale`.
|
|
326
|
+
|
|
327
|
+
Command name localize example:
|
|
328
|
+
|
|
329
|
+
```ruby
|
|
330
|
+
localizations = {
|
|
331
|
+
localized: {
|
|
332
|
+
text: {
|
|
333
|
+
en: "Hello, %s!",
|
|
334
|
+
ja: "%sさん、こんにちは!",
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
client.slash({
|
|
340
|
+
default: "greet",
|
|
341
|
+
ja: "挨拶",
|
|
342
|
+
}, {
|
|
343
|
+
default: "Bot greets. Cute OwO",
|
|
344
|
+
ja: "Botが挨拶します。かわいいね",
|
|
345
|
+
}, {
|
|
346
|
+
"name" => {
|
|
347
|
+
name_localizations: {
|
|
348
|
+
ja: "名前",
|
|
349
|
+
},
|
|
350
|
+
description: {
|
|
351
|
+
default: "The name to greet.",
|
|
352
|
+
ja: "挨拶する人の名前。",
|
|
353
|
+
},
|
|
354
|
+
type: :string,
|
|
355
|
+
optional: true,
|
|
356
|
+
},
|
|
357
|
+
}) do |interaction, name|
|
|
358
|
+
interaction.post(
|
|
359
|
+
(localizations[:localized][:text][interaction.locale] || localizations[:localized][:text][:en]) % [name || interaction.target.to_s_user],
|
|
360
|
+
ephemeral: true,
|
|
361
|
+
)
|
|
362
|
+
end
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Option localize example:
|
|
366
|
+
|
|
367
|
+
```ruby
|
|
368
|
+
{
|
|
369
|
+
"vocaloid" => {
|
|
370
|
+
name_localizations: {
|
|
371
|
+
ja: "ボカロ",
|
|
372
|
+
},
|
|
373
|
+
required: true,
|
|
374
|
+
description: "The vocaloid which you like.",
|
|
375
|
+
description_localizations: {
|
|
376
|
+
ja: "好きなボカロ。",
|
|
377
|
+
},
|
|
378
|
+
type: :string,
|
|
379
|
+
choices: {
|
|
380
|
+
"Hatsune Miku" => "miku",
|
|
381
|
+
"Kagamine Rin" => "rin",
|
|
382
|
+
"Kagamine Len" => "len",
|
|
383
|
+
"Megurine Luka" => "luka",
|
|
384
|
+
"MEIKO" => "meiko",
|
|
385
|
+
"KAITO" => "kaito",
|
|
386
|
+
},
|
|
387
|
+
choice_localizations: {
|
|
388
|
+
"Hatsune Miku" => {
|
|
389
|
+
ja: "初音ミク",
|
|
390
|
+
},
|
|
391
|
+
"Kagamine Rin" => {
|
|
392
|
+
ja: "鏡音リン",
|
|
393
|
+
},
|
|
394
|
+
"Kagamine Len" => {
|
|
395
|
+
ja: "鏡音レン",
|
|
396
|
+
},
|
|
397
|
+
"Megurine Luka" => {
|
|
398
|
+
ja: "巡音ルカ",
|
|
399
|
+
},
|
|
400
|
+
"MEIKO" => {
|
|
401
|
+
ja: "MEIKO",
|
|
402
|
+
},
|
|
403
|
+
"KAITO" => {
|
|
404
|
+
ja: "KAITO",
|
|
405
|
+
},
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
```
|
data/docs/cli/irb.md
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
This command will start an interactive Ruby shell with connected client.
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
## Usage
|
|
11
10
|
|
|
12
11
|
```
|
|
@@ -16,6 +15,7 @@ discorb irb [options]
|
|
|
16
15
|
### Load a token
|
|
17
16
|
|
|
18
17
|
discorb irb will load a token from...
|
|
18
|
+
|
|
19
19
|
1. the `DISCORD_BOT_TOKEN` environment variable
|
|
20
20
|
2. the `DISCORD_TOKEN` environment variable
|
|
21
21
|
3. `token` file in the current directory(customizable with `-t` option)
|
|
@@ -36,4 +36,4 @@ Token file to load.
|
|
|
36
36
|
|
|
37
37
|
#### `message`
|
|
38
38
|
|
|
39
|
-
Last message received.
|
|
39
|
+
Last message received.
|
data/docs/cli/new.md
CHANGED
|
@@ -56,16 +56,21 @@ Default to TOKEN.
|
|
|
56
56
|
Whether to overwrite an existing directory.
|
|
57
57
|
Default to false.
|
|
58
58
|
|
|
59
|
+
### `--[no-]comment`
|
|
60
|
+
|
|
61
|
+
Whether to write comment in main.rb.
|
|
62
|
+
Default to true.
|
|
63
|
+
|
|
59
64
|
## File structure
|
|
60
65
|
|
|
61
66
|
The following files will be created:
|
|
62
67
|
|
|
63
|
-
| File
|
|
64
|
-
|
|
|
65
|
-
| `.env`
|
|
66
|
-
| `main.rb`
|
|
67
|
-
| `.gitignore`
|
|
68
|
-
| `Gemfile`
|
|
69
|
-
| `Gemfile.lock` | Gemfile lock file. Won't be created if `--bundle` is false.
|
|
70
|
-
| `README.md`
|
|
71
|
-
| `.env.sample`
|
|
68
|
+
| File | Description |
|
|
69
|
+
| -------------- | -------------------------------------------------------------------- |
|
|
70
|
+
| `.env` | Environment variables. |
|
|
71
|
+
| `main.rb` | Main script. |
|
|
72
|
+
| `.gitignore` | Git ignore file. Won't be created if `--git` is false. |
|
|
73
|
+
| `Gemfile` | Gemfile. Won't be created if `--bundle` is false. |
|
|
74
|
+
| `Gemfile.lock` | Gemfile lock file. Won't be created if `--bundle` is false. |
|
|
75
|
+
| `README.md` | Readme file. Won't be created if `--desc` is false. |
|
|
76
|
+
| `.env.sample` | Sample environment variables. Won't be created if `--desc` is false. |
|
data/docs/cli/run.md
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
This command will run a client.
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
## Usage
|
|
11
10
|
|
|
12
11
|
```
|
|
@@ -31,12 +30,12 @@ The title of the process.
|
|
|
31
30
|
Specify the log level.
|
|
32
31
|
Should be one of the following:
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
- `none`
|
|
34
|
+
- `debug`
|
|
35
|
+
- `info`
|
|
36
|
+
- `warn`
|
|
37
|
+
- `error`
|
|
38
|
+
- `fatal`
|
|
40
39
|
|
|
41
40
|
#### `-f`, `--log-file`
|
|
42
41
|
|
|
@@ -47,6 +46,7 @@ You can use `stdout` to write to the standard output, and `stderr` to write to t
|
|
|
47
46
|
|
|
48
47
|
Whether to colorize the log output.
|
|
49
48
|
If not specified, the default will be:
|
|
49
|
+
|
|
50
50
|
- `true` if the file to write logs to is `stdout` or `stderr`.
|
|
51
51
|
- `false` otherwise.
|
|
52
52
|
|
|
@@ -57,7 +57,3 @@ Whether to set up application commands.
|
|
|
57
57
|
#### `-e`, `--env`
|
|
58
58
|
|
|
59
59
|
The name of the environment variable to use for token, or just `-t` or `--token` for intractive prompt.
|
|
60
|
-
|
|
61
|
-
#### `-b`, `--bundler`
|
|
62
|
-
|
|
63
|
-
Whether to use bundler to load the script.
|
data/docs/cli.md
CHANGED
|
@@ -9,20 +9,27 @@ discorb has a CLI tool for developing.
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
|
|
12
|
+
Usage: discorb [options] [subcommand [options]]
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## Options
|
|
16
|
+
|
|
17
|
+
### `-b`, `--[no-]bundler`
|
|
18
|
+
|
|
19
|
+
Whether to use bundler.
|
|
20
|
+
Default to true.
|
|
21
|
+
|
|
15
22
|
## Commands
|
|
16
23
|
|
|
17
24
|
Currently, discorb has the following commands:
|
|
18
25
|
|
|
19
|
-
| Command
|
|
20
|
-
|
|
21
|
-
| {file:docs/cli/new.md `new`}
|
|
22
|
-
| {file:docs/cli/irb.md `irb`}
|
|
23
|
-
| {file:docs/cli/run.md `run`}
|
|
24
|
-
| {file:docs/cli/setup.md `setup`} | Setup application commands.
|
|
25
|
-
| `show`
|
|
26
|
-
| `about`
|
|
26
|
+
| Command | Description |
|
|
27
|
+
| -------------------------------- | ------------------------------------------------------ |
|
|
28
|
+
| {file:docs/cli/new.md `new`} | Create a new project. |
|
|
29
|
+
| {file:docs/cli/irb.md `irb`} | Start an interactive Ruby shell with connected client. |
|
|
30
|
+
| {file:docs/cli/run.md `run`} | Run a client. |
|
|
31
|
+
| {file:docs/cli/setup.md `setup`} | Setup application commands. |
|
|
32
|
+
| `show` | Show your environment. (No document) |
|
|
33
|
+
| `about` | Show discorb's information. (No document) |
|
|
27
34
|
|
|
28
|
-
Click the command name to see the document.
|
|
35
|
+
Click the command name to see the document.
|