discorb 0.12.0 → 0.12.4

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.
@@ -42,7 +42,22 @@ opt.parse!(ARGV)
42
42
 
43
43
  script = ARGV[0]
44
44
 
45
- script ||= "main.rb"
45
+ if script.nil?
46
+ script = "main.rb"
47
+ dir = Dir.pwd
48
+ loop do
49
+ if File.exist?(File.join(dir, "main.rb"))
50
+ script = File.join(dir, "main.rb")
51
+ break
52
+ end
53
+ break if dir == File.dirname(dir)
54
+ dir = File.dirname(dir)
55
+ end
56
+ if File.dirname(script) != Dir.pwd
57
+ Dir.chdir(File.dirname(script))
58
+ iputs "Changed directory to \e[m#{File.dirname(script)}"
59
+ end
60
+ end
46
61
 
47
62
  ENV["DISCORB_CLI_FLAG"] = "run"
48
63
  ENV["DISCORB_CLI_OPTIONS"] = JSON.generate(options)
data/lib/discorb/http.rb CHANGED
@@ -144,7 +144,7 @@ module Discorb
144
144
  end
145
145
 
146
146
  #
147
- # A helper method to send multipart/form-data requests.
147
+ # A helper method to send multipart/form-data requests for creating messages.
148
148
  #
149
149
  # @param [Hash] payload The payload to send.
150
150
  # @param [Array<Discorb::File>] files The files to send.
@@ -159,15 +159,22 @@ module Discorb
159
159
 
160
160
  #{payload.to_json}
161
161
  HTTP
162
- files.each do |single_file|
162
+ files.each_with_index do |single_file, i|
163
163
  str_payloads << <<~HTTP
164
- Content-Disposition: form-data; name="file"; filename="#{single_file.filename}"
164
+ Content-Disposition: form-data; name="files[#{i}]"; filename="#{single_file.filename}"
165
165
  Content-Type: #{single_file.content_type}
166
166
 
167
167
  #{single_file.io.read}
168
168
  HTTP
169
169
  end
170
- [boundary, "--#{boundary}\n#{str_payloads.join("\n--#{boundary}\n")}\n--#{boundary}--"]
170
+ payload = +"--#{boundary}".encode(Encoding::ASCII_8BIT)
171
+ str_payloads.each do |str_payload|
172
+ payload << "\r\n".encode(Encoding::ASCII_8BIT)
173
+ payload << str_payload.force_encoding(Encoding::ASCII_8BIT)
174
+ payload << "\r\n--#{boundary}".encode(Encoding::ASCII_8BIT)
175
+ end
176
+ payload += +"--".encode(Encoding::ASCII_8BIT)
177
+ [boundary, payload]
171
178
  end
172
179
 
173
180
  private
@@ -84,7 +84,7 @@ module Discorb
84
84
  @account = Account.new(data[:account])
85
85
  @subscriber_count = data[:subscriber_count]
86
86
  @revoked = data[:revoked]
87
- @application = Application.new(@client, data[:application])
87
+ @application = data[:application] and Application.new(@client, data[:application])
88
88
  end
89
89
 
90
90
  class << self
@@ -18,7 +18,7 @@ module Discorb
18
18
  end
19
19
 
20
20
  option_map = command.options.map { |k, v| [k.to_s, v[:default]] }.to_h
21
- Discorb::CommandInteraction::SlashCommand.modify_option_map(option_map, options)
21
+ Discorb::CommandInteraction::SlashCommand.modify_option_map(option_map, options, guild)
22
22
  focused_index = options.find_index { |o| o[:focused] }
23
23
  val = command.options.values[focused_index][:autocomplete]&.call(self, *command.options.map { |k, v| option_map[k.to_s] })
24
24
  send_complete_result(val)
@@ -26,7 +26,7 @@ module Discorb
26
26
  end
27
27
 
28
28
  option_map = command.options.map { |k, v| [k.to_s, v[:default]] }.to_h
29
- SlashCommand.modify_option_map(option_map, options)
29
+ SlashCommand.modify_option_map(option_map, options, guild)
30
30
 
31
31
  command.block.call(self, *command.options.map { |k, v| option_map[k.to_s] })
32
32
  end
@@ -59,7 +59,7 @@ module Discorb
59
59
  end
60
60
 
61
61
  # @private
62
- def modify_option_map(option_map, options)
62
+ def modify_option_map(option_map, options, guild)
63
63
  options ||= []
64
64
  options.each_with_index do |option|
65
65
  val = case option[:type]
@@ -109,9 +109,10 @@ module Discorb
109
109
  # * `:guild_discovery_grace_period_final_warning`
110
110
  # * `:thread_created`
111
111
  # * `:reply`
112
- # * `:application_command`
112
+ # * `:chat_input_command`
113
113
  # * `:thread_starter_message`
114
114
  # * `:guild_invite_reminder`
115
+ # * `:context_menu_command`
115
116
  attr_reader :type
116
117
  # @return [Discorb::Message::Activity] The activity of the message.
117
118
  attr_reader :activity
@@ -143,28 +144,29 @@ module Discorb
143
144
  attr_reader :pinned
144
145
  alias pinned? pinned
145
146
  @message_type = {
146
- default: 0,
147
- recipient_add: 1,
148
- recipient_remove: 2,
149
- call: 3,
150
- channel_name_change: 4,
151
- channel_icon_change: 5,
152
- channel_pinned_message: 6,
153
- guild_member_join: 7,
154
- user_premium_guild_subscription: 8,
155
- user_premium_guild_subscription_tier_1: 9,
156
- user_premium_guild_subscription_tier_2: 10,
157
- user_premium_guild_subscription_tier_3: 11,
158
- channel_follow_add: 12,
159
- guild_discovery_disqualified: 14,
160
- guild_discovery_requalified: 15,
161
- guild_discovery_grace_period_initial_warning: 16,
162
- guild_discovery_grace_period_final_warning: 17,
163
- thread_created: 18,
164
- reply: 19,
165
- application_command: 20,
166
- thread_starter_message: 21,
167
- guild_invite_reminder: 22,
147
+ 0 => :default,
148
+ 1 => :recipient_add,
149
+ 2 => :recipient_remove,
150
+ 3 => :call,
151
+ 4 => :channel_name_change,
152
+ 5 => :channel_icon_change,
153
+ 6 => :channel_pinned_message,
154
+ 7 => :guild_member_join,
155
+ 8 => :user_premium_guild_subscription,
156
+ 9 => :user_premium_guild_subscription_tier_1,
157
+ 10 => :user_premium_guild_subscription_tier_2,
158
+ 11 => :user_premium_guild_subscription_tier_3,
159
+ 12 => :channel_follow_add,
160
+ 14 => :guild_discovery_disqualified,
161
+ 15 => :guild_discovery_requalified,
162
+ 16 => :guild_discovery_grace_period_initial_warning,
163
+ 17 => :guild_discovery_grace_period_final_warning,
164
+ 18 => :thread_created,
165
+ 19 => :reply,
166
+ 20 => :chat_input_command,
167
+ 21 => :thread_starter_message,
168
+ 22 => :guild_invite_reminder,
169
+ 23 => :context_menu_command,
168
170
  }.freeze
169
171
 
170
172
  # @!attribute [r] channel
data/lib/discorb/user.rb CHANGED
@@ -26,6 +26,9 @@ module Discorb
26
26
 
27
27
  include Discorb::Messageable
28
28
 
29
+ # @!attribute [r] mention
30
+ # @return [String] The user's mention.
31
+
29
32
  # @private
30
33
  def initialize(client, data)
31
34
  @client = client
@@ -43,6 +46,10 @@ module Discorb
43
46
  "#{@username}##{@discriminator}"
44
47
  end
45
48
 
49
+ def mention
50
+ "<@#{@id}>"
51
+ end
52
+
46
53
  alias to_s_user to_s
47
54
 
48
55
  def inspect
@@ -22,6 +22,12 @@ def yard_replace(dir, version)
22
22
  <h1 class="noborder title">Documentation by YARD 0.9.26</h1>
23
23
  HTML3
24
24
  HTML4
25
+ if version == "main"
26
+ display_version = "(main)"
27
+ else
28
+ display_version = "v" + version
29
+ end
30
+ contents.gsub!(/Documentation by YARD \d+\.\d+\.\d+/, "discorb #{display_version} documentation")
25
31
  File.write(file, contents)
26
32
  end
27
33
  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.12.0
4
+ version: 0.12.4
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-10-24 00:00:00.000000000 Z
11
+ date: 2021-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -77,11 +77,13 @@ files:
77
77
  - ".github/ISSUE_TEMPLATE/bug_report.md"
78
78
  - ".github/ISSUE_TEMPLATE/config.yml"
79
79
  - ".github/ISSUE_TEMPLATE/feature_request.md"
80
+ - ".github/PULL_REQUEST_TEMPLATE.md"
80
81
  - ".github/workflows/build_main.yml"
81
82
  - ".github/workflows/build_version.yml"
82
83
  - ".github/workflows/package_register.yml"
83
84
  - ".gitignore"
84
85
  - ".yardopts"
86
+ - CONTRIBUTING.md
85
87
  - Changelog.md
86
88
  - Gemfile
87
89
  - LICENSE.txt
@@ -219,5 +221,5 @@ requirements: []
219
221
  rubygems_version: 3.2.22
220
222
  signing_key:
221
223
  specification_version: 4
222
- summary: discorb is a Discord API wrapper for Ruby.
224
+ summary: A discord API wrapper written in Ruby
223
225
  test_files: []