Class: Discorb::Message::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/discorb/message_meta.rb

Overview

Represents reference of message.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(guild_id, channel_id, message_id, fail_if_not_exists: true) -> Reference

Initialize a new reference.

Parameters:



58
59
60
61
62
63
# File 'lib/discorb/message_meta.rb', line 58

def initialize(guild_id, channel_id, message_id, fail_if_not_exists: true)
  @guild_id = guild_id
  @channel_id = channel_id
  @message_id = message_id
  @fail_if_not_exists = fail_if_not_exists
end

Instance Attribute Details

#channel_id -> Discorb::Snowflake

Returns The channel ID.

Returns:



42
43
44
# File 'lib/discorb/message_meta.rb', line 42

def channel_id
  @channel_id
end

#fail_if_not_exists -> Boolean Also known as: fail_if_not_exists?

Returns Whether fail the request if the message is not found.

Returns:

  • (Boolean)

    Whether fail the request if the message is not found.



46
47
48
# File 'lib/discorb/message_meta.rb', line 46

def fail_if_not_exists
  @fail_if_not_exists
end

#guild_id -> Discorb::Snowflake

Returns The guild ID.

Returns:



40
41
42
# File 'lib/discorb/message_meta.rb', line 40

def guild_id
  @guild_id
end

#message_id -> Discorb::Snowflake

Returns The message ID.

Returns:



44
45
46
# File 'lib/discorb/message_meta.rb', line 44

def message_id
  @message_id
end

Class Method Details

.from_hash(data) -> Discorb::Message::Reference

Initialize a new reference from a hash.

Parameters:

  • data (Hash)

    The hash.

Returns:

See Also:



87
88
89
# File 'lib/discorb/message_meta.rb', line 87

def self.from_hash(data)
  new(data[:guild_id], data[:channel_id], data[:message_id], fail_if_not_exists: data[:fail_if_not_exists])
end

Instance Method Details

#inspect -> Object



91
92
93
# File 'lib/discorb/message_meta.rb', line 91

def inspect
  "#<#{self.class.name} #{@channel_id}/#{@message_id}>"
end

#to_hash -> Hash

Convert the reference to a hash.

Returns:

  • (Hash)

    The hash.



70
71
72
73
74
75
76
77
# File 'lib/discorb/message_meta.rb', line 70

def to_hash
  {
    message_id: @message_id,
    channel_id: @channel_id,
    guild_id: @guild_id,
    fail_if_not_exists: @fail_if_not_exists,
  }
end