Module: OnyxCord::Events::Respondable
- Included in:
- MessageEvent, MessageIDEvent, ReactionEvent, ReactionRemoveAllEvent, TypingEvent
- Defined in:
- lib/onyxcord/events/message/base.rb
Overview
Module to make sending messages easier with the presence of a text channel in an event
Instance Attribute Summary collapse
-
#channel ⇒ Channel
readonly
The channel in which this event occurred.
Instance Method Summary collapse
-
#<<(message) ⇒ Object
Adds a string to be sent after the event has finished execution.
-
#drain ⇒ Object
Drains the currently saved message, which clears it out, resulting in everything being saved before being thrown away and nothing being sent to the channel (unless there is something saved after this).
-
#drain_into(result) ⇒ String
Drains the currently saved message into a result string.
-
#send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) {|embed| ... } ⇒ Message
The same as #send_message, but yields a Webhooks::Embed for easy building of embedded content inside a block.
-
#send_message(content = nil, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0, embeds: nil, **_kwargs) ⇒ OnyxCord::Message
(also: #send, #respond)
Sends a message to the channel this message was sent in, right now.
-
#send_message! ⇒ Object
(also: #send!, #respond!)
Sends a message to the channel this message was sent in, right now.
-
#send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, components = nil, flags = 0) ⇒ Object
(also: #send_temp)
Sends a temporary message to the channel this message was sent in, right now.
Instance Attribute Details
#channel ⇒ Channel (readonly)
Returns the channel in which this event occurred.
10 11 12 |
# File 'lib/onyxcord/events/message/base.rb', line 10 def channel @channel end |
Instance Method Details
#<<(message) ⇒ Object
Adds a string to be sent after the event has finished execution. Avoids problems with rate limiting because only one message is ever sent. If it is used multiple times, the strings will bunch up into one message (separated by newlines)
76 77 78 79 80 |
# File 'lib/onyxcord/events/message/base.rb', line 76 def <<() addition = "#{}\n" @saved_message = @saved_message ? @saved_message + addition : addition nil end |
#drain ⇒ Object
Drains the currently saved message, which clears it out, resulting in everything being saved before being thrown away and nothing being sent to the channel (unless there is something saved after this).
85 86 87 88 |
# File 'lib/onyxcord/events/message/base.rb', line 85 def drain @saved_message = '' nil end |
#drain_into(result) ⇒ String
Drains the currently saved message into a result string. This prepends it before that string, clears the saved message and returns the concatenation.
94 95 96 97 98 99 100 |
# File 'lib/onyxcord/events/message/base.rb', line 94 def drain_into(result) return if result.is_a?(OnyxCord::Message) result = (@saved_message.nil? ? '' : @saved_message.to_s) + (result.nil? ? '' : result.to_s) drain result end |
#send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) {|embed| ... } ⇒ Message
The same as #send_message, but yields a Webhooks::Embed for easy building of embedded content inside a block.
49 50 51 |
# File 'lib/onyxcord/events/message/base.rb', line 49 def ( = '', = nil, = nil, tts = false, allowed_mentions = nil, = nil, components = nil, flags = 0, &block) channel.(, , , tts, allowed_mentions, , components, flags, &block) end |
#send_message(content = nil, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0, embeds: nil, **_kwargs) ⇒ OnyxCord::Message Also known as: send, respond
Sends a message to the channel this message was sent in, right now. Supports both positional and keyword arguments:
event.('Hello')
event.('Hello', false, { title: 'Hi' })
event.('Hello', embed: { title: 'Hi' })
event.(embed: { title: 'Hi' })
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/onyxcord/events/message/base.rb', line 21 def (content = nil, tts = false, = nil, = nil, allowed_mentions = nil, = nil, components = nil, flags = 0, embeds: nil, **_kwargs) # Support keyword args: event.send_message('text', embed: { ... }) = Array() if && ! ||= [] # Use first embed for backward-compatible positional API = .first channel.(content || '', tts, , , allowed_mentions, , components, flags) end |
#send_message! ⇒ Object Also known as: send!, respond!
Sends a message to the channel this message was sent in, right now.
68 69 70 |
# File 'lib/onyxcord/events/message/base.rb', line 68 def (...) channel.(...) end |
#send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, components = nil, flags = 0) ⇒ Object Also known as: send_temp
Sends a temporary message to the channel this message was sent in, right now.
62 63 64 |
# File 'lib/onyxcord/events/message/base.rb', line 62 def (content, timeout, tts = false, = nil, = nil, allowed_mentions = nil, components = nil, flags = 0) channel.(content, timeout, tts, , , allowed_mentions, components, flags) end |