module Discordrb::IDObject

Mixin for objects that have IDs

Attributes

hash[R]

@return [Integer] the ID which uniquely identifies this object across Discord.

id[R]

@return [Integer] the ID which uniquely identifies this object across Discord.

resolve_id[R]

@return [Integer] the ID which uniquely identifies this object across Discord.

Public Class Methods

synthesise(time) click to toggle source

Creates an artificial snowflake at the given point in time. Useful for comparing against. @param time [Time] The time the snowflake should represent. @return [Integer] a snowflake with the timestamp data as the given time

# File lib/discordrb/id_object.rb, line 30
def self.synthesise(time)
  ms = (time.to_f * 1000).to_i
  (ms - DISCORD_EPOCH) << 22
end
Also aliased as: synthesize
synthesize(time)
Alias for: synthesise

Public Instance Methods

==(other) click to toggle source

ID based comparison

# File lib/discordrb/id_object.rb, line 12
def ==(other)
  Discordrb.id_compare(@id, other)
end
Also aliased as: eql?
creation_time() click to toggle source

Estimates the time this object was generated on based on the beginning of the ID. This is fairly accurate but shouldn’t be relied on as Discord might change its algorithm at any time @return [Time] when this object was created at

# File lib/discordrb/id_object.rb, line 21
def creation_time
  # Milliseconds
  ms = (@id >> 22) + DISCORD_EPOCH
  Time.at(ms / 1000.0)
end
eql?(other)
Alias for: ==