Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit c6c85df

Browse files
seperatet lib's
1 parent f6c34e4 commit c6c85df

File tree

8 files changed

+342
-113
lines changed

8 files changed

+342
-113
lines changed

Diff for: .github/workflows/lstore-put.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Publish lStore package
22
on:
3+
workflow_dispatch:
34
push:
45
branches:
56
- main
@@ -18,7 +19,7 @@ jobs:
1819
mv client/youcube.lua client/main.lua
1920
2021
- name: Publish Package
21-
uses: Commandcracker/lstore-put@v1
22+
uses: Commandcracker/lstore-put@v2
2223
with:
2324
username: ${{ secrets.LSTORE_USERNAME }}
2425
password: ${{ secrets.LSTORE_PASSWORD }}

Diff for: asyncapi.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
asyncapi: 2.4.0
22
info:
33
title: YouCube
4-
version: 1.0.0
4+
version: 0.0.poc0
55
description: |
66
Documentation for YouCube's backend API.
77

Diff for: client/lib/numberformatter.lua

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--[[
2+
_ _ _ _ _ _ ___ ____ ____
3+
|\ | | | |\/| |__] |___ |__/
4+
| \| |__| | | |__] |___ | \
5+
____ ____ ____ _ _ ____ ___ ___ ____ ____
6+
|___ | | |__/ |\/| |__| | | |___ |__/
7+
| |__| | \ | | | | | | |___ | \
8+
9+
Github Repository: https://github.com/Commandcracker/YouCube
10+
License: GPL-3.0
11+
Libary Version: 1.0.0
12+
]]
13+
14+
local NumberFormatter = {}
15+
-- https://devforum.roblox.com/t/how-can-i-turn-a-number-to-a-shorter-number-i-dont-know-how-to-explain-click-to-understand-3/649496/3
16+
17+
local Suffixes = { "k", "M", "B", "T", "qd", "Qn", "sx", "Sp", "O", "N", "de", "Ud", "DD", "tdD", "qdD", "QnD", "sxD",
18+
"SpD", "OcD", "NvD", "Vgn", "UVg", "DVg", "TVg", "qtV", "QnV", "SeV", "SPG", "OVG", "NVG", "TGN", "UTG", "DTG",
19+
"tsTG", "qtTG", "QnTG", "ssTG", "SpTG", "OcTG", "NoTG", "QdDR", "uQDR", "dQDR", "tQDR", "qdQDR", "QnQDR", "sxQDR",
20+
"SpQDR", "OQDDr", "NQDDr", "qQGNT", "uQGNT", "dQGNT", "tQGNT", "qdQGNT", "QnQGNT", "sxQGNT", "SpQGNT", "OQQGNT",
21+
"NQQGNT", "SXGNTL" }
22+
23+
function NumberFormatter.compact(number)
24+
local Negative = number < 0
25+
number = math.abs(number)
26+
27+
local Paired = false
28+
for i in pairs(Suffixes) do
29+
if not (number >= 10 ^ (3 * i)) then
30+
number = number / 10 ^ (3 * (i - 1))
31+
local isComplex = string.find(tostring(number), ".") and string.sub(tostring(number), 4, 4) ~= "."
32+
number = string.sub(tostring(number), 1, isComplex and 4 or 3) .. (Suffixes[i - 1] or "")
33+
Paired = true
34+
break
35+
end
36+
end
37+
if not Paired then
38+
local Rounded = math.floor(number)
39+
number = tostring(Rounded)
40+
end
41+
if Negative then
42+
return "-" .. number
43+
end
44+
return number -- returns 1.0k for example
45+
end
46+
47+
function NumberFormatter.abbreviate(number)
48+
local left, num, right = string.match(number, '^([^%d]*%d)(%d*)(.-)$')
49+
return left .. num:reverse():gsub('(%d%d%d)', '%1,'):reverse() .. right -- returns for example 1,000, it gets every 3 zeros and adds a comma
50+
end
51+
52+
return NumberFormatter

Diff for: client/lib/youcubeapi.lua

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
--[[
2+
_ _ ____ _ _ ____ _ _ ___ ____ ____ ___ _
3+
\_/ | | | | | | | |__] |___ |__| |__] |
4+
| |__| |__| |___ |__| |__] |___ | | | |
5+
6+
Github Repository: https://github.com/Commandcracker/YouCube
7+
License: GPL-3.0
8+
9+
Lib Version: 0.0.poc0
10+
API Version: 0.0.poc0 (https://commandcracker.github.io/YouCube/)
11+
]]
12+
13+
local YouCubeAPI = {}
14+
15+
function YouCubeAPI.new(websocket)
16+
return setmetatable({
17+
websocket = websocket,
18+
}, { __index = YouCubeAPI })
19+
end
20+
21+
local servers = {
22+
"ws://localhost:5000",
23+
"ws://oxygen.knijn.one:5000", -- By EmmaKnijn, Contact EmmaKnijn#0043 on Discord if this doesn't work
24+
"wss://youcube.onrender.com" -- By Commandcracker
25+
}
26+
27+
if settings then
28+
local server = settings.get("youcube.server")
29+
if server then
30+
table.insert(servers, 1, server)
31+
end
32+
end
33+
34+
function YouCubeAPI:detect_bestest_server()
35+
for i, server in pairs(servers) do
36+
local websocket, websocket_error = http.websocket(server)
37+
38+
if websocket ~= false then
39+
term.write("Using the YouCube server: ")
40+
term.setTextColor(colors.blue)
41+
print(server)
42+
term.setTextColor(colors.white)
43+
self.websocket = websocket
44+
break
45+
elseif i == #servers then
46+
error(websocket_error)
47+
end
48+
49+
end
50+
end
51+
52+
function YouCubeAPI:get_chunk(chunkindex, id)
53+
self.websocket.send(textutils.serialiseJSON({
54+
["action"] = "get_chunk",
55+
["chunkindex"] = chunkindex,
56+
["id"] = id
57+
}))
58+
end
59+
60+
function YouCubeAPI:request_media(url)
61+
--local status, retval = pcall(self.websocket.send, textutils.serialiseJSON({
62+
self.websocket.send(textutils.serialiseJSON({
63+
["action"] = "request_media",
64+
["url"] = url
65+
}))
66+
67+
--if not status then
68+
-- print("Lost connection to server -> Reconnection ...")
69+
-- self:detect_bestest_server()
70+
-- self:request_media(url)
71+
--end
72+
end
73+
74+
--[[
75+
function YouCubeAPI:handshake()
76+
local version = "0.0.poc0"
77+
self.websocket.send(textutils.serialiseJSON({
78+
["action"] = "handshake",
79+
["version"] = version
80+
}))
81+
end
82+
]]
83+
84+
return YouCubeAPI

Diff for: client/youcube.lua

+38-109
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,64 @@
11
--[[
2-
_ _ _ _ _ _ ___ ____ ____
3-
|\ | | | |\/| |__] |___ |__/
4-
| \| |__| | | |__] |___ | \
5-
____ ____ ____ _ _ ____ ___ ___ ____ ____
6-
|___ | | |__/ |\/| |__| | | |___ |__/
7-
| |__| | \ | | | | | | |___ | \
8-
]]
9-
10-
local NumberFormatter = {}
11-
-- https://devforum.roblox.com/t/how-can-i-turn-a-number-to-a-shorter-number-i-dont-know-how-to-explain-click-to-understand-3/649496/3
12-
13-
local Suffixes = { "k", "M", "B", "T", "qd", "Qn", "sx", "Sp", "O", "N", "de", "Ud", "DD", "tdD", "qdD", "QnD", "sxD",
14-
"SpD", "OcD", "NvD", "Vgn", "UVg", "DVg", "TVg", "qtV", "QnV", "SeV", "SPG", "OVG", "NVG", "TGN", "UTG", "DTG",
15-
"tsTG", "qtTG", "QnTG", "ssTG", "SpTG", "OcTG", "NoTG", "QdDR", "uQDR", "dQDR", "tQDR", "qdQDR", "QnQDR", "sxQDR",
16-
"SpQDR", "OQDDr", "NQDDr", "qQGNT", "uQGNT", "dQGNT", "tQGNT", "qdQGNT", "QnQGNT", "sxQGNT", "SpQGNT", "OQQGNT",
17-
"NQQGNT", "SXGNTL" }
18-
19-
function NumberFormatter.compact(number)
20-
local Negative = number < 0
21-
number = math.abs(number)
22-
23-
local Paired = false
24-
for i in pairs(Suffixes) do
25-
if not (number >= 10 ^ (3 * i)) then
26-
number = number / 10 ^ (3 * (i - 1))
27-
local isComplex = string.find(tostring(number), ".") and string.sub(tostring(number), 4, 4) ~= "."
28-
number = string.sub(tostring(number), 1, isComplex and 4 or 3) .. (Suffixes[i - 1] or "")
29-
Paired = true
30-
break
31-
end
32-
end
33-
if not Paired then
34-
local Rounded = math.floor(number)
35-
number = tostring(Rounded)
36-
end
37-
if Negative then
38-
return "-" .. number
39-
end
40-
return number -- returns 1.0k for example
41-
end
2+
_ _ ____ _ _ ____ _ _ ___ ____
3+
\_/ | | | | | | | |__] |___
4+
| |__| |__| |___ |__| |__] |___
425
43-
function NumberFormatter.abbreviate(number)
44-
local left, num, right = string.match(number, '^([^%d]*%d)(%d*)(.-)$')
45-
return left .. num:reverse():gsub('(%d%d%d)', '%1,'):reverse() .. right -- returns for example 1,000, it gets every 3 zeros and adds a comma
46-
end
47-
48-
--[[
49-
_ _ ____ _ _ ____ _ _ ___ ____ ____ ___ _
50-
\_/ | | | | | | | |__] |___ |__| |__] |
51-
| |__| |__| |___ |__| |__] |___ | | | |
6+
Github Repository: https://github.com/Commandcracker/YouCube
7+
License: GPL-3.0
8+
Client Version: 0.0.poc0
529
]]
5310

54-
local YouCubeAPI = {}
55-
56-
function YouCubeAPI.new(websocket)
57-
return setmetatable({
58-
websocket = websocket,
59-
}, { __index = YouCubeAPI })
60-
end
61-
62-
local servers = {
63-
"ws://localhost:5000",
64-
"ws://oxygen.knijn.one:5000", -- By EmmaKnijn, Contact EmmaKnijn#0043 on Discord if this doesn't work
65-
"wss://youcube.onrender.com" -- By Commandcracker
66-
}
11+
-- Libraries - OpenLibrarieLoader v1.0.0 --
6712

68-
if settings then
69-
local server = settings.get("youcube.server")
70-
if server then
71-
table.insert(servers, 1, server)
13+
local function is_lib(Table, Item)
14+
for key, value in ipairs(Table) do
15+
if value == Item or value .. ".lua" == Item then
16+
return true, value
17+
end
7218
end
19+
return false
7320
end
7421

75-
function YouCubeAPI:detect_bestest_server()
76-
for i, server in pairs(servers) do
77-
local websocket, websocket_error = http.websocket(server)
78-
79-
if websocket ~= false then
80-
term.write("Using the YouCube server: ")
81-
term.setTextColor(colors.blue)
82-
print(server)
83-
term.setTextColor(colors.white)
84-
self.websocket = websocket
85-
break
86-
elseif i == #servers then
87-
error(websocket_error)
22+
local libs = { "youcubeapi", "numberformatter" }
23+
local lib_paths = { ".", "./lib", "./apis", "./modules", "/", "/lib", "/apis", "/modules" }
24+
25+
for i, path in pairs(lib_paths) do
26+
if fs.exists(path) then
27+
for _i, file_name in pairs(fs.list(path)) do
28+
local found, lib = is_lib(libs, file_name)
29+
if found and libs[lib] == nil then
30+
if require then
31+
libs[lib] = require(path .. "/" .. file_name:gsub(".lua", ""))
32+
else
33+
libs[lib] = dofile(path .. "/" .. file_name)
34+
end
35+
end
8836
end
89-
9037
end
9138
end
9239

93-
function YouCubeAPI:get_chunk(chunkindex, id)
94-
self.websocket.send(textutils.serialiseJSON({
95-
["action"] = "get_chunk",
96-
["chunkindex"] = chunkindex,
97-
["id"] = id
98-
}))
99-
end
100-
101-
function YouCubeAPI:request_media(url)
102-
--local status, retval = pcall(self.websocket.send, textutils.serialiseJSON({
103-
self.websocket.send(textutils.serialiseJSON({
104-
["action"] = "request_media",
105-
["url"] = url
106-
}))
107-
108-
--if not status then
109-
-- print("Lost connection to server -> Reconnection ...")
110-
-- self:detect_bestest_server()
111-
-- self:request_media(url)
112-
--end
40+
for key, lib in ipairs(libs) do
41+
if libs[lib] == nil then
42+
error("Library \"" .. lib .. "\" not found")
43+
end
11344
end
11445

115-
--[[
116-
_ _ ____ _ _ _ ____ _ _
117-
|\/| |__| | |\ | | | |
118-
| | | | | | \| |___ |___ |
119-
]]
46+
-- CraftOS-PC support --
12047

121-
if periphemu then -- CraftOS-PC
48+
if periphemu then
12249
periphemu.create("top", "speaker")
12350
end
12451

52+
-- main --
53+
12554
local speaker = peripheral.find("speaker")
12655
local tape = peripheral.find("tape_drive")
12756

12857
if speaker == nil and tape == nil then
12958
error("You need a tapedrive or speaker in order to use YouCube!")
13059
end
13160

132-
local youcubeapi = YouCubeAPI.new()
61+
local youcubeapi = libs.youcubeapi.new()
13362
youcubeapi:detect_bestest_server()
13463

13564
-------------------------------
@@ -174,11 +103,11 @@ local function run(url, no_close)
174103
term.setTextColor(colors.white)
175104

176105
if data.like_count then
177-
print("Likes: " .. NumberFormatter.compact(data.like_count))
106+
print("Likes: " .. libs.numberformatter.compact(data.like_count))
178107
end
179108

180109
if data.view_count then
181-
print("Views: " .. NumberFormatter.compact(data.view_count))
110+
print("Views: " .. libs.numberformatter.compact(data.view_count))
182111
end
183112

184113
local x, y = term.getCursorPos()

Diff for: illuaminate.sexp

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,27 @@
88
(at /
99
;; Modifications to make to the linter set. For instance, `+all -var:unused`
1010
;; will enable all warnings but var:unused.
11-
(linters -format:table-trailing -doc:undocumented -var:unused)
11+
(linters -format:table-trailing -doc:undocumented -var:unused -doc:undocumented-arg)
1212

1313
;; Control how the illuaminate linter works.
1414
(lint
1515
;; Modules which may have members which are not documented. Modules within this list are skipped by the `var:unresolved-member` warning.
1616
(dynamic-modules)
1717

1818
;; List of global variables
19-
(globals :max textutils term colors http peripheral periphemu read settings)
19+
(globals :max
20+
textutils
21+
term
22+
colors
23+
http
24+
peripheral
25+
periphemu
26+
read
27+
settings
28+
fs
29+
printError
30+
shell
31+
)
2032

2133
;; Whether tables entries should be separated by a comma (',') or semicolon (';').
2234
(table-separator comma)

0 commit comments

Comments
 (0)