Class: DiscordRDA::MessageDeleteEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/discord_rda/event/base.rb

Instance Attribute Summary

Attributes inherited from Event

#data, #shard_id, #timestamp, #type

Instance Method Summary collapse

Methods inherited from Event

#created_at, #inspect, #to_h

Constructor Details

#initialize(data, shard_id:) ⇒ MessageDeleteEvent

Returns a new instance of MessageDeleteEvent.



552
553
554
# File 'lib/discord_rda/event/base.rb', line 552

def initialize(data, shard_id:)
  super('MESSAGE_DELETE', data, shard_id: shard_id)
end

Instance Method Details

#authorObject



579
580
581
# File 'lib/discord_rda/event/base.rb', line 579

def author
  @author ||= User.new(@data['author']) if @data['author']
end

#channel_idObject



560
561
562
# File 'lib/discord_rda/event/base.rb', line 560

def channel_id
  @data['channel_id']
end

#contentObject



583
584
585
# File 'lib/discord_rda/event/base.rb', line 583

def content
  @data['content']
end

#dm?Boolean

Returns:

  • (Boolean)


591
592
593
# File 'lib/discord_rda/event/base.rb', line 591

def dm?
  guild_id.nil?
end

#guild?Boolean

Returns:

  • (Boolean)


587
588
589
# File 'lib/discord_rda/event/base.rb', line 587

def guild?
  !guild_id.nil?
end

#guild_idObject



564
565
566
# File 'lib/discord_rda/event/base.rb', line 564

def guild_id
  @data['guild_id']
end

#jump_urlObject



595
596
597
598
599
600
601
# File 'lib/discord_rda/event/base.rb', line 595

def jump_url
  if guild_id
    "https://discord.com/channels/#{guild_id}/#{channel_id}/#{message_id}"
  else
    "https://discord.com/channels/@me/#{channel_id}/#{message_id}"
  end
end

#messageObject



568
569
570
571
572
573
574
575
576
577
# File 'lib/discord_rda/event/base.rb', line 568

def message
  @message ||= begin
    # Try to reconstruct partial message from available data
    if @data['author'] || @data['content'] || @data['embeds']
      Message.new(@data.merge('id' => message_id, 'deleted' => true))
    else
      nil
    end
  end
end

#message_idObject



556
557
558
# File 'lib/discord_rda/event/base.rb', line 556

def message_id
  @data['id']
end