summaryrefslogtreecommitdiff
path: root/listener.lua
blob: 1419f996f0d5b92ca8f09fdd5ab700553721b3d0 (plain)
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
local pm = require'pm'

local ws = assert(http.websocket("wss://citrons.xyz/ws-echo/rebecca"))
function main()
	print("listening")
	while true do
		local msg = ws.receive()
		local parsed = assert(textutils.unserializeJSON(msg))
		if parsed.msg then
			print("got msg",parsed.msg)
			-- more sophisticated cmds later, maybe
			local pkgname = parsed.msg:gsub("%s","")
			pm.cc()
			pm.dl(pkgname)
			shell.run('bg '..pkgname)
		end
	end
end

local ok, err = pcall(main)
if not ok then
	print(err)
end
ws.close()
print("all done")