Class: RubyCord::Message::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycord/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:



61
62
63
64
65
66
# File 'lib/rubycord/message_meta.rb', line 61

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_idRubyCord::Snowflake

Returns The channel ID.

Returns:



45
46
47
# File 'lib/rubycord/message_meta.rb', line 45

def channel_id
  @channel_id
end

#fail_if_not_existsBoolean 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.



49
50
51
# File 'lib/rubycord/message_meta.rb', line 49

def fail_if_not_exists
  @fail_if_not_exists
end

#guild_idRubyCord::Snowflake

Returns The guild ID.

Returns:



43
44
45
# File 'lib/rubycord/message_meta.rb', line 43

def guild_id
  @guild_id
end

#message_idRubyCord::Snowflake

Returns The message ID.

Returns:



47
48
49
# File 'lib/rubycord/message_meta.rb', line 47

def message_id
  @message_id
end

Class Method Details

.from_hash(data) ⇒ RubyCord::Message::Reference

Initialize a new reference from a hash.

Parameters:

  • data (Hash)

    The hash.

Returns:

See Also:



90
91
92
93
94
95
96
97
# File 'lib/rubycord/message_meta.rb', line 90

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

#inspectObject



99
100
101
# File 'lib/rubycord/message_meta.rb', line 99

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

#to_hashHash

Convert the reference to a hash.

Returns:

  • (Hash)

    The hash.



73
74
75
76
77
78
79
80
# File 'lib/rubycord/message_meta.rb', line 73

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