-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathFunctions.lua
More file actions
109 lines (91 loc) · 3.37 KB
/
Functions.lua
File metadata and controls
109 lines (91 loc) · 3.37 KB
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
-- Additional help: @ActualMasterOogway
-- \\ Services // --
local MarketplaceService = game:GetService("MarketplaceService")
local HttpService = game:GetService("HttpService")
-- \\ Variables // --
local Module = {}
-- \\ Functions // --
local function timestampToMillis(timestamp: string | number | DateTime): number
return
(typeof(timestamp) == "string" and DateTime.fromIsoDate(timestamp).UnixTimestampMillis)
or (typeof(timestamp) == "number" and timestamp)
or timestamp.UnixTimestampMillis
end
-- \\ Main // --
Module.Require = function(s: string): any?
local content = s
if s:lower():sub(1, 4) == "http" then
content = game:HttpGet(s)
elseif isfile(s) then
content = readfile(s)
end
local func, err = loadstring(content)
if not func then
error(debug.traceback("Failed to load module:\n"..s.."\nError: "..err))
end
return func()
end
Module.LoadCustomAsset = function(url: string): string?
if getcustomasset then
if url:lower():sub(1, 4) == "http" then
local fileName = `temp_{tick()}.txt`
local _, result = pcall(function()
writefile(fileName, game:HttpGet(url))
return getcustomasset(fileName, true)
end)
if isfile(fileName) then
delfile(fileName)
end
return result
elseif isfile(url) then
return getcustomasset(url, true)
end
else
warn("Executor doesn't support 'getcustomasset', rbxassetid only.")
end
if url:find("rbxassetid") or tonumber(url) then
return "rbxassetid://"..url:match("%d+")
end
error(debug.traceback("Failed to load custom asset for:\n"..url))
end
Module.LoadCustomInstance = function(url: string): Instance?
local success, result = pcall(function()
return game:GetObjects(Module.LoadCustomAsset(url))[1]
end)
return success and result or nil
end
Module.GetGameLastUpdate = function(): DateTime
return DateTime.fromIsoDate(MarketplaceService:GetProductInfo(game.PlaceId).Updated)
end
Module.HasGameUpdated = function(timestamp: string | number | DateTime): boolean
local millis = timestampToMillis(timestamp)
if millis then
return millis < Module.GetGameLastUpdate().UnixTimestampMillis
end
return false
end
Module.GetGitLastUpdate = function(owner: string, repo: string, filePath: string): DateTime
local url = `https://api.github.com/repos/{owner}/{repo}/commits?per_page=1&path={filePath}`
local success, result = pcall(HttpService.JSONDecode, HttpService, game:HttpGet(url))
if not success then
error(debug.traceback("Failed to get last commit for:\n"..url))
end
return DateTime.fromIsoDate(result[1].commit.committer.date)
end
Module.HasGitUpdated = function(owner: string, repo: string, filePath: string, timestamp: string | number | DateTime): boolean
local millis = timestampToMillis(timestamp)
if millis then
return millis < Module.GetGitLastUpdate(owner, repo, filePath).UnixTimestampMillis
end
return false
end
Module.TruncateNumber = function(num: number, decimals: number): number
local shift = 10 ^ (decimals and math.max(decimals, 0) or 0)
return num * shift // 1 / shift
end
for name, func in next, Module do
if typeof(func) == "function" then
getgenv()[name] = func
end
end
return Module