Class: Discorb::Gateway::MessageUpdateEvent

Inherits:
GatewayEvent show all
Defined in:
lib/discorb/gateway.rb

Overview

Represents a MESSAGE_UPDATE event.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data, before, after) -> MessageUpdateEvent

Returns a new instance of MessageUpdateEvent.



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/discorb/gateway.rb', line 271

def initialize(client, data, before, after)
  @client = client
  @data = data
  @before = before
  @after = after
  @id = Snowflake.new(data[:id])
  @channel_id = Snowflake.new(data[:channel_id])
  @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
  @content = data[:content]
  @timestamp = Time.iso8601(data[:edited_timestamp])
  @mention_everyone = data[:mention_everyone]
  @mention_roles = data[:mention_roles].map { |r| guild.roles[r] } if data.key?(:mention_roles)
  @attachments = data[:attachments].map { |a| Attachment.new(a) } if data.key?(:attachments)
  @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.new(data: e) } : [] if data.key?(:embeds)
end

Instance Attribute Details

#after -> Discorb::Message (readonly)

Returns The message after update.

Returns:



243
244
245
# File 'lib/discorb/gateway.rb', line 243

def after
  @after
end

#attachments -> Array<Discorb::Attachment> (readonly)

Returns The attachments in the message.

Returns:



260
261
262
# File 'lib/discorb/gateway.rb', line 260

def attachments
  @attachments
end

#before -> Discorb::Message (readonly)

Returns The message before update.

Returns:



241
242
243
# File 'lib/discorb/gateway.rb', line 241

def before
  @before
end

#channel -> nil, Discorb::Channel (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Discorb::Channel)

    The channel the message was sent in.



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/discorb/gateway.rb', line 271

def initialize(client, data, before, after)
  @client = client
  @data = data
  @before = before
  @after = after
  @id = Snowflake.new(data[:id])
  @channel_id = Snowflake.new(data[:channel_id])
  @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
  @content = data[:content]
  @timestamp = Time.iso8601(data[:edited_timestamp])
  @mention_everyone = data[:mention_everyone]
  @mention_roles = data[:mention_roles].map { |r| guild.roles[r] } if data.key?(:mention_roles)
  @attachments = data[:attachments].map { |a| Attachment.new(a) } if data.key?(:attachments)
  @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.new(data: e) } : [] if data.key?(:embeds)
end

#channel_id -> Discorb::Snowflake (readonly)

Returns The ID of the channel the message was sent in.

Returns:



247
248
249
# File 'lib/discorb/gateway.rb', line 247

def channel_id
  @channel_id
end

#content -> String (readonly)

Returns The new content of the message.

Returns:

  • (String)

    The new content of the message.



251
252
253
# File 'lib/discorb/gateway.rb', line 251

def content
  @content
end

#embeds -> Array<Discorb::Embed> (readonly)

Returns The embeds in the message.

Returns:



262
263
264
# File 'lib/discorb/gateway.rb', line 262

def embeds
  @embeds
end

#guild -> nil, Discorb::Guild (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Discorb::Guild)

    The guild the message was sent in.



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/discorb/gateway.rb', line 271

def initialize(client, data, before, after)
  @client = client
  @data = data
  @before = before
  @after = after
  @id = Snowflake.new(data[:id])
  @channel_id = Snowflake.new(data[:channel_id])
  @guild_id = Snowflake.new(data[:guild_id]) if data.key?(:guild_id)
  @content = data[:content]
  @timestamp = Time.iso8601(data[:edited_timestamp])
  @mention_everyone = data[:mention_everyone]
  @mention_roles = data[:mention_roles].map { |r| guild.roles[r] } if data.key?(:mention_roles)
  @attachments = data[:attachments].map { |a| Attachment.new(a) } if data.key?(:attachments)
  @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.new(data: e) } : [] if data.key?(:embeds)
end

#guild_id -> Discorb::Snowflake (readonly)

Returns The ID of the guild the message was sent in.

Returns:



249
250
251
# File 'lib/discorb/gateway.rb', line 249

def guild_id
  @guild_id
end

#id -> Discorb::Snowflake (readonly)

Returns The ID of the message.

Returns:



245
246
247
# File 'lib/discorb/gateway.rb', line 245

def id
  @id
end

#mention_everyone -> Boolean (readonly)

Returns Whether the message pings @everyone.

Returns:

  • (Boolean)

    Whether the message pings @everyone.



255
256
257
# File 'lib/discorb/gateway.rb', line 255

def mention_everyone
  @mention_everyone
end

#mention_roles -> nil, Array<Discorb::Role> (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Array<Discorb::Role>)

    The roles mentioned in the message.



258
259
260
# File 'lib/discorb/gateway.rb', line 258

def mention_roles
  @mention_roles
end

#timestamp -> Time (readonly)

Returns The time the message was edited.

Returns:

  • (Time)

    The time the message was edited.



253
254
255
# File 'lib/discorb/gateway.rb', line 253

def timestamp
  @timestamp
end

Instance Method Details

#fetch_message -> Async::Task<Discorb::Message>

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

Fetch the message.

Returns:

Raises:



300
301
302
303
304
# File 'lib/discorb/gateway.rb', line 300

def fetch_message
  Async do
    channel.fetch_message(@id).wait
  end
end