Module: Rubycord::IDObject
- Included in:
- Application, Attachment, AuditLogs::Entry, Channel, Emoji, Integration, Rubycord::Interactions::Message, InviteChannel, InviteServer, Light::Integration, Light::LightProfile, Light::UltraLightServer, Message, Role, Server, User, Webhook
- Defined in:
- lib/rubycord/id_object.rb
Overview
Mixin for objects that have IDs
Instance Attribute Summary collapse
-
#id ⇒ Integer
(also: #resolve_id, #hash)
readonly
The ID which uniquely identifies this object across Discord.
Class Method Summary collapse
-
.synthesise(time) ⇒ Integer
(also: synthesize)
Creates an artificial snowflake at the given point in time.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
ID based comparison.
-
#creation_time ⇒ Time
Estimates the time this object was generated on based on the beginning of the ID.
Instance Attribute Details
#id ⇒ Integer (readonly) Also known as: resolve_id, hash
Returns the ID which uniquely identifies this object across Discord.
5 6 7 |
# File 'lib/rubycord/id_object.rb', line 5 def id @id end |
Class Method Details
.synthesise(time) ⇒ Integer Also known as: synthesize
Creates an artificial snowflake at the given point in time. Useful for comparing against.
28 29 30 31 |
# File 'lib/rubycord/id_object.rb', line 28 def self.synthesise(time) ms = (time.to_f * 1000).to_i (ms - DISCORD_EPOCH) << 22 end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
ID based comparison
10 11 12 |
# File 'lib/rubycord/id_object.rb', line 10 def ==(other) Rubycord.id_compare(@id, other) end |
#creation_time ⇒ Time
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
19 20 21 22 23 |
# File 'lib/rubycord/id_object.rb', line 19 def creation_time # Milliseconds ms = (@id >> 22) + DISCORD_EPOCH Time.at(ms / 1000.0) end |