-
Notifications
You must be signed in to change notification settings - Fork 145
/
Activity.lua
157 lines (130 loc) · 4.41 KB
/
Activity.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
--[=[
@c Activity
@d Represents a Discord user's presence data, either an application or streaming
presence or a rich presence. Most if not all properties may be nil.
]=]
local Container = require('containers/abstract/Container')
local format = string.format
local Activity, get = require('class')('Activity', Container)
function Activity:__init(data, parent)
Container.__init(self, data, parent)
return self:_loadMore(data)
end
function Activity:_load(data)
Container._load(self, data)
return self:_loadMore(data)
end
function Activity:_loadMore(data)
local timestamps = data.timestamps
self._start = timestamps and timestamps.start
self._stop = timestamps and timestamps['end'] -- thanks discord
local assets = data.assets
self._small_text = assets and assets.small_text
self._large_text = assets and assets.large_text
self._small_image = assets and assets.small_image
self._large_image = assets and assets.large_image
local party = data.party
self._party_id = party and party.id
self._party_size = party and party.size and party.size[1]
self._party_max = party and party.size and party.size[2]
local emoji = data.emoji
self._emoji_name = emoji and emoji.name
self._emoji_id = emoji and emoji.id
self._emoji_animated = emoji and emoji.animated
end
--[=[
@m __hash
@r string
@d Returns `Activity.parent:__hash()`
]=]
function Activity:__hash()
return self._parent:__hash()
end
--[=[@p start number/nil The Unix timestamp for when this Rich Presence activity was started.]=]
function get.start(self)
return self._start
end
--[=[@p stop number/nil The Unix timestamp for when this Rich Presence activity was stopped.]=]
function get.stop(self)
return self._stop
end
--[=[@p name string/nil The name of the activity in which the user is currently engaged.]=]
function get.name(self)
return self._name
end
--[=[@p type number/nil The user's activity type. See the `activityType`
enumeration for a human-readable representation.]=]
function get.type(self)
return self._type
end
--[=[@p url string/nil The URL for a user's streaming activity.]=]
function get.url(self)
return self._url
end
--[=[@p applicationId string/nil The application id controlling this Rich Presence activity.]=]
function get.applicationId(self)
return self._application_id
end
--[=[@p state string/nil string for the Rich Presence state section.]=]
function get.state(self)
return self._state
end
--[=[@p details string/nil string for the Rich Presence details section.]=]
function get.details(self)
return self._details
end
--[=[@p textSmall string/nil string for the Rich Presence small image text.]=]
function get.textSmall(self)
return self._small_text
end
--[=[@p textLarge string/nil string for the Rich Presence large image text.]=]
function get.textLarge(self)
return self._large_text
end
--[=[@p imageSmall string/nil URL for the Rich Presence small image.]=]
function get.imageSmall(self)
return self._small_image
end
--[=[@p imageLarge string/nil URL for the Rich Presence large image.]=]
function get.imageLarge(self)
return self._large_image
end
--[=[@p partyId string/nil Party id for this Rich Presence.]=]
function get.partyId(self)
return self._party_id
end
--[=[@p partySize number/nil Size of the Rich Presence party.]=]
function get.partySize(self)
return self._party_size
end
--[=[@p partyMax number/nil Max size for the Rich Presence party.]=]
function get.partyMax(self)
return self._party_max
end
--[=[@p emojiId string/nil The ID of the emoji used in this presence if one is
set and if it is a custom emoji.]=]
function get.emojiId(self)
return self._emoji_id
end
--[=[@p emojiName string/nil The name of the emoji used in this presence if one
is set and if it has a custom emoji. This will be the raw string for a standard emoji.]=]
function get.emojiName(self)
return self._emoji_name
end
--[=[@p emojiHash string/nil The discord hash for the emoji used in this presence if one is
set. This will be the raw string for a standard emoji.]=]
function get.emojiHash(self)
if self._emoji_id then
return self._emoji_name .. ':' .. self._emoji_id
else
return self._emoji_name
end
end
--[=[@p emojiURL string/nil string The URL that can be used to view a full
version of the emoji used in this activity if one is set and if it is a custom emoji.]=]
function get.emojiURL(self)
local id = self._emoji_id
local ext = self._emoji_animated and 'gif' or 'png'
return id and format('https://cdn.discordapp.com/emojis/%s.%s', id, ext) or nil
end
return Activity