Advertisement
_DudeWhat_

mcdiscordbot Client code

Nov 22nd, 2022 (edited)
1,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. local function getCode(socket)
  2.     socket.send("getcode")
  3.     local timeout = 5
  4.     local message, isboolean = socket.receive(timeout)
  5.     if not message then error("Socket server did not respond within "..timeout.." seconds!") end
  6.  
  7.     local execute, reason = loadstring(message)
  8.     if not execute then error("Could not load server code: "..reason) end
  9.     return execute
  10. end
  11.  
  12. local function runRemoteCode(url)
  13.     print("Connecting to the socket server...")
  14.     local socket, reason = http.websocket(url)
  15.     if not socket then error("Socket server could not be reached: "..reason) end
  16.     print("Connection successful!")
  17.     local status, execute = pcall(getCode, socket)
  18.     if not status then
  19.         socket.send("error="..execute)
  20.         socket.close()
  21.         error("Failed to receive the code: "..execute)
  22.     end
  23.     socket.close()
  24.  
  25.     local status, message = pcall(execute)
  26.     if not status then error("Code execution failed: "..message) end
  27. end
  28.  
  29. local function main()
  30.     local status, message = pcall(runRemoteCode, "wss://mcdiscordbot.cnml.de")
  31.     if not status then
  32.         print("Failed to run remote code: "..message)
  33.     end
  34.  
  35.     local waittime = 5
  36.     print("Waiting "..waittime.." seconds to reconnect!")
  37.     sleep(waittime)
  38. end
  39.  
  40. while true do main() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement