discorb 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +32 -1
- data/Gemfile.lock +1 -1
- data/docs/application_command.md +251 -0
- data/docs/events.md +8 -8
- data/docs/extension.md +39 -0
- data/examples/commands/bookmarker.rb +41 -0
- data/examples/commands/hello.rb +9 -0
- data/examples/commands/inspect.rb +24 -0
- data/examples/components/authorization_button.rb +1 -1
- data/examples/components/select_menu.rb +1 -1
- data/lib/discorb/asset.rb +34 -0
- data/lib/discorb/client.rb +20 -3
- data/lib/discorb/command.rb +393 -0
- data/lib/discorb/common.rb +5 -5
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +7 -7
- data/lib/discorb/emoji.rb +6 -1
- data/lib/discorb/emoji_table.rb +9 -2
- data/lib/discorb/error.rb +4 -1
- data/lib/discorb/extension.rb +5 -2
- data/lib/discorb/gateway.rb +487 -478
- data/lib/discorb/http.rb +1 -1
- data/lib/discorb/interaction.rb +131 -19
- data/lib/discorb/log.rb +1 -1
- data/lib/discorb/member.rb +10 -1
- data/lib/discorb/user.rb +6 -1
- data/lib/discorb/webhook.rb +12 -1
- data/lib/discorb.rb +7 -7
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6281613f37f7da894dcdcb0df3070fd7c9efa685cf3a0412b6822fd60124cab9
|
4
|
+
data.tar.gz: b584a8ef44f9f18758c18a8a065c003cac6f54beadb8c3c29081cac7c98fa416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 906cc3412b9cb6189947bf3446f3b9129b4665ec4247896f450f4e7bcbab3243764a246956180d5d9dc905ad86132fcadbea0659318d7fd47a30a47a4101f4f0
|
7
|
+
data.tar.gz: 3615cb4feb58e8c5e7c24999a6e6af7596645f3dbebcaafe658c5c0b7c50a9a5aca467160560c316a2a7fa51ab79b6f214da0590d937f0ed2899d9ee79210346
|
data/Changelog.md
CHANGED
@@ -14,4 +14,35 @@
|
|
14
14
|
|
15
15
|
## v0.0.4
|
16
16
|
|
17
|
-
- Fix: Fix NoMethodError by webhook message
|
17
|
+
- Fix: Fix NoMethodError by webhook message
|
18
|
+
- Add: Add `#author` to webhook message
|
19
|
+
- Fix: Add `#bot?` to webhook author
|
20
|
+
|
21
|
+
## v0.0.5
|
22
|
+
|
23
|
+
- Fix: Fix GitHub link
|
24
|
+
- Change: Internet to HTTP
|
25
|
+
|
26
|
+
## v0.0.6
|
27
|
+
|
28
|
+
- Fix: Fix error in client without members intent
|
29
|
+
- Add: Add ThreadChannel::News
|
30
|
+
- Add: Add official discord link
|
31
|
+
|
32
|
+
## v0.0.7
|
33
|
+
|
34
|
+
- Fix: Fix `member_xxx` event
|
35
|
+
|
36
|
+
## 0.0.8
|
37
|
+
|
38
|
+
- Delete: Delete task parameter
|
39
|
+
|
40
|
+
## 0.1.0
|
41
|
+
|
42
|
+
- Add: Add `User#created_at`
|
43
|
+
- Add: Add `Member#to_s_user`
|
44
|
+
- Add: Add `DefaultAvatar`
|
45
|
+
- Add: Suppot application commands
|
46
|
+
- Add: Add `Client#ping`
|
47
|
+
- Add: Allow `String` for `Embed#initialize`
|
48
|
+
- Change: Change log format
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,251 @@
|
|
1
|
+
# @title Application Commands
|
2
|
+
|
3
|
+
# Application Commands
|
4
|
+
|
5
|
+
## What is an application command?
|
6
|
+
|
7
|
+
> Application commands are commands that an application can register to Discord. They provide users a first-class way of interacting directly with your application that feels deeply integrated into Discord.
|
8
|
+
|
9
|
+
From: [Discord API docs](https://discord.com/developers/docs/interactions/application-commands#application-commands)
|
10
|
+
|
11
|
+
## How do I register an application command?
|
12
|
+
|
13
|
+
Use {Discorb::Command::Handler#slash}, {Discorb::Command::Handler#group} for slash commands, {Discorb::Command::Handler#user_command} for user menu commands, and {Discorb::Command::Handler#message_command} for message menu commands.
|
14
|
+
|
15
|
+
### Note
|
16
|
+
|
17
|
+
To register a global command, it will take 1 hour to be registered.
|
18
|
+
Guild commands will be registered immediately.
|
19
|
+
|
20
|
+
### Register Slash Commands
|
21
|
+
|
22
|
+
This example registers a slash command that says "Hello, world!" when the user types `/hello`.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require "discorb"
|
26
|
+
|
27
|
+
client = Discorb::Client.new
|
28
|
+
|
29
|
+
client.slash("hello", "Greet for you") do |interaction|
|
30
|
+
interaction.post("Hello World!", ephemeral: true)
|
31
|
+
end
|
32
|
+
|
33
|
+
client.run(ENV["DISCORD_BOT_TOKEN"])
|
34
|
+
```
|
35
|
+
|
36
|
+
{Discorb::Command::Handler#slash} takes 5 arguments:
|
37
|
+
|
38
|
+
| Argument | Description |
|
39
|
+
|---------|-------------|
|
40
|
+
| `command_name` | The name of the command. |
|
41
|
+
| `description` | The description of the command. |
|
42
|
+
| `options` | A hash of options. |
|
43
|
+
| `guild_ids` | The ID of the guild to register the command in. |
|
44
|
+
| `block` | A block that will be called when the command is invoked. |
|
45
|
+
|
46
|
+
In `options`, hash should be like this:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
{
|
50
|
+
"Name" => {
|
51
|
+
type: :string,
|
52
|
+
required: true,
|
53
|
+
description: "The description of the command."
|
54
|
+
}
|
55
|
+
}
|
56
|
+
```
|
57
|
+
|
58
|
+
| Key | Description |
|
59
|
+
| --- | --- |
|
60
|
+
| `type` | The type of the argument. |
|
61
|
+
| `required` | Whether the argument is required. |
|
62
|
+
| `description` | The description of the argument. |
|
63
|
+
| `choices` | The choices of the argument. |
|
64
|
+
|
65
|
+
`choices` should be unspecified if you don't want to use it.
|
66
|
+
`choices` is hash like this:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
{
|
70
|
+
"vocaloid" => {
|
71
|
+
required: true,
|
72
|
+
description: "The vocaloid which you like."
|
73
|
+
type: :string,
|
74
|
+
choices: {
|
75
|
+
"Hatsune Miku" => "miku",
|
76
|
+
"Kagamine Rin" => "rin",
|
77
|
+
"Kagamine Len" => "len",
|
78
|
+
"Megurine Luka" => "luka",
|
79
|
+
"MEIKO" => "meiko",
|
80
|
+
"KAITO" => "kaito",
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
# Note: This aritcle is written in 8/31.
|
86
|
+
```
|
87
|
+
|
88
|
+
The key will be displayed in the user menu, and the value will be used as the argument.
|
89
|
+
|
90
|
+
In `type`, You must use one of the following:
|
91
|
+
|
92
|
+
| Name | Description | Aliases|
|
93
|
+
| --- | --- | --- |
|
94
|
+
| `:string` | String argument. | `:str` |
|
95
|
+
| `:integer` | Integer argument. | `:int` |
|
96
|
+
| `:float` | Float argument. | None |
|
97
|
+
| `:boolean` | Boolean argument. | `:bool` |
|
98
|
+
| `:user` | User argument. | `:member` |
|
99
|
+
| `:channel` | Channel argument. | None |
|
100
|
+
| `:role` | Role argument. | None |
|
101
|
+
|
102
|
+
### Group Slash Commands
|
103
|
+
|
104
|
+
To register a group of slash commands, use {Discorb::Command::Handler#slash_group}.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
group = client.slash_group("settings", "Set settings of bot.")
|
108
|
+
|
109
|
+
group.slash("message_expand", "Whether bot should expand message.", {
|
110
|
+
"enabled" => {
|
111
|
+
type: :boolean,
|
112
|
+
description: "Whether bot should expand message."
|
113
|
+
}
|
114
|
+
}) do |interaction|
|
115
|
+
# ...
|
116
|
+
end
|
117
|
+
|
118
|
+
group.slash("bump_alert", "Whether bot should notify DISBOARD bump.", {
|
119
|
+
"enabled" => {
|
120
|
+
type: :boolean,
|
121
|
+
description: "Whether bot should notify DISBOARD bump."
|
122
|
+
}
|
123
|
+
}) do |interaction|
|
124
|
+
# ...
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
You can make subcommand group by using {Discorb::Command::GroupCommand#group}.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
group = client.slash_group("permission", "Set/Get command permissions.")
|
132
|
+
|
133
|
+
group_user = group.group("user", "Set/Get user's command permissions.")
|
134
|
+
|
135
|
+
group_user.slash("set", "Set user's command permissions.", {
|
136
|
+
"user_id" => {
|
137
|
+
type: :user,
|
138
|
+
description: "The user."
|
139
|
+
},
|
140
|
+
"value" => {
|
141
|
+
type: :boolean,
|
142
|
+
description: "Whether the user can use the command."
|
143
|
+
}
|
144
|
+
}) do |interaction, user|
|
145
|
+
# ...
|
146
|
+
end
|
147
|
+
|
148
|
+
group_user.slash("get", "Set user's command permissions.", {
|
149
|
+
"user_id" => {
|
150
|
+
type: :user,
|
151
|
+
description: "The user."
|
152
|
+
},
|
153
|
+
}) do |interaction, user|
|
154
|
+
# ...
|
155
|
+
end
|
156
|
+
|
157
|
+
group_user = group.group("user", "Set/Get user's command permissions.")
|
158
|
+
|
159
|
+
group_user.slash("set", "Set user's command permissions.", {
|
160
|
+
"user_id" => {
|
161
|
+
type: :user,
|
162
|
+
description: "The user."
|
163
|
+
},
|
164
|
+
"value" => {
|
165
|
+
type: :boolean,
|
166
|
+
description: "Whether the user can use the command."
|
167
|
+
}
|
168
|
+
}) do |interaction, user|
|
169
|
+
# ...
|
170
|
+
end
|
171
|
+
|
172
|
+
group_user.slash("get", "Set user's command permissions.", {
|
173
|
+
"user_id" => {
|
174
|
+
type: :user,
|
175
|
+
description: "The user."
|
176
|
+
},
|
177
|
+
}) do |interaction, user|
|
178
|
+
# ...
|
179
|
+
end
|
180
|
+
|
181
|
+
group_role = group.group("role", "Set/Get role's command permissions.")
|
182
|
+
|
183
|
+
group_role.slash("set", "Set role's command permissions.", {
|
184
|
+
"role_id" => {
|
185
|
+
type: :role,
|
186
|
+
description: "The role."
|
187
|
+
},
|
188
|
+
"value" => {
|
189
|
+
type: :boolean,
|
190
|
+
description: "Whether the role can use the command."
|
191
|
+
}
|
192
|
+
}) do |interaction, role|
|
193
|
+
# ...
|
194
|
+
end
|
195
|
+
|
196
|
+
group_role.slash("get", "Set role's command permissions.", {
|
197
|
+
"role_id" => {
|
198
|
+
type: :role,
|
199
|
+
description: "The role."
|
200
|
+
},
|
201
|
+
}) do |interaction, role|
|
202
|
+
# ...
|
203
|
+
end
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
### Register User Context Menu Command
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
client.user_command("hello") do |interaction, user|
|
211
|
+
interaction.post("Hello, #{user.name}!")
|
212
|
+
end
|
213
|
+
```
|
214
|
+
{Discorb::Command::Handler#user_command} takes 3 arguments:
|
215
|
+
|
216
|
+
| Parameter | Description |
|
217
|
+
| --- | --- |
|
218
|
+
| `command_name` | The name of the command. |
|
219
|
+
| `guild_ids` | The ID of the guild to register the command in. |
|
220
|
+
| `block` | A block that will be called when the command is invoked. |
|
221
|
+
|
222
|
+
`block` will be called with two arguments:
|
223
|
+
|
224
|
+
| Parameter | Description |
|
225
|
+
| --- | --- |
|
226
|
+
| `interaction` | The interaction object. |
|
227
|
+
| `user` | The user object. |
|
228
|
+
|
229
|
+
|
230
|
+
### Register Message Context Menu Command
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
client.message_command("Bookmark") do |interaction, message|
|
234
|
+
# ...
|
235
|
+
end
|
236
|
+
```
|
237
|
+
|
238
|
+
{Discorb::Command::Handler#message_command} takes 3 arguments:
|
239
|
+
|
240
|
+
| Parameter | Description |
|
241
|
+
| --- | --- |
|
242
|
+
| `command_name` | The name of the command. |
|
243
|
+
| `guild_ids` | The ID of the guild to register the command in. |
|
244
|
+
| `block` | A block that will be called when the command is invoked. |
|
245
|
+
|
246
|
+
`block` will be called with two arguments:
|
247
|
+
|
248
|
+
| Parameter | Description |
|
249
|
+
| --- | --- |
|
250
|
+
| `interaction` | The interaction object. |
|
251
|
+
| `message` | The message object. |
|
data/docs/events.md
CHANGED
@@ -239,7 +239,7 @@ Fires when a message is updated.
|
|
239
239
|
|
240
240
|
| Parameter | Type | Description |
|
241
241
|
| ---------- | ----- | ----------- |
|
242
|
-
|`event` | {Discorb::
|
242
|
+
|`event` | {Discorb::Gateway::MessageUpdateEvent}| The message after the update. |
|
243
243
|
|
244
244
|
#### `message_delete(message, channel, guild)`
|
245
245
|
|
@@ -272,7 +272,7 @@ Fires when a bulk of messages are deleted.
|
|
272
272
|
|
273
273
|
| Parameter | Type | Description |
|
274
274
|
| ---------- | ----- | ----------- |
|
275
|
-
|`messages` | Array<{Discorb::Message}, {Discorb::
|
275
|
+
|`messages` | Array<{Discorb::Message}, {Discorb::Gateway::UnknownDeleteBulkMessage}> | The deleted messages. |
|
276
276
|
|
277
277
|
#### `message_pin_update(event)`
|
278
278
|
|
@@ -280,7 +280,7 @@ Fires when a message is pinned or unpinned.
|
|
280
280
|
|
281
281
|
| Parameter | Type | Description |
|
282
282
|
| ---------- | ----- | ----------- |
|
283
|
-
|`event` | {Discorb::
|
283
|
+
|`event` | {Discorb::Gateway::MessagePinUpdateEvent}| The event object. |
|
284
284
|
|
285
285
|
#### `typing_start(event)`
|
286
286
|
|
@@ -288,7 +288,7 @@ Fires when a user starts typing.
|
|
288
288
|
|
289
289
|
| Parameter | Type | Description |
|
290
290
|
| --------- | ----- | ----------- |
|
291
|
-
|`event` | {Discorb::
|
291
|
+
|`event` | {Discorb::Gateway::TypingStartEvent}| The event object. |
|
292
292
|
|
293
293
|
### Reaction events
|
294
294
|
|
@@ -298,7 +298,7 @@ Fires when a reaction is added to a message.
|
|
298
298
|
|
299
299
|
| Parameter | Type | Description |
|
300
300
|
| ---------- | ----- | ----------- |
|
301
|
-
|`event` | {Discorb::
|
301
|
+
|`event` | {Discorb::Gateway::ReactionEvent}| The event object. |
|
302
302
|
|
303
303
|
#### `reaction_remove(event)`
|
304
304
|
|
@@ -306,7 +306,7 @@ Fires when someone removes a reaction from a message.
|
|
306
306
|
|
307
307
|
| Parameter | Type | Description |
|
308
308
|
| ---------- | ----- | ----------- |
|
309
|
-
|`event` | {Discorb::
|
309
|
+
|`event` | {Discorb::Gateway::ReactionEvent}| The event object. |
|
310
310
|
|
311
311
|
#### `reaction_remove_all(event)`
|
312
312
|
|
@@ -314,7 +314,7 @@ Fires when all reactions are removed from a message.
|
|
314
314
|
|
315
315
|
| Parameter | Type | Description |
|
316
316
|
| ---------- | ----- | ----------- |
|
317
|
-
|`event` | {Discorb::
|
317
|
+
|`event` | {Discorb::Gateway::ReactionRemoveAllEvent}| The event object. |
|
318
318
|
|
319
319
|
#### `reaction_remove_emoji(event)`
|
320
320
|
|
@@ -322,7 +322,7 @@ Fires when a reaction is removed from a message.
|
|
322
322
|
|
323
323
|
| Parameter | Type | Description |
|
324
324
|
| ---------- | ----- | ----------- |
|
325
|
-
|`event` | {Discorb::
|
325
|
+
|`event` | {Discorb::Gateway::ReactionRemoveEmojiEvent}| The event object. |
|
326
326
|
|
327
327
|
### Role events
|
328
328
|
|
data/docs/extension.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# @title Extension
|
2
|
+
|
3
|
+
# Extension
|
4
|
+
|
5
|
+
Extension allows you to split your code into multiple files.
|
6
|
+
|
7
|
+
## Make a new extension
|
8
|
+
|
9
|
+
Make a new module, and extend {Discorb::Extension}.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
module MyExtension
|
13
|
+
extend Discorb::Extension
|
14
|
+
|
15
|
+
# ...
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
## Register Event
|
20
|
+
|
21
|
+
Use {Extension#event} to register event, or {Extension#once_event} to register event only once.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
module MyExtension
|
25
|
+
extend Discorb::Extension
|
26
|
+
|
27
|
+
event :message do |message|
|
28
|
+
# ...
|
29
|
+
end
|
30
|
+
|
31
|
+
once_event :ready do |message|
|
32
|
+
# ...
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Load extension
|
38
|
+
|
39
|
+
Use {Client#extend} to load extension.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "discorb"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
client = Discorb::Client.new
|
5
|
+
|
6
|
+
client.once :ready do
|
7
|
+
puts "Logged in as #{client.user}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def bookmark_channel(guild)
|
11
|
+
guild.channels.find { |c| c.is_a?(Discorb::TextChannel) && c.name == "bookmarks" }
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_embed_from_message(message)
|
15
|
+
embed = Discorb::Embed.new
|
16
|
+
embed.description = message.content
|
17
|
+
embed.author = Discorb::Embed::Author.new(message.author.to_s_user, icon: message.author.avatar.url)
|
18
|
+
embed.timestamp = message.timestamp
|
19
|
+
embed.footer = Discorb::Embed::Footer.new("Message ID: #{message.id}")
|
20
|
+
embed
|
21
|
+
end
|
22
|
+
|
23
|
+
client.message_command("Bookmark", guild_ids: [857373681096327180]) do |interaction, message|
|
24
|
+
unless channel = bookmark_channel(interaction.guild)
|
25
|
+
interaction.post("Bookmark channel not found. Please create one called `bookmarks`.", ephemeral: true)
|
26
|
+
next
|
27
|
+
end
|
28
|
+
channel.post(
|
29
|
+
message.jump_url,
|
30
|
+
embed: build_embed_from_message(message),
|
31
|
+
).wait
|
32
|
+
interaction.post("Bookmarked!", ephemeral: true)
|
33
|
+
end
|
34
|
+
|
35
|
+
client.change_presence(
|
36
|
+
Discorb::Activity.new(
|
37
|
+
"Open message context menu to bookmark"
|
38
|
+
)
|
39
|
+
)
|
40
|
+
|
41
|
+
client.run(ENV["DISCORD_BOT_TOKEN"])
|