Class: Discorb::Gateway::MessageUpdateEvent

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

Overview

Represents a MESSAGE_UPDATE event.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GatewayEvent

#inspect

Constructor Details

#initialize(client, data, before, after) ⇒ MessageUpdateEvent

Returns a new instance of MessageUpdateEvent.



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/discorb/gateway_events.rb', line 340

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.from_hash(a) } if data.key?(
    :attachments
  )
  @embeds =
    (
      if data[:embeds]
        data[:embeds].map { |e| Embed.from_hash(e) }
      else
        []
      end
    ) if data.key?(:embeds)
end

Instance Attribute Details

#afterDiscorb::Message (readonly)

Returns The message after update.

Returns:



312
313
314
# File 'lib/discorb/gateway_events.rb', line 312

def after
  @after
end

#attachmentsArray<Discorb::Attachment> (readonly)

Returns The attachments in the message.

Returns:



329
330
331
# File 'lib/discorb/gateway_events.rb', line 329

def attachments
  @attachments
end

#beforeDiscorb::Message (readonly)

Returns The message before update.

Returns:



310
311
312
# File 'lib/discorb/gateway_events.rb', line 310

def before
  @before
end

#channelnil, 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.



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/discorb/gateway_events.rb', line 340

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.from_hash(a) } if data.key?(
    :attachments
  )
  @embeds =
    (
      if data[:embeds]
        data[:embeds].map { |e| Embed.from_hash(e) }
      else
        []
      end
    ) if data.key?(:embeds)
end

#channel_idDiscorb::Snowflake (readonly)

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

Returns:



316
317
318
# File 'lib/discorb/gateway_events.rb', line 316

def channel_id
  @channel_id
end

#contentString (readonly)

Returns The new content of the message.

Returns:

  • (String)

    The new content of the message.



320
321
322
# File 'lib/discorb/gateway_events.rb', line 320

def content
  @content
end

#embedsArray<Discorb::Embed> (readonly)

Returns The embeds in the message.

Returns:



331
332
333
# File 'lib/discorb/gateway_events.rb', line 331

def embeds
  @embeds
end

#guildnil, 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.



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/discorb/gateway_events.rb', line 340

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.from_hash(a) } if data.key?(
    :attachments
  )
  @embeds =
    (
      if data[:embeds]
        data[:embeds].map { |e| Embed.from_hash(e) }
      else
        []
      end
    ) if data.key?(:embeds)
end

#guild_idDiscorb::Snowflake (readonly)

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

Returns:



318
319
320
# File 'lib/discorb/gateway_events.rb', line 318

def guild_id
  @guild_id
end

#idDiscorb::Snowflake (readonly)

Returns The ID of the message.

Returns:



314
315
316
# File 'lib/discorb/gateway_events.rb', line 314

def id
  @id
end

#mention_everyoneBoolean (readonly)

Returns Whether the message pings @everyone.

Returns:

  • (Boolean)

    Whether the message pings @everyone.



324
325
326
# File 'lib/discorb/gateway_events.rb', line 324

def mention_everyone
  @mention_everyone
end

#mention_rolesnil, 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.



327
328
329
# File 'lib/discorb/gateway_events.rb', line 327

def mention_roles
  @mention_roles
end

#timestampTime (readonly)

Returns The time the message was edited.

Returns:

  • (Time)

    The time the message was edited.



322
323
324
# File 'lib/discorb/gateway_events.rb', line 322

def timestamp
  @timestamp
end

Instance Method Details

#fetch_messageAsync::Task<Discorb::Message>

Fetch the message.

Returns:



381
382
383
# File 'lib/discorb/gateway_events.rb', line 381

def fetch_message
  Async { channel.fetch_message(@id).wait }
end