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.



547
548
549
# File 'lib/discord_rda/event/base.rb', line 547

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

Instance Method Details

#authorObject



574
575
576
# File 'lib/discord_rda/event/base.rb', line 574

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

#channel_idObject



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

def channel_id
  @data['channel_id']
end

#contentObject



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

def content
  @data['content']
end

#dm?Boolean

Returns:

  • (Boolean)


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

def dm?
  guild_id.nil?
end

#guild?Boolean

Returns:

  • (Boolean)


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

def guild?
  !guild_id.nil?
end

#guild_idObject



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

def guild_id
  @data['guild_id']
end

#jump_urlObject



590
591
592
593
594
595
596
# File 'lib/discord_rda/event/base.rb', line 590

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



563
564
565
566
567
568
569
570
571
572
# File 'lib/discord_rda/event/base.rb', line 563

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



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

def message_id
  @data['id']
end