discorb 0.9.4 → 0.9.5
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/Changelog.md +6 -0
- data/README.md +5 -5
- data/Rakefile +3 -0
- data/docs/application_command.md +8 -7
- data/docs/license.md +1 -1
- data/lib/discorb/app_command.rb +4 -2
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/extend.rb +21 -0
- data/lib/discorb/file.rb +18 -0
- data/lib/discorb/interaction.rb +19 -17
- data/lib/discorb/message.rb +4 -4
- data/lib/discorb/modules.rb +1 -1
- data/lib/discorb/utils.rb +0 -20
- data/template-replace/files/css/common.css +2 -2
- data/template-replace/scripts/arrow.rb +7 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39902a57677adf3ce903678e58060ee04da318617ba81611546772131c9d1696
|
4
|
+
data.tar.gz: 6f0f17d2230a19b79f6330cda2d567f704f8ffe44ca59e8938cc0ec0f32dfb35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 453b9228e5afca3d9b206b54aa3f34f97b3a4c6d6ade46034fe3d0fd8620c1069d0288fa672bc20cdcce2816405f925d92a9fcf6012bc73d5a09fdb4bc7c0335
|
7
|
+
data.tar.gz: 11920dcfc13754975686abe69504af19f81331fa684fd5d51aa1065ff426300dfa90ef373c626a84f1c3533e511dd0f35641126f020c1838bc7262538d6fa505
|
data/Changelog.md
CHANGED
@@ -252,3 +252,9 @@ end
|
|
252
252
|
- Fix: Fix some issues in document
|
253
253
|
- Add: Add some attributes to `Message`
|
254
254
|
- Fix: Fix guild parameter in message of message command
|
255
|
+
|
256
|
+
## 0.9.5
|
257
|
+
|
258
|
+
- Fix: Fix editing message
|
259
|
+
- Add: Add `required` in slash command argument
|
260
|
+
- Add: Add `default` in slash command argument
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
<div align="center"><img src="./assets/banner.svg" alt="discorb"></div>
|
2
2
|
|
3
|
-
<div align="center"><a href="https://discorb-lib.github.io/"><img src="https://img.shields.io/badge/Document-discorb--lib.github.io-blue.svg?style=flat-square" alt="Document"></a>
|
4
|
-
<a href="https://rubygems.org/gems/discorb"><img src="https://img.shields.io/gem/dt/discorb?logo=rubygems&logoColor=fff&label=Downloads&style=flat-square" alt="Gem"></a>
|
5
|
-
<a href="https://rubygems.org/gems/discorb"><img src="https://img.shields.io/gem/v/discorb?logo=rubygems&logoColor=fff&label=Version&style=flat-square" alt="Gem"></a>
|
6
|
-
<a href="https://discord.gg/hCP6zq8Vpj"><img src="https://img.shields.io/discord/863581274916913193?logo=discord&logoColor=fff&color=5865f2&label=Discord&style=flat-square" alt="Discord"></a>
|
7
|
-
<a href="https://github.com/discorb-lib/discorb"><img src="https://img.shields.io/github/stars/discorb-lib/discorb?color=24292e&label=Stars&logo=GitHub&logoColor=fff&style=flat-square" alt="GitHub"></a></div>
|
3
|
+
<div align="center"><a href="https://discorb-lib.github.io/"><img src="https://img.shields.io/badge/Document-discorb--lib.github.io-blue.svg?style=flat-square&labelColor=2f3136" alt="Document"></a>
|
4
|
+
<a href="https://rubygems.org/gems/discorb"><img src="https://img.shields.io/gem/dt/discorb?logo=rubygems&logoColor=fff&label=Downloads&style=flat-square&labelColor=2f3136" alt="Gem"></a>
|
5
|
+
<a href="https://rubygems.org/gems/discorb"><img src="https://img.shields.io/gem/v/discorb?logo=rubygems&logoColor=fff&label=Version&style=flat-square&labelColor=2f3136" alt="Gem"></a>
|
6
|
+
<a href="https://discord.gg/hCP6zq8Vpj"><img src="https://img.shields.io/discord/863581274916913193?logo=discord&logoColor=fff&color=5865f2&label=Discord&style=flat-square&labelColor=2f3136" alt="Discord"></a>
|
7
|
+
<a href="https://github.com/discorb-lib/discorb"><img src="https://img.shields.io/github/stars/discorb-lib/discorb?color=24292e&label=Stars&logo=GitHub&logoColor=fff&style=flat-square&labelColor=2f3136" alt="GitHub"></a></div>
|
8
8
|
|
9
9
|
----
|
10
10
|
|
data/Rakefile
CHANGED
@@ -91,6 +91,7 @@ namespace :document do
|
|
91
91
|
require_relative "template-replace/scripts/index.rb"
|
92
92
|
require_relative "template-replace/scripts/yard_replace.rb"
|
93
93
|
require_relative "template-replace/scripts/favicon.rb"
|
94
|
+
require_relative "template-replace/scripts/arrow.rb"
|
94
95
|
iputs "Resetting changes"
|
95
96
|
Dir.glob("doc/#{version}/**/*.html") do |f|
|
96
97
|
next if (m = f.match(/[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)?/)) && m[0] != version
|
@@ -112,6 +113,8 @@ namespace :document do
|
|
112
113
|
yard_replace("doc/#{version}", version)
|
113
114
|
iputs "Adding favicon"
|
114
115
|
add_favicon("doc/#{version}")
|
116
|
+
iputs "Replacing arrow"
|
117
|
+
replace_arrow("doc/#{version}")
|
115
118
|
iputs "Successfully replaced htmls"
|
116
119
|
end
|
117
120
|
|
data/docs/application_command.md
CHANGED
@@ -60,13 +60,14 @@ In `options`, hash should be like this:
|
|
60
60
|
}
|
61
61
|
}
|
62
62
|
```
|
63
|
-
|
64
|
-
|
|
65
|
-
|
|
66
|
-
| `
|
67
|
-
| `
|
68
|
-
| `
|
69
|
-
| `
|
63
|
+
| Key | Type | Description |
|
64
|
+
| --- | --- | --- |
|
65
|
+
| `:description` | `String` | Description of the option. |
|
66
|
+
| `:required` | Whether the argument is required. `optional` will be used if not specified. |
|
67
|
+
| `:optional` | Whether the argument is optional. `required` will be used if not specified. |
|
68
|
+
| `:type` | `Object` | Type of the option. |
|
69
|
+
| `:choice` | `Hash{String => String, Integer, Float}` | Type of the option. |
|
70
|
+
| `:default` | `Object` | Default value of the option. |
|
70
71
|
|
71
72
|
`choices` should be unspecified if you don't want to use it.
|
72
73
|
`choices` is hash like this:
|
data/docs/license.md
CHANGED
data/lib/discorb/app_command.rb
CHANGED
@@ -20,9 +20,11 @@ module Discorb
|
|
20
20
|
# | Key | Type | Description |
|
21
21
|
# | --- | --- | --- |
|
22
22
|
# | `:description` | `String` | Description of the option. |
|
23
|
-
# | `:
|
23
|
+
# | `:required` | Whether the argument is required. `optional` will be used if not specified. |
|
24
|
+
# | `:optional` | Whether the argument is optional. `required` will be used if not specified. |
|
24
25
|
# | `:type` | `Object` | Type of the option. |
|
25
26
|
# | `:choice` | `Hash{String => String, Integer, Float}` | Type of the option. |
|
27
|
+
# | `:default` | `Object` | Default value of the option. |
|
26
28
|
#
|
27
29
|
# @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
28
30
|
# @param [Proc] block Command block.
|
@@ -231,7 +233,7 @@ module Discorb
|
|
231
233
|
end,
|
232
234
|
name: name,
|
233
235
|
description: value[:description],
|
234
|
-
required: !value[:optional],
|
236
|
+
required: value[:required].nil? ? !value[:optional] : value[:required],
|
235
237
|
}
|
236
238
|
if value[:choices]
|
237
239
|
ret[:choices] = value[:choices].map { |t| { name: t[0], value: t[1] } }
|
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.9.
|
7
|
+
VERSION = "0.9.5"
|
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/extend.rb
CHANGED
@@ -16,3 +16,24 @@ class Time
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
# @private
|
21
|
+
class Async::Node
|
22
|
+
def description
|
23
|
+
@object_name ||= "#{self.class}:0x#{object_id.to_s(16)}#{@transient ? " transient" : nil}"
|
24
|
+
|
25
|
+
if @annotation
|
26
|
+
"#{@object_name} #{@annotation}"
|
27
|
+
elsif line = self.backtrace(0, 1)&.first
|
28
|
+
"#{@object_name} #{line}"
|
29
|
+
else
|
30
|
+
@object_name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
"\#<#{self.description}>"
|
36
|
+
end
|
37
|
+
|
38
|
+
alias inspect to_s
|
39
|
+
end
|
data/lib/discorb/file.rb
CHANGED
@@ -60,6 +60,14 @@ module Discorb
|
|
60
60
|
# @return [String] The content type of the file. If not set, it is guessed from the filename.
|
61
61
|
attr_accessor :content_type
|
62
62
|
|
63
|
+
#
|
64
|
+
# Creates a new file from IO.
|
65
|
+
#
|
66
|
+
# @param [#read] io The IO of the file.
|
67
|
+
# @param [String] filename The filename of the file. If not set, path or object_id of the IO is used.
|
68
|
+
# @param [String] content_type The content type of the file. If not set, it is guessed from the filename.
|
69
|
+
# If failed to guess, it is set to `application/octet-stream`.
|
70
|
+
#
|
63
71
|
def initialize(io, filename = nil, content_type: nil)
|
64
72
|
@io = io
|
65
73
|
@filename = filename || (io.respond_to?(:path) ? io.path : io.object_id)
|
@@ -67,8 +75,18 @@ module Discorb
|
|
67
75
|
@content_type = "application/octet-stream" if @content_type == ""
|
68
76
|
end
|
69
77
|
|
78
|
+
#
|
79
|
+
# Creates a new file from a string.
|
80
|
+
#
|
81
|
+
# @param [String] string The string to create the file from.
|
82
|
+
# @param [String] filename The filename of the file. object_id of the string is used if not set.
|
83
|
+
# @param [String] content_type The content type of the file. If not set, it is guessed from the filename.
|
84
|
+
#
|
85
|
+
# @return [File] The new file.
|
86
|
+
#
|
70
87
|
def self.from_string(string, filename: nil, content_type: nil)
|
71
88
|
io = StringIO.new(string)
|
89
|
+
filename ||= string.object_id.to_s + ".txt"
|
72
90
|
new(io, filename, content_type: content_type)
|
73
91
|
end
|
74
92
|
end
|
data/lib/discorb/interaction.rb
CHANGED
@@ -198,7 +198,6 @@ module Discorb
|
|
198
198
|
# @macro http
|
199
199
|
# @macro edit
|
200
200
|
#
|
201
|
-
# @param [Discorb::Webhook::Message] message The message to edit.
|
202
201
|
# @param [String] content The new content of the message.
|
203
202
|
# @param [Discorb::Embed] embed The new embed of the message.
|
204
203
|
# @param [Array<Discorb::Embed>] embeds The new embeds of the message.
|
@@ -363,28 +362,31 @@ module Discorb
|
|
363
362
|
options = data[:options]
|
364
363
|
end
|
365
364
|
end
|
366
|
-
options ||= []
|
367
|
-
options.map! do |option|
|
368
|
-
case option[:type]
|
369
|
-
when 3, 4, 5, 10
|
370
|
-
option[:value]
|
371
|
-
when 6
|
372
|
-
guild.members[option[:value]] || guild.fetch_member(option[:value]).wait
|
373
|
-
when 7
|
374
|
-
guild.channels[option[:value]] || guild.fetch_channels.wait.find { |channel| channel.id == option[:value] }
|
375
|
-
when 8
|
376
|
-
guild.roles[option[:value]] || guild.fetch_roles.wait.find { |role| role.id == option[:value] }
|
377
|
-
when 9
|
378
|
-
guild.members[option[:value]] || guild.roles[option[:value]] || guild.fetch_member(option[:value]).wait || guild.fetch_roles.wait.find { |role| role.id == option[:value] }
|
379
|
-
end
|
380
|
-
end
|
381
365
|
|
382
366
|
unless (command = @client.bottom_commands.find { |c| c.to_s == name && c.type_raw == 1 })
|
383
367
|
@client.log.warn "Unknown command name #{name}, ignoreing"
|
384
368
|
next
|
385
369
|
end
|
386
370
|
|
387
|
-
command.
|
371
|
+
option_map = command.options.map { |k, v| [k.to_s, v[:default]] }.to_h
|
372
|
+
options ||= []
|
373
|
+
options.each do |option|
|
374
|
+
val = case option[:type]
|
375
|
+
when 3, 4, 5, 10
|
376
|
+
option[:value]
|
377
|
+
when 6
|
378
|
+
guild.members[option[:value]] || guild.fetch_member(option[:value]).wait
|
379
|
+
when 7
|
380
|
+
guild.channels[option[:value]] || guild.fetch_channels.wait.find { |channel| channel.id == option[:value] }
|
381
|
+
when 8
|
382
|
+
guild.roles[option[:value]] || guild.fetch_roles.wait.find { |role| role.id == option[:value] }
|
383
|
+
when 9
|
384
|
+
guild.members[option[:value]] || guild.roles[option[:value]] || guild.fetch_member(option[:value]).wait || guild.fetch_roles.wait.find { |role| role.id == option[:value] }
|
385
|
+
end
|
386
|
+
option_map[option[:name]] = val
|
387
|
+
end
|
388
|
+
|
389
|
+
command.block.call(self, *command.options.map { |k, v| option_map[k.to_s] })
|
388
390
|
end
|
389
391
|
end
|
390
392
|
end
|
data/lib/discorb/message.rb
CHANGED
@@ -296,11 +296,11 @@ module Discorb
|
|
296
296
|
# @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
|
297
297
|
# @param [Boolean] supress Whether to supress embeds.
|
298
298
|
#
|
299
|
-
def edit(
|
300
|
-
|
299
|
+
def edit(content = nil, embed: nil, embeds: nil, allowed_mentions: nil,
|
300
|
+
components: nil, supress: nil)
|
301
301
|
Async do
|
302
|
-
channel.edit_message(@id,
|
303
|
-
|
302
|
+
channel.edit_message(@id, content, embed: embed, embeds: embeds, allowed_mentions: allowed_mentions,
|
303
|
+
components: components, supress: supress).wait
|
304
304
|
end
|
305
305
|
end
|
306
306
|
|
data/lib/discorb/modules.rb
CHANGED
@@ -113,7 +113,7 @@ module Discorb
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
tmp_components << tmp_row
|
116
|
-
payload[:flags] = (supress ? 1 << 2 : 0) unless
|
116
|
+
payload[:flags] = (supress ? 1 << 2 : 0) unless supress.nil?
|
117
117
|
payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
|
118
118
|
end
|
119
119
|
@client.http.patch("/channels/#{channel_id.wait}/messages/#{message_id}", payload).wait
|
data/lib/discorb/utils.rb
CHANGED
@@ -14,23 +14,3 @@ module Discorb
|
|
14
14
|
module_function :try
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
|
-
class Async::Node
|
19
|
-
def description
|
20
|
-
@object_name ||= "#{self.class}:0x#{object_id.to_s(16)}#{@transient ? ' transient' : nil}"
|
21
|
-
|
22
|
-
if @annotation
|
23
|
-
"#{@object_name} #{@annotation}"
|
24
|
-
elsif line = self.backtrace(0, 1)&.first
|
25
|
-
"#{@object_name} #{line}"
|
26
|
-
else
|
27
|
-
@object_name
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_s
|
32
|
-
"\#<#{self.description}>"
|
33
|
-
end
|
34
|
-
|
35
|
-
alias inspect to_s
|
36
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discorb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sevenc-nanashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- template-replace/files/css/common.css
|
182
182
|
- template-replace/files/favicon.png
|
183
183
|
- template-replace/resources/version_list.html
|
184
|
+
- template-replace/scripts/arrow.rb
|
184
185
|
- template-replace/scripts/favicon.rb
|
185
186
|
- template-replace/scripts/index.rb
|
186
187
|
- template-replace/scripts/sidebar.rb
|