Class: OnyxCord::Events::MessageEvent
- Includes:
- Respondable
- Defined in:
- lib/onyxcord/events/message/base.rb
Overview
Event raised when a text message is sent to a channel
Direct Known Subclasses
Commands::CommandEvent, MentionEvent, MessageEditEvent, MessageUpdateEvent, PrivateMessageEvent
Instance Attribute Summary collapse
-
#author ⇒ Member, User
(also: #user)
readonly
Who sent this message.
-
#channel ⇒ Channel
readonly
The channel in which this message was sent.
-
#content ⇒ String
(also: #text)
readonly
The message's content.
-
#file ⇒ File
readonly
The file that has been saved by a call to #attach_file and will be sent to Discord upon completion.
-
#file_spoiler ⇒ true, false
readonly
Whether or not this file should appear as a spoiler.
-
#filename ⇒ String
readonly
The filename set in #attach_file that will override the original filename when sent.
-
#message ⇒ Message
readonly
The message which triggered this event.
-
#saved_message ⇒ String
readonly
The message that has been saved by calls to Respondable#<< and will be sent to Discord upon completion.
-
#server ⇒ Server?
readonly
The server where this message was sent, or nil if it was sent in PM.
-
#timestamp ⇒ Time
readonly
The time at which the message was sent.
Attributes inherited from Event
Instance Method Summary collapse
-
#attach_file(file, filename: nil, spoiler: nil) ⇒ Object
Attaches a file to the message event and converts the message into a caption.
-
#detach_file ⇒ Object
Detaches a file from the message event.
-
#from_bot? ⇒ true, false
Whether or not this message was sent by the bot itself.
-
#send_file(file, caption: nil, filename: nil, spoiler: nil) ⇒ OnyxCord::Message
Sends file with a caption to the channel this message was sent in, right now.
-
#voice ⇒ Client?
Utility method to get the voice bot for the current server.
Methods included from Respondable
#<<, #drain, #drain_into, #send_embed, #send_message, #send_message!, #send_temporary_message
Instance Attribute Details
#author ⇒ Member, User (readonly) Also known as: user
Returns who sent this message.
143 |
# File 'lib/onyxcord/events/message/base.rb', line 143 delegate :author, :channel, :content, :timestamp, to: :message |
#channel ⇒ Channel (readonly)
Returns the channel in which this message was sent.
143 |
# File 'lib/onyxcord/events/message/base.rb', line 143 delegate :author, :channel, :content, :timestamp, to: :message |
#content ⇒ String (readonly) Also known as: text
Returns the message's content.
143 |
# File 'lib/onyxcord/events/message/base.rb', line 143 delegate :author, :channel, :content, :timestamp, to: :message |
#file ⇒ File (readonly)
Returns the file that has been saved by a call to #attach_file and will be sent to Discord upon completion.
123 124 125 |
# File 'lib/onyxcord/events/message/base.rb', line 123 def file @file end |
#file_spoiler ⇒ true, false (readonly)
Returns Whether or not this file should appear as a spoiler. Set by #attach_file.
129 130 131 |
# File 'lib/onyxcord/events/message/base.rb', line 129 def file_spoiler @file_spoiler end |
#filename ⇒ String (readonly)
Returns the filename set in #attach_file that will override the original filename when sent.
126 127 128 |
# File 'lib/onyxcord/events/message/base.rb', line 126 def filename @filename end |
#message ⇒ Message (readonly)
Returns the message which triggered this event.
117 118 119 |
# File 'lib/onyxcord/events/message/base.rb', line 117 def @message end |
#saved_message ⇒ String (readonly)
Returns the message that has been saved by calls to Respondable#<< and will be sent to Discord upon completion.
120 121 122 |
# File 'lib/onyxcord/events/message/base.rb', line 120 def @saved_message end |
#server ⇒ Server? (readonly)
Returns the server where this message was sent, or nil if it was sent in PM.
148 |
# File 'lib/onyxcord/events/message/base.rb', line 148 delegate :server, to: :channel |
#timestamp ⇒ Time (readonly)
Returns the time at which the message was sent.
143 |
# File 'lib/onyxcord/events/message/base.rb', line 143 delegate :author, :channel, :content, :timestamp, to: :message |
Instance Method Details
#attach_file(file, filename: nil, spoiler: nil) ⇒ Object
Attaches a file to the message event and converts the message into a caption.
180 181 182 183 184 185 186 187 |
# File 'lib/onyxcord/events/message/base.rb', line 180 def attach_file(file, filename: nil, spoiler: nil) raise ArgumentError, 'Argument is not a file!' unless file.is_a?(File) @file = file @filename = filename @file_spoiler = spoiler nil end |
#detach_file ⇒ Object
Detaches a file from the message event.
190 191 192 193 194 |
# File 'lib/onyxcord/events/message/base.rb', line 190 def detach_file @file = nil @filename = nil @file_spoiler = nil end |
#from_bot? ⇒ true, false
Returns whether or not this message was sent by the bot itself.
197 198 199 |
# File 'lib/onyxcord/events/message/base.rb', line 197 def from_bot? @message.user.id == @bot.profile.id end |
#send_file(file, caption: nil, filename: nil, spoiler: nil) ⇒ OnyxCord::Message
Sends file with a caption to the channel this message was sent in, right now. It is usually preferable to use Respondable#<< and #attach_file instead because it avoids rate limiting problems
171 172 173 |
# File 'lib/onyxcord/events/message/base.rb', line 171 def send_file(file, caption: nil, filename: nil, spoiler: nil) @message.channel.send_file(file, caption: caption, filename: filename, spoiler: spoiler) end |
#voice ⇒ Client?
Utility method to get the voice bot for the current server
203 204 205 |
# File 'lib/onyxcord/events/message/base.rb', line 203 def voice @bot.voice(@message.channel.server.id) end |