discorb 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 575a8b441c3065b5ffa3620b115c58f6356da23c0a50448e48e8db2c364093ef
4
- data.tar.gz: c355067b4585325ecc33e400e5a96ba5b95f71843882217f1bc6d34de502b931
3
+ metadata.gz: 39902a57677adf3ce903678e58060ee04da318617ba81611546772131c9d1696
4
+ data.tar.gz: 6f0f17d2230a19b79f6330cda2d567f704f8ffe44ca59e8938cc0ec0f32dfb35
5
5
  SHA512:
6
- metadata.gz: c93f55029eeaaa52448146e1f19f4fd482ae50038b3024c7339a32ad6afc350604e860ae11d8ca36a69b13fc565ce7c64aa445fe17aca2423c6aad9792e2e78f
7
- data.tar.gz: 57e2b64e98d0fbff3cb69c8ad576267adc9d17dbe066b1005db2c5a394d7a61faf003e8957b858fc18804b76195a1d16cd0d00ce1e49a9b8ff11225c5289dc5a
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
 
@@ -60,13 +60,14 @@ In `options`, hash should be like this:
60
60
  }
61
61
  }
62
62
  ```
63
-
64
- | Key | Description |
65
- | --- | --- |
66
- | `type` | The type of the argument. |
67
- | `required` | Whether the argument is required. |
68
- | `description` | The description of the argument. |
69
- | `choices` | The choices of the argument. |
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
@@ -4,4 +4,4 @@
4
4
 
5
5
  discorb is licensed under the [MIT license](https://opensource.org/licenses/MIT).
6
6
 
7
- {include:file:License.txt}
7
+ {include:file:LICENSE.txt}
@@ -20,9 +20,11 @@ module Discorb
20
20
  # | Key | Type | Description |
21
21
  # | --- | --- | --- |
22
22
  # | `:description` | `String` | Description of the option. |
23
- # | `:optional` | `Boolean` | Whether the option is optional or not. |
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] } }
@@ -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.4"
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
 
@@ -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
@@ -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.block.call(self, *options)
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
@@ -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(message_id, content = nil, embed: nil, embeds: nil, allowed_mentions: nil,
300
- components: nil, supress: nil)
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, message_id, content, embed: embed, embeds: embeds, allowed_mentions: allowed_mentions,
303
- components: components, supress: supress).wait
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
 
@@ -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 flags.nil?
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
@@ -550,6 +550,6 @@ dd pre.code {
550
550
  display: inline !important;
551
551
  }
552
552
 
553
- p.signature, h3.signature{
554
- font-family: var(--font-monospace);
553
+ p.signature, h3.signature, p.signature tt, h3.signature tt{
554
+ font-family: var(--monospace-font);
555
555
  }
@@ -0,0 +1,7 @@
1
+ def replace_arrow(dir)
2
+ Dir.glob("#{dir}/**/*.html") do |file|
3
+ content = File.read(file)
4
+ content.gsub!(" &#x21d2; ", " -&gt; ")
5
+ File.write(file, content, mode: "wb")
6
+ end
7
+ 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
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-26 00:00:00.000000000 Z
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