Skip to content

Commit 92ffcd6

Browse files
Merge branch 'main' into feat/rubocop-rspec
2 parents 7427bbe + cfce8ce commit 92ffcd6

File tree

8 files changed

+68
-39
lines changed

8 files changed

+68
-39
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Gem](https://img.shields.io/gem/v/discordrb.svg)](https://rubygems.org/gems/discordrb)
44
[![Gem](https://img.shields.io/gem/dt/discordrb.svg)](https://rubygems.org/gems/discordrb)
55
[![CircleCI](https://circleci.com/gh/shardlab/discordrb.svg?style=svg)](https://circleci.com/gh/shardlab/discordrb)
6-
[![Inline docs](https://inch-ci.org/github/shardlab/discordrb.svg?branch=main)](https://drb.shardlab.dev/v3.4.0/)
6+
[![Inline docs](https://inch-ci.org/github/shardlab/discordrb.svg?branch=main)](https://drb.shardlab.dev/v3.5.0/)
77
[![Join Discord](https://img.shields.io/badge/discord-join-7289DA.svg)](https://discord.gg/cyK3Hjm)
88

99
An implementation of the [Discord](https://discord.com/) API using Ruby.
@@ -19,7 +19,7 @@ An implementation of the [Discord](https://discord.com/) API using Ruby.
1919
- [Development](https://github.com/shardlab/discordrb#development), [Contributing](https://github.com/shardlab/discordrb#contributing)
2020
- [License](https://github.com/shardlab/discordrb#license)
2121

22-
See also: [Documentation](https://drb.shardlab.dev/v3.4.0/), [Tutorials](https://github.com/shardlab/discordrb/wiki)
22+
See also: [Documentation](https://drb.shardlab.dev/v3.5.0/), [Tutorials](https://github.com/shardlab/discordrb/wiki)
2323

2424
## Introduction
2525

@@ -131,7 +131,7 @@ If you've made an open source project on GitHub that uses discordrb, consider ad
131131

132132
Also included is a webhooks client, which can be used as a separate gem `discordrb-webhooks`. This special client can be used to form requests to Discord webhook URLs in a high-level manner.
133133

134-
- [`discordrb-webhooks` documentation](https://drb.shardlab.dev/v3.4.0/Discordrb/Webhooks.html)
134+
- [`discordrb-webhooks` documentation](https://drb.shardlab.dev/v3.5.0/Discordrb/Webhooks.html)
135135
- [More information about webhooks](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks)
136136
- [Embed visualizer tool](https://leovoel.github.io/embed-visualizer/) - Includes a discordrb code generator for forming embeds
137137

lib/discordrb/api/channel.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def message(token, channel_id, message_id)
7575
# https://discord.com/developers/docs/resources/channel#create-message
7676
# @param attachments [Array<File>, nil] Attachments to use with `attachment://` in embeds. See
7777
# https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds
78-
def create_message(token, channel_id, message, tts = false, embeds = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
79-
body = { content: message, tts: tts, embeds: embeds, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference, components: components&.to_a }
78+
def create_message(token, channel_id, message, tts = false, embeds = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = nil)
79+
body = { content: message, tts: tts, embeds: embeds, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference, components: components&.to_a, flags: flags }
8080
body = if attachments
8181
files = [*0...attachments.size].zip(attachments).to_h
8282
{ **files, payload_json: body.to_json }
@@ -117,13 +117,13 @@ def upload_file(token, channel_id, file, caption: nil, tts: false)
117117

118118
# Edit a message
119119
# https://discord.com/developers/docs/resources/channel#edit-message
120-
def edit_message(token, channel_id, message_id, message, mentions = [], embeds = nil, components = nil)
120+
def edit_message(token, channel_id, message_id, message, mentions = [], embeds = nil, components = nil, flags = nil)
121121
Discordrb::API.request(
122122
:channels_cid_messages_mid,
123123
channel_id,
124124
:patch,
125125
"#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
126-
{ content: message, mentions: mentions, embeds: embeds, components: components }.to_json,
126+
{ content: message, mentions: mentions, embeds: embeds, components: components, flags: flags }.reject { |_, v| v == :undef }.to_json,
127127
Authorization: token,
128128
content_type: :json
129129
)

lib/discordrb/bot.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,16 @@ def delete_invite(code)
401401
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
402402
# @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
403403
# @param components [View, Array<Hash>] Interaction components to associate with this message.
404+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.
404405
# @return [Message] The message that was sent.
405-
def send_message(channel, content, tts = false, embeds = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
406+
def send_message(channel, content, tts = false, embeds = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
406407
channel = channel.resolve_id
407408
debug("Sending message to #{channel} with content '#{content}'")
408409
allowed_mentions = { parse: [] } if allowed_mentions == false
409410
message_reference = { message_id: message_reference.id } if message_reference.respond_to?(:id)
410411
embeds = (embeds.instance_of?(Array) ? embeds.map(&:to_hash) : [embeds&.to_hash]).compact
411412

412-
response = API::Channel.create_message(token, channel, content, tts, embeds, nil, attachments, allowed_mentions&.to_hash, message_reference, components)
413+
response = API::Channel.create_message(token, channel, content, tts, embeds, nil, attachments, allowed_mentions&.to_hash, message_reference, components, flags)
413414
Message.new(JSON.parse(response), self)
414415
end
415416

@@ -424,11 +425,12 @@ def send_message(channel, content, tts = false, embeds = nil, attachments = nil,
424425
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
425426
# @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
426427
# @param components [View, Array<Hash>] Interaction components to associate with this message.
427-
def send_temporary_message(channel, content, timeout, tts = false, embeds = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
428+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.
429+
def send_temporary_message(channel, content, timeout, tts = false, embeds = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
428430
Thread.new do
429431
Thread.current[:discordrb_name] = "#{@current_thread}-temp-msg"
430432

431-
message = send_message(channel, content, tts, embeds, attachments, allowed_mentions, message_reference, components)
433+
message = send_message(channel, content, tts, embeds, attachments, allowed_mentions, message_reference, components, flags)
432434
sleep(timeout)
433435
message.delete
434436
end

lib/discordrb/data/activity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def instance?
121121

122122
# @!visibility private
123123
def flag_set?(sym)
124-
@flags.nobits?(FLAGS[sym])
124+
!@flags.nobits?(FLAGS[sym])
125125
end
126126

127127
# Timestamps for the start and end of instanced activities

lib/discordrb/data/channel.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,10 @@ def slowmode?
428428
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
429429
# @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
430430
# @param components [View, Array<Hash>] Interaction components to associate with this message.
431+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.
431432
# @return [Message] the message that was sent.
432-
def send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
433-
@bot.send_message(@id, content, tts, embed, attachments, allowed_mentions, message_reference, components)
433+
def send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
434+
@bot.send_message(@id, content, tts, embed, attachments, allowed_mentions, message_reference, components, flags)
434435
end
435436

436437
alias_method :send, :send_message
@@ -444,8 +445,9 @@ def send_message(content, tts = false, embed = nil, attachments = nil, allowed_m
444445
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
445446
# @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
446447
# @param components [View, Array<Hash>] Interaction components to associate with this message.
447-
def send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
448-
@bot.send_temporary_message(@id, content, timeout, tts, embed, attachments, allowed_mentions, message_reference, components)
448+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.
449+
def send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
450+
@bot.send_temporary_message(@id, content, timeout, tts, embed, attachments, allowed_mentions, message_reference, components, flags)
449451
end
450452

451453
# Convenience method to send a message with an embed.
@@ -461,16 +463,17 @@ def send_temporary_message(content, timeout, tts = false, embed = nil, attachmen
461463
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
462464
# @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
463465
# @param components [View, Array<Hash>] Interaction components to associate with this message.
466+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.
464467
# @yield [embed] Yields the embed to allow for easy building inside a block.
465468
# @yieldparam embed [Discordrb::Webhooks::Embed] The embed from the parameters, or a new one.
466469
# @return [Message] The resulting message.
467-
def send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil, components = nil)
470+
def send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
468471
embed ||= Discordrb::Webhooks::Embed.new
469472
view = Discordrb::Webhooks::View.new
470473

471474
yield(embed, view) if block_given?
472475

473-
send_message(message, tts, embed, attachments, allowed_mentions, message_reference, components || view.to_a)
476+
send_message(message, tts, embed, attachments, allowed_mentions, message_reference, components || view.to_a, flags)
474477
end
475478

476479
# Sends multiple messages to a channel

lib/discordrb/data/message.rb

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,15 @@ class Message
7070
# @return [Integer, nil] the webhook ID that sent this message, or `nil` if it wasn't sent through a webhook.
7171
attr_reader :webhook_id
7272

73-
# @return [Array<Component>]
73+
# @return [Array<Component>] Interaction components for this message.
7474
attr_reader :components
7575

76+
# @return [Integer] flags set on the message.
77+
attr_reader :flags
78+
79+
# @return [Channel, nil] The thread that was started from this message, or nil.
80+
attr_reader :thread
81+
7682
# @!visibility private
7783
def initialize(data, bot)
7884
@bot = bot
@@ -157,6 +163,10 @@ def initialize(data, bot)
157163

158164
@components = []
159165
@components = data['components'].map { |component_data| Components.from_data(component_data, @bot) } if data['components']
166+
167+
@flags = data['flags'] || 0
168+
169+
@thread = data['thread'] ? @bot.ensure_channel(data['thread'], @server) : nil
160170
end
161171

162172
# Replies to this message with the specified content.
@@ -176,31 +186,33 @@ def reply(content)
176186
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
177187
# @param mention_user [true, false] Whether the user that is being replied to should be pinged by the reply.
178188
# @param components [View, Array<Hash>] Interaction components to associate with this message.
189+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.
179190
# @return (see #respond)
180-
def reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false, components: nil)
191+
def reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false, components: nil, flags: 0)
181192
allowed_mentions = { parse: [] } if allowed_mentions == false
182193
allowed_mentions = allowed_mentions.to_hash.transform_keys(&:to_sym)
183194
allowed_mentions[:replied_user] = mention_user
184195

185-
respond(content, tts, embed, attachments, allowed_mentions, self, components)
196+
respond(content, tts, embed, attachments, allowed_mentions, self, components, flags)
186197
end
187198

188199
# (see Channel#send_message)
189-
def respond(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
190-
@channel.send_message(content, tts, embed, attachments, allowed_mentions, message_reference, components)
200+
def respond(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
201+
@channel.send_message(content, tts, embed, attachments, allowed_mentions, message_reference, components, flags)
191202
end
192203

193204
# Edits this message to have the specified content instead.
194205
# You can only edit your own messages.
195206
# @param new_content [String] the new content the message should have.
196207
# @param new_embeds [Hash, Discordrb::Webhooks::Embed, Array<Hash>, Array<Discordrb::Webhooks::Embed>, nil] The new embeds the message should have. If `nil` the message will be changed to have no embeds.
197208
# @param new_components [View, Array<Hash>] The new components the message should have. If `nil` the message will be changed to have no components.
209+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) can be edited.
198210
# @return [Message] the resulting message.
199-
def edit(new_content, new_embeds = nil, new_components = nil)
211+
def edit(new_content, new_embeds = nil, new_components = nil, flags = 0)
200212
new_embeds = (new_embeds.instance_of?(Array) ? new_embeds.map(&:to_hash) : [new_embeds&.to_hash]).compact
201213
new_components = new_components.to_a
202214

203-
response = API::Channel.edit_message(@bot.token, @channel.id, @id, new_content, [], new_embeds, new_components)
215+
response = API::Channel.edit_message(@bot.token, @channel.id, @id, new_content, [], new_embeds, new_components, flags)
204216
Message.new(JSON.parse(response), @bot)
205217
end
206218

@@ -292,6 +304,14 @@ def my_reactions
292304
@reactions.select(&:me)
293305
end
294306

307+
# Removes embeds from the message
308+
# @return [Message] the resulting message.
309+
def suppress_embeds
310+
flags = @flags | (1 << 2)
311+
response = API::Channel.edit_message(@bot.token, @channel.id, @id, :undef, :undef, :undef, :undef, flags)
312+
Message.new(JSON.parse(response), @bot)
313+
end
314+
295315
# Reacts to a message.
296316
# @param reaction [String, #to_reaction] the unicode emoji or {Emoji}
297317
def create_reaction(reaction)

lib/discordrb/events/message.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ module Respondable
1818
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
1919
# @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
2020
# @param components [View, Array<Hash>, nil] A collection of components to attach to the message.
21+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.
2122
# @return [Discordrb::Message] the message that was sent
22-
def send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
23-
channel.send_message(content, tts, embed, attachments, allowed_mentions, message_reference, components)
23+
def send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
24+
channel.send_message(content, tts, embed, attachments, allowed_mentions, message_reference, components, flags)
2425
end
2526

2627
# The same as {#send_message}, but yields a {Webhooks::Embed} for easy building of embedded content inside a block.
@@ -32,11 +33,12 @@ def send_message(content, tts = false, embed = nil, attachments = nil, allowed_m
3233
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
3334
# @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
3435
# @param components [View, Array<Hash>, nil] A collection of components to attach to the message.
36+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.
3537
# @yield [embed] Yields the embed to allow for easy building inside a block.
3638
# @yieldparam embed [Discordrb::Webhooks::Embed] The embed from the parameters, or a new one.
3739
# @return [Message] The resulting message.
38-
def send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil, components = nil, &block)
39-
channel.send_embed(message, embed, attachments, tts, allowed_mentions, message_reference, components, &block)
40+
def send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0, &block)
41+
channel.send_embed(message, embed, attachments, tts, allowed_mentions, message_reference, components, flags, &block)
4042
end
4143

4244
# Sends a temporary message to the channel this message was sent in, right now.
@@ -47,8 +49,9 @@ def send_embed(message = '', embed = nil, attachments = nil, tts = false, allowe
4749
# @param attachments [Array<File>] Files that can be referenced in embeds via `attachment://file.png`
4850
# @param allowed_mentions [Hash, Discordrb::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
4951
# @param components [View, Array<Hash>, nil] A collection of components to attach to the message.
50-
def send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, components = nil)
51-
channel.send_temporary_message(content, timeout, tts, embed, attachments, allowed_mentions, components)
52+
# @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.
53+
def send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, components = nil, flags = 0)
54+
channel.send_temporary_message(content, timeout, tts, embed, attachments, allowed_mentions, components, flags)
5255
end
5356

5457
# Adds a string to be sent after the event has finished execution. Avoids problems with rate limiting because only

0 commit comments

Comments
 (0)