discorb 0.14.0 → 0.15.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.
@@ -16,13 +16,13 @@ module Discorb
16
16
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions.
17
17
  # @param [Discorb::Message, Discorb::Message::Reference] reference The message to reply to.
18
18
  # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
19
- # @param [Discorb::File] file The file to send.
20
- # @param [Array<Discorb::File>] files The files to send.
19
+ # @param [Discorb::Attachment] attachment The attachment to send.
20
+ # @param [Array<Discorb::Attachment>] attachments The attachments to send.
21
21
  #
22
22
  # @return [Async::Task<Discorb::Message>] The message sent.
23
23
  #
24
24
  def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil,
25
- reference: nil, components: nil, file: nil, files: nil)
25
+ reference: nil, components: nil, attachment: nil, attachments: nil)
26
26
  Async do
27
27
  payload = {}
28
28
  payload[:content] = content if content
@@ -37,8 +37,17 @@ module Discorb
37
37
  allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
38
38
  payload[:message_reference] = reference.to_reference if reference
39
39
  payload[:components] = Component.to_payload(components) if components
40
- files = [file]
41
- _resp, data = @client.http.multipart_request(Route.new("/channels/#{channel_id.wait}/messages", "//channels/:channel_id/messages", :post), payload, files).wait
40
+ attachments ||= attachment ? [attachment] : []
41
+
42
+ payload[:attachments] = attachments.map.with_index do |a, i|
43
+ {
44
+ id: i,
45
+ filename: a.filename,
46
+ description: a.description,
47
+ }
48
+ end
49
+
50
+ _resp, data = @client.http.multipart_request(Route.new("/channels/#{channel_id.wait}/messages", "//channels/:channel_id/messages", :post), payload, attachments).wait
42
51
  Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
43
52
  end
44
53
  end
@@ -48,33 +57,48 @@ module Discorb
48
57
  #
49
58
  # Edit a message.
50
59
  # @async
60
+ # @!macro edit
51
61
  #
52
62
  # @param [#to_s] message_id The message id.
53
63
  # @param [String] content The message content.
54
64
  # @param [Discorb::Embed] embed The embed to send.
55
65
  # @param [Array<Discorb::Embed>] embeds The embeds to send.
56
66
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions.
67
+ # @param [Array<Discorb::Attachment>] attachments The new attachments.
57
68
  # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
58
69
  # @param [Boolean] supress Whether to supress embeds.
59
70
  #
60
71
  # @return [Async::Task<void>] The task.
61
72
  #
62
- def edit_message(message_id, content = nil, embed: nil, embeds: nil, allowed_mentions: nil,
63
- components: nil, supress: nil)
73
+ def edit_message(message_id, content = Discorb::Unset, embed: Discorb::Unset, embeds: Discorb::Unset, allowed_mentions: Discorb::Unset,
74
+ attachments: Discorb::Unset, components: Discorb::Unset, supress: Discorb::Unset)
64
75
  Async do
65
76
  payload = {}
66
- payload[:content] = content if content
67
- tmp_embed = if embed
77
+ payload[:content] = content if content != Discorb::Unset
78
+ tmp_embed = if embed != Discorb::Unset
68
79
  [embed]
69
- elsif embeds
80
+ elsif embeds != Discorb::Unset
70
81
  embeds
71
82
  end
72
83
  payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
73
84
  payload[:allowed_mentions] =
74
- allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
75
- payload[:components] = Component.to_payload(components) if components
76
- payload[:flags] = (supress ? 1 << 2 : 0) unless supress.nil?
77
- @client.http.request(Route.new("/channels/#{channel_id.wait}/messages/#{message_id}", "//channels/:channel_id/messages/:message_id", :patch), payload).wait
85
+ allowed_mentions == Discorb::Unset ? @client.allowed_mentions.to_hash : allowed_mentions.to_hash(@client.allowed_mentions)
86
+ payload[:components] = Component.to_payload(components) if components != Discorb::Unset
87
+ payload[:flags] = (supress ? 1 << 2 : 0) if supress != Discorb::Unset
88
+ if attachments != Discorb::Unset
89
+ payload[:attachments] = attachments.map.with_index do |a, i|
90
+ {
91
+ id: i,
92
+ filename: a.filename,
93
+ description: a.description,
94
+ }
95
+ end
96
+ end
97
+ @client.http.multipart_request(
98
+ Route.new("/channels/#{channel_id.wait}/messages/#{message_id}", "//channels/:channel_id/messages/:message_id", :patch),
99
+ payload,
100
+ attachments == Discorb::Unset ? [] : attachments
101
+ ).wait
78
102
  end
79
103
  end
80
104
 
@@ -334,7 +334,7 @@ module Discorb
334
334
  @channel_id = Snowflake.new(data[:channel_id])
335
335
  @author = Author.new(data[:author])
336
336
  @attachments = data[:attachments].map { |a| Attachment.new(a) }
337
- @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.new(data: e) } : []
337
+ @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.from_hash(e) } : []
338
338
  @mentions = data[:mentions].map { |m| Mention.new(m) }
339
339
  @mention_roles = data[:mention_roles].map { |m| Snowflake.new(m) }
340
340
  @mention_everyone = data[:mention_everyone]
data/lib/discorb.rb CHANGED
@@ -43,7 +43,7 @@ require_order = %w[common flag dictionary error rate_limit http intents emoji_ta
43
43
  %w[message_meta allowed_mentions] +
44
44
  %w[user member guild emoji channel embed message] +
45
45
  %w[application audit_logs color components event event_handler] +
46
- %w[file guild_template image integration interaction invite log permission] +
46
+ %w[attachment guild_template image integration interaction invite log permission] +
47
47
  %w[presence reaction role sticker utils voice_state webhook] +
48
48
  %w[gateway_requests gateway app_command] +
49
49
  %w[asset extension client extend]