SHOW:
|
|
- or go back to the newest paste.
1 | local uri = "https://discordapp.com/api/webhooks/193796725309441/4Xa8HU1cQiG72gyYC7az7Yfd_UqoE_ydngFswXbNDVjKRCQFPDa5Sidu12TvKa0e6OWO" | |
2 | local intervalSec = 15 | |
3 | function tableHasValue(table, v) | |
4 | for i=1,#table do | |
5 | if table[i] == v then | |
6 | return true | |
7 | end | |
8 | end | |
9 | return false | |
10 | end | |
11 | ||
12 | if not term.isColor() then | |
13 | print("Advanced computer required") | |
14 | error() | |
15 | end | |
16 | ||
17 | local function showError(message) | |
18 | term.setBackgroundColor(colors.black) | |
19 | term.setTextColor(colors.red) | |
20 | term.write(message) | |
21 | term.setBackgroundColor(colors.black) | |
22 | term.setTextColor(colors.white) | |
23 | print() | |
24 | end | |
25 | ||
26 | local function showErrorAndExit(message) | |
27 | showError(message) | |
28 | error() | |
29 | end | |
30 | ||
31 | local camera | |
32 | local cameras = {} | |
33 | local sides = peripheral.getNames() | |
34 | for key,side in pairs(sides) do | |
35 | if peripheral.getType(side) == "warpdriveCamera" then | |
36 | print("Camera found on " .. side) | |
37 | camera = peripheral.wrap(side) | |
38 | table.insert(cameras, peripheral.wrap(side)) | |
39 | --camera.videoChannel("23" + key) | |
40 | end | |
41 | end | |
42 | if camera == nil or camera.isInterfaced() == nil then | |
43 | showErrorAndExit("No camera detected") | |
44 | end | |
45 | ||
46 | local argv = { ... } | |
47 | if #argv ~= 0 then | |
48 | showErrorAndExit("Usage: recognition") | |
49 | end | |
50 | while true do | |
51 | for _, camera in pairs(cameras) do | |
52 | local delay = 0 | |
53 | local count | |
54 | local newFaces = {} | |
55 | local oldFaces = {} | |
56 | repeat | |
57 | count = camera.getResultsCount() | |
58 | os.sleep(0.1) | |
59 | delay = delay + 1 | |
60 | until (count ~= nil and count ~= -1) or delay > 10 | |
61 | ||
62 | if count ~= nil and count > 0 then | |
63 | for i=0, count-1 do | |
64 | local success, type, name, x, y, z, vx, vy, vz = camera.getResult(i) | |
65 | x = math.floor(x * 10) / 10 | |
66 | y = math.floor(y * 10) / 10 | |
67 | z = math.floor(z * 10) / 10 | |
68 | if success then | |
69 | if type == "minecraft:player" then | |
70 | player = "".. name .." @ (" .. x .. " " .. y .. " " .. z .. ")" | |
71 | table.insert(newFaces,player) | |
72 | - | -- print(type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")") |
72 | + | if not tableHasValue(oldFaces, player) then -- not already tracked |
73 | - | if not tableHasValue(oldFaces, player) then |
73 | + | if firstMsgPart then |
74 | - | http.post(uri,"{\"content\":\":camera: ".. camera.videoChannel() .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. "\"}",{['content-type']="application/json"}) |
74 | + | str = str.."**Newly tracked Players:**" |
75 | firstMsgPart = false | |
76 | end | |
77 | str = str.."\n"..so | |
78 | end | |
79 | --print(so) | |
80 | --os.sleep(.5) | |
81 | - | else |
81 | + | -- |
82 | end | |
83 | end | |
84 | ||
85 | ||
86 | firstMsgPart = true | |
87 | for i=1,#oldFaces do | |
88 | if not tableHasValue(newFaces, oldFaces[i]) then -- if a ship was removed | |
89 | if firstMsgPart then | |
90 | str = str.."Lost contact with ships:\n" | |
91 | firstMsgPart = false | |
92 | end | |
93 | str = str..oldFaces[i].."\n" | |
94 | end | |
95 | end | |
96 | --print("\n\n") | |
97 | --print("l3:"..#newShips) | |
98 | if str ~= "" then | |
99 | str = "-------------------------------\n"..str | |
100 | --print("posting update to discord...") | |
101 | local sanitized = "" | |
102 | for j=1,str:len() do | |
103 | if string.find(str:sub(j,j), "\"") or str:sub(j,j):find("\\") then | |
104 | sanitized = sanitized .. "." | |
105 | -- print("removed "..str:sub(j,j)) | |
106 | else | |
107 | sanitized = sanitized .. string.sub(str,j,j) | |
108 | end | |
109 | end | |
110 | --print(sanitized) | |
111 | term.setCursorPos(1,11) | |
112 | term.clearLine() | |
113 | print("Sent Results to HFGR Server.") | |
114 | if sanitized:len() > 1950 then | |
115 | sanitized = sanitized:sub(1,1951).."[..]" | |
116 | end | |
117 | http.post(discordUri, "{\"content\":\""..sanitized:gsub("\n","\\n").."\"}",{['content-type']="application/json"}) | |
118 | end | |
119 | oldFaces = newFaces | |
120 | sleep(intervalSec) | |
121 | end | |
122 | ||
123 | else | |
124 | end | |
125 | else | |
126 | showError("Error " .. type) | |
127 | end | |
128 | end | |
129 | else | |
130 | print("Nothing was found =(") | |
131 | end | |
132 | end | |
133 | oldFaces = newFaces | |
134 | sleep(intervalSec) | |
135 | end |