-
Notifications
You must be signed in to change notification settings - Fork 145
/
Snowflake.lua
63 lines (51 loc) · 1.56 KB
/
Snowflake.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--[=[
@c Snowflake x Container
@t abc
@d Defines the base methods and/or properties for all Discord objects that have
a Snowflake ID.
]=]
local Date = require('utils/Date')
local Container = require('containers/abstract/Container')
local Snowflake, get = require('class')('Snowflake', Container)
function Snowflake:__init(data, parent)
Container.__init(self, data, parent)
end
--[=[
@m __hash
@r string
@d Returns `Snowflake.id`
]=]
function Snowflake:__hash()
return self._id
end
--[=[
@m getDate
@t mem
@r Date
@d Returns a unique Date object that represents when the object was created by Discord.
Equivalent to `Date.fromSnowflake(Snowflake.id)`
]=]
function Snowflake:getDate()
return Date.fromSnowflake(self._id)
end
--[=[@p id string The Snowflake ID that can be used to identify the object. This is guaranteed to
be unique except in cases where an object shares the ID of its parent.]=]
function get.id(self)
return self._id
end
--[=[@p createdAt number The Unix time in seconds at which this object was created by Discord. Additional
decimal points may be present, though only the first 3 (milliseconds) should be
considered accurate.
Equivalent to `Date.parseSnowflake(Snowflake.id)`.
]=]
function get.createdAt(self)
return Date.parseSnowflake(self._id)
end
--[=[@p timestamp string The date and time at which this object was created by Discord, represented as
an ISO 8601 string plus microseconds when available.
Equivalent to `Date.fromSnowflake(Snowflake.id):toISO()`.
]=]
function get.timestamp(self)
return Date.fromSnowflake(self._id):toISO()
end
return Snowflake