Class: DiscordRDA::MessageBuilder
- Inherits:
-
Object
- Object
- DiscordRDA::MessageBuilder
- Defined in:
- lib/discord_rda/entity/message_builder.rb
Overview
Builder for creating message payloads with a DSL. Supports content, embeds, components, and other message options.
Instance Method Summary collapse
-
#allowed_mentions(parse: nil, roles: nil, users: nil, replied_user: nil) ⇒ self
Set allowed mentions for the message.
-
#attachment(filename:, description: nil) ⇒ self
Add attachments (requires multipart/form-data, not supported in basic builder).
-
#components(type: 1) {|ComponentBuilder| ... } ⇒ self
Add components (buttons, select menus) to the message.
-
#content(text) ⇒ self
Set message content.
-
#embed(title: nil, description: nil, color: nil) {|EmbedBuilder| ... } ⇒ self
Add an embed to the message.
-
#flags(flags) ⇒ self
Set message flags.
-
#initialize(base = {}) ⇒ MessageBuilder
constructor
Initialize with base payload.
-
#to_h ⇒ Hash
Convert builder to hash payload.
-
#tts(enabled = true) ⇒ self
Set whether this is a TTS message.
Constructor Details
#initialize(base = {}) ⇒ MessageBuilder
Initialize with base payload
10 11 12 |
# File 'lib/discord_rda/entity/message_builder.rb', line 10 def initialize(base = {}) @payload = base end |
Instance Method Details
#allowed_mentions(parse: nil, roles: nil, users: nil, replied_user: nil) ⇒ self
Set allowed mentions for the message
78 79 80 81 82 83 84 85 |
# File 'lib/discord_rda/entity/message_builder.rb', line 78 def allowed_mentions(parse: nil, roles: nil, users: nil, replied_user: nil) @payload[:allowed_mentions] = {} @payload[:allowed_mentions][:parse] = parse if parse @payload[:allowed_mentions][:roles] = roles if roles @payload[:allowed_mentions][:users] = users if users @payload[:allowed_mentions][:replied_user] = replied_user unless replied_user.nil? self end |
#attachment(filename:, description: nil) ⇒ self
Add attachments (requires multipart/form-data, not supported in basic builder)
91 92 93 94 95 |
# File 'lib/discord_rda/entity/message_builder.rb', line 91 def (filename:, description: nil) @payload[:attachments] ||= [] @payload[:attachments] << { filename: filename, description: description }.compact self end |
#components(type: 1) {|ComponentBuilder| ... } ⇒ self
Add components (buttons, select menus) to the message
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/discord_rda/entity/message_builder.rb', line 50 def components(type: 1, &block) @payload[:components] ||= [] row = { type: type, components: [] } if block builder = ComponentBuilder.new(row[:components]) block.call(builder) end @payload[:components] << row unless row[:components].empty? self end |
#content(text) ⇒ self
Set message content
17 18 19 20 |
# File 'lib/discord_rda/entity/message_builder.rb', line 17 def content(text) @payload[:content] = text self end |
#embed(title: nil, description: nil, color: nil) {|EmbedBuilder| ... } ⇒ self
Add an embed to the message
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/discord_rda/entity/message_builder.rb', line 28 def (title: nil, description: nil, color: nil, &block) @payload[:embeds] ||= [] = {} [:title] = title if title [:description] = description if description [:color] = color.is_a?(Color) ? color.to_i : color if color if block builder = EmbedBuilder.new() block.call(builder) = builder.to_h end @payload[:embeds] << self end |
#flags(flags) ⇒ self
Set message flags
100 101 102 103 |
# File 'lib/discord_rda/entity/message_builder.rb', line 100 def flags(flags) @payload[:flags] = flags self end |
#to_h ⇒ Hash
Convert builder to hash payload
107 108 109 |
# File 'lib/discord_rda/entity/message_builder.rb', line 107 def to_h @payload end |
#tts(enabled = true) ⇒ self
Set whether this is a TTS message
67 68 69 70 |
# File 'lib/discord_rda/entity/message_builder.rb', line 67 def tts(enabled = true) @payload[:tts] = enabled self end |