SHARE
TWEET

gcapi

a guest Jan 26th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.    
  3.             --*--*--*--*--*--*--*--*--*--*--*--*--*--*--   
  4.             --*                GCAPI                 *--
  5.             --*     https://pastebin.com/0uAaAcrW    *--
  6.             --*            by: GravityCube           *--
  7.             --*--*--*--*--*--*--*--*--*--*--*--*--*--*--
  8.  
  9.            
  10.     Changelog:
  11.         1.0.0 First release
  12.         1.1.0 Image displayer for monitors added and bugs in the economy fixed
  13.         1.2.0 Tracker of players and chatSpy added, a custom http.get was added and global peripheral.find.
  14.         1.3.0 New listener, chatEvents and local admins for selling programs!
  15.         1.4.0 Various bugs fixed (repited chatEvents, and rgb api changed). Added version changelog and getVersion()
  16.         1.5.0 table.contains added
  17.             1.5.1 ChatEvent Listener little fix
  18.             1.5.2 Split function modified (self) and getChar added
  19.             1.5.3 getCenter added and centered of monitors fixed
  20.             1.5.4 getCenter now supports number and string in the #2 argument
  21.             1.5.5 Added some default "URLs" to the images
  22.             1.5.6 URL Alias updated
  23.             1.5.7 Added password for unfiltered tracker (akaElite request)
  24.         1.6.0 New method for tracking and some minor modifications.
  25.             1.6.1 Some minor changes and bugs fixed
  26.         1.7.0 New method gcapi.customMonitorWrite()
  27.             1.7.1 Added table.isEmpty
  28.             1.7.2 New admin (Freecss).
  29.         1.8.0 New method printAvatar()
  30.        
  31. --]]
  32. --------------------------------------------
  33. -->               Version                <--
  34. --------------------------------------------
  35. local debugAPI = false
  36.  
  37. local version = "1.8.0"
  38.  
  39. print("GCAPI Version: " .. version)
  40.  
  41. function getVersion()
  42.     return version
  43. end
  44. --------------------------------------------
  45. -->              URL ALIAS               <--
  46. --------------------------------------------
  47. local urlAlias = {
  48.     ["emx"] = "http://bmo.emx.cl/logo.jpg",
  49.     ["cl"] = "http://craftersland.net/images/logo.png",
  50.     ["deadpool"] = "http://pixelartmaker.com/art/de17950892c0026.png"
  51. }
  52. --------------------------------------------
  53. -->                Tools                 <--
  54. --------------------------------------------
  55.  
  56. local charToColor = {["0"]=0, ["1"]= 1,["2"]= 2, ["3"]=3, ["4"]=4, ["5"]=5, ["6"]=6, ["7"]=7, ["8"]=8, ["9"]=9, ["a"]=10 ,["b"]=11, ["c"]=12, ["d"]=13, ["e"]=14, ["f"]=15}
  57. function customMonitorWrite(mon, text)
  58.     local xi, yi = mon.getCursorPos()
  59.     local chars = {}
  60.     for i = 1, string.len(text) do
  61.         local c = text:sub(i,i)
  62.         table.insert(chars, c)
  63.     end
  64.    
  65.     --charToColor["g"] = mon.getBackgroundColor()
  66.     local isNumber = false
  67.     for i=1, #chars, 1 do
  68.         local c = chars[i]
  69.         if c == "&" and charToColor[chars[i+1]] then
  70.             color = 2^chars[i+1]
  71.             mon.setBackgroundColor(color)
  72.             isNumber = true
  73.         else
  74.             if not isNumber then
  75.                 mon.write(c)
  76.             end
  77.             isNumber = false
  78.         end
  79.     end
  80. end
  81.  
  82.  
  83. function verifyVar(rawVar, varType)
  84.     verifyVar(varType, "string")
  85.     if type(rawVar) ~= varType then
  86.         error( "bad argument (expected " .. varType .. ", got " .. type( rawVar ) .. ")", 2 )
  87.     end
  88. end
  89.  
  90. -- RANDOM STRING
  91. local charset = {}
  92. -- qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890
  93. for i = 48,  57 do table.insert(charset, string.char(i)) end
  94. for i = 65,  90 do table.insert(charset, string.char(i)) end
  95. for i = 97, 122 do table.insert(charset, string.char(i)) end
  96.  
  97. math.randomseed(os.time()*100)
  98. function randomString(length)
  99.     if length > 0 then
  100.         return string.random(length - 1) .. charset[math.random(1, #charset)]
  101.     else
  102.         return ""
  103.     end
  104. end
  105. string.random = randomString
  106. --END RANDOM STRING
  107.  
  108. function getRandom(minValue, maxValue)
  109.     return math.random(minValue, maxValue)
  110. end
  111.  
  112. --peripheral.find() in Tekkit
  113. function findPeripheral(pType)
  114.     local pList = {}
  115.     for _,pName in pairs(peripheral.getNames()) do
  116.         if peripheral.getType(pName) == pType then
  117.             table.insert(pList, peripheral.wrap(pName))
  118.         end
  119.     end
  120.     return unpack(pList)
  121. end
  122. peripheral.find = findPeripheral
  123.  
  124. --Wipe table "t"
  125. function wipeTable(t)
  126.     local listForDeletion = {}
  127.     for k,v in pairs(t) do
  128.         table.insert(listForDeletion, k)
  129.     end
  130.    
  131.     for _,i in pairs(listForDeletion) do
  132.         t[i] = nil
  133.     end
  134. end
  135. table.wipe = wipeTable
  136.  
  137. --Split string
  138. function split(self, delimiter)
  139.     result = {};
  140.     for match in (self..delimiter):gmatch("(.-)"..delimiter) do
  141.         table.insert(result, match);
  142.     end
  143.     return result;
  144. end
  145. string.split = split
  146.  
  147. string.getChar = function (self, nVar)
  148.     if type(nVar) ~= "number" then
  149.         error( "bad argument #2 (expected number, got " .. type( nVar ) .. ")")
  150.     else
  151.         return self:sub(nVar, nVar)
  152.     end
  153. end
  154.  
  155. table.isEmpty = function(self)
  156.     for k,v in pairs(self) do
  157.         return true
  158.     end
  159.     return false
  160. end
  161.  
  162. table.contains = function (self, eVar)
  163.     for k,v in pairs(self) do
  164.         if v == eVar then
  165.             return true
  166.         end
  167.     end
  168.     return false
  169. end
  170.  
  171. --Print to a file and term (message, dir(optional) )
  172. function printLog(line, dir)
  173.     if line == nil then
  174.         return nil
  175.     end
  176.     if dir == nil then
  177.         dir = "/log"
  178.     end
  179.     line = line
  180.     print(line)
  181.    
  182.     file = fs.open(dir,"a")
  183.     file.writeLine(line)
  184.     file.close()
  185. end
  186.  
  187. --Are items equal? Ignoring quantity
  188. function equalItems(item1, item2)
  189.     if item1 == nil or item2 == nil then
  190.         return false
  191.     end
  192.     for k,v in pairs(item1) do
  193.         if k ~= qty then
  194.             if item2[k] ~= v then
  195.                 return false
  196.             end
  197.         end
  198.     end
  199.     return true
  200. end
  201.  
  202. --Get number of lines file
  203. function getNumberOfLinesFile(filePath)
  204.     if not fs.exists(filePath) then
  205.         print("[GCAPI] File not found")
  206.         return 0
  207.     end
  208.     file = fs.open(filePath, "r")
  209.     if file then
  210.         local i = 0
  211.         while file.readLine() do
  212.             i = i + 1
  213.         end
  214.         file.close()
  215.         return i
  216.     end
  217.     return 0
  218. end
  219.  
  220. function getListFromFile(filePath)
  221.     local list = {}
  222.     if not fs.exists(filePath) then
  223.         saveListToFile(filePath, list)
  224.         return list
  225.     end
  226.     local file = fs.open(filePath,"r")
  227.     local data = file.readAll()
  228.     file.close()
  229.     list = textutils.unserialize(data)
  230.     if textutils.unserialize(data) == nil then
  231.         list = {}
  232.     end
  233.     return list
  234. end
  235.  
  236. function saveListToFile(filePath, list)
  237.     file = fs.open(filePath,"w")
  238.     file.write(textutils.serialize(list))
  239.     file.close()
  240. end
  241.  
  242. string.starts = function (self,Start)
  243.    return string.sub(self,1,string.len(Start))==Start
  244. end
  245.  
  246. function getCenter(f, varP)
  247.     if not varP then
  248.         varP = 0
  249.     end
  250.    
  251.     local lengthOfVar = 0
  252.     if type(varP) == "number" then
  253.         lengthOfVar = varP
  254.     elseif type(varP) == "string" then
  255.         lengthOfVar = string.len(varP)
  256.     else
  257.         error("For function gcapi.getCenter expected number or string in argument #2")
  258.     end
  259.    
  260.     if (f - string.len(varP) % 2) == 0 then
  261.         return math.floor((f - lengthOfVar)/2)
  262.     end
  263.    
  264.     return math.floor((f - lengthOfVar)/2)+1
  265.    
  266. end
  267.  
  268. --------------------------------------------
  269. -->          Custom Http Request         <--
  270. -->    http.get with timeout variable    <--
  271. --------------------------------------------
  272.  
  273. function http.getStringWithTimeout(url, headers, timeout)
  274.     if timeout == nil then
  275.         local response = http.get(url, headers)
  276.         local responseString = response.readAll()
  277.         response.close()
  278.         return responseString
  279.     end
  280.    
  281.     --seconds to ticks
  282.     timeout = timeout*20
  283.    
  284.     http.request(url, nil, headers)
  285.    
  286.     local requesting = true
  287.    
  288.     local localReloj = 0
  289.     local nextTimeEventID = os.startTimer(0.1)
  290.     while requesting do
  291.        
  292.         --Wait for event.
  293.         tEvent = {os.pullEvent()}
  294.        
  295.         if "timer" == tEvent[1] then
  296.             if tEvent[2] == nextTimeEventID then
  297.                 if timeout < localReloj then
  298.                     return nil
  299.                 end
  300.                 localReloj = localReloj + 2
  301.                 nextTimeEventID = os.startTimer(0.1)
  302.             end
  303.         else
  304.             --Success.
  305.             if tEvent[1] == "http_success" and url == tEvent[2] then
  306.                 local response = tEvent[3]
  307.                 local responseString = response.readAll()
  308.                 response.close()
  309.                 return responseString
  310.             end
  311.             --Failure
  312.             if tEvent[1] == "http_failure" and url == tEvent[2] then
  313.                 return nil
  314.             end
  315.            
  316.             nextTimeEventID = os.startTimer(0.1)
  317.         end
  318.        
  319.     end
  320. end
  321.  
  322.  
  323. --------------------------------------------
  324. -->             ImageDisplay             <--
  325. -->                                      <--
  326. -->              IMPORTANT:              <--
  327. -->  The API server get bugged sometimes <--
  328. -->  so I had to make a timeout http.get <--
  329. --------------------------------------------
  330.  
  331. -- ** Display Image from URL **
  332.  
  333. -- Example:
  334. -- url = http://www.image.com/image.jpg
  335. -- glassesPeripheral = peripheral.wrap(glassesName) [Optional]
  336. -- maxSize = 10 (10 max of height and weight) [Optional]
  337.  
  338. -- NOTE: If you want the image to be send to only 1 player use
  339. -- peripheral.wrap(glassesName).getUserSurface(playerName)
  340. -- instead of peripheral.wrap(glassesName)
  341.  
  342. function displayImageFromURL(url, glassesPeripheral, maxSize, xo, yo)
  343.    
  344.     local filePath, ok, err = getImagePathFromURL(url, maxSize)
  345.     if not ok then
  346.         return false, err
  347.     end
  348.    
  349.     displayImageFromFile(filePath, glassesPeripheral, xo, yo)
  350.     fs.delete(filePath)
  351.    
  352.     return true
  353. end
  354.  
  355. -- ** Display Image from Rule34 **
  356.  
  357. -- Example:
  358. -- tag = random (just 1)
  359. -- glassesPeripheral = peripheral.wrap(glassesName) [Optional]
  360. -- maxSize = 10 (10 max of height and weight) [Optional]
  361.  
  362. -- NOTE: If you want the image to be send to only 1 player use
  363. -- peripheral.wrap(glassesName).getUserSurface(playerName)
  364. -- instead of peripheral.wrap(glassesName)
  365.  
  366. function displayImageFromRule34(tag, glassesPeripheral, maxSize, xo, yo)
  367.     url, err = getURLfromRule34(tag)
  368.     if url == nil then
  369.         return false, err
  370.     end
  371.     return displayImageFromURL(url, glassesPeripheral, maxSize, xo, yo)
  372.     end
  373.  
  374. function getURLfromRule34(tag)
  375.     if tag == nil then
  376.         tag = "random"
  377.     end
  378.    
  379.     local dataWeb = http.get("http://bmo.emx.cl/rule34CC.php?tag=" .. tag).readAll()
  380.     if not dataWeb then
  381.         err = "[GCAPI] Tag not found"
  382.         print(err)
  383.         return nil, err
  384.     end
  385.    
  386.     return dataWeb
  387. end
  388.  
  389. function getGlasses(glassesPeripheral)
  390.     if glassesPeripheral == nil then
  391.         return peripheral.find("openperipheral_glassesbridge")
  392.     end
  393.     return glassesPeripheral
  394. end
  395.  
  396. -- file = fs.open("imagen","r")
  397. -- glassesPeripheral = peripheral.wrap(glassesName) [Optional]
  398. function displayImageFromFile(filePath, glassesPeripheral, xo, yo)
  399.    
  400.     if xo == nil then
  401.         xo = 1
  402.     end
  403.     if yo == nil then
  404.         yo = 1
  405.     end
  406.    
  407.     numberLines = getNumberOfLinesFile(filePath)
  408.     file = fs.open(filePath, "r")
  409.    
  410.     gb = getGlasses(glassesPeripheral) 
  411.     if gb == nil then
  412.         error("[GCAPI] Glasses peripheral not found")
  413.     end
  414.    
  415.     for i=1,numberLines,1 do
  416.         linea = file.readLine(i)
  417.         lineaQ = {}
  418.         lineaQ = split(linea,",")
  419.         for x,color in pairs(lineaQ) do
  420.             hcolor = assert(loadstring("return "..color))()
  421.             gb.addBox(x+xo,i+yo,1,1,hcolor,1)
  422.         end
  423.     end
  424.     file.close()
  425. end
  426.  
  427. function getImagePathFromURL(url, maxSize, max_x, max_y, forMonitor, filePath)
  428.    
  429.     if filePath == nil then
  430.         filePath = 'gcAPIImage'
  431.     end
  432.  
  433.     if url == nil then
  434.         err = '[GCAPI] No URL for image'
  435.         print(err)
  436.         return nil, false, err
  437.     end
  438.    
  439.     --DELETE SAVED IMAGE
  440.     if url == "none" then
  441.         fs.delete(filePath)
  442.     end
  443.    
  444.     --URL ALIAS
  445.     if urlAlias[url] then
  446.         url = urlAlias[url]
  447.     end
  448.    
  449.     extraParameters = ""
  450.     if maxSize ~= nil and tonumber(maxSize) then
  451.         extraParameters = extraParameters .. '&max_size=' .. maxSize
  452.     end
  453.    
  454.     if max_x ~= nil and tonumber(max_x) then
  455.         extraParameters = extraParameters .. '&max_x=' .. max_x
  456.     end
  457.    
  458.     if max_y ~= nil and tonumber(max_y) then
  459.         extraParameters = extraParameters .. '&max_y=' .. max_y
  460.     end
  461.    
  462.     script = "imageCC"
  463.    
  464.     if forMonitor then
  465.         script = "monitorImageCC"
  466.     end
  467.    
  468.     local dataWeb = http.getStringWithTimeout("http://bmo.emx.cl/" .. script .. ".php?url=" .. url .. extraParameters, nil, 3)
  469.     if not dataWeb then
  470.         err = "[GCAPI] Server error or timeout"
  471.         print(err)
  472.         return nil, false, err
  473.     end
  474.    
  475.     if #dataWeb < 30 then
  476.         err = "[GCAPI] " .. dataWeb
  477.         print(err)
  478.         return nil, false, err
  479.     end
  480.    
  481.     fs.delete(filePath)
  482.    
  483.     f = fs.open(filePath, "w")
  484.     f.write(dataWeb)
  485.     f.close()
  486.    
  487.     return filePath, true, nil
  488.    
  489. end
  490.  
  491. --------------------------------------------
  492. -->             ImageDisplay for         <--
  493. -->                 monitors             <--
  494. --------------------------------------------
  495. function getMonitor(monSelected)
  496.     if monSelected == nil then
  497.         return peripheral.find("monitor")
  498.     end
  499.     return monSelected
  500. end
  501. function printImageFromURL(url, monSelected, centered)
  502.    
  503.     mon = getMonitor(monSelected)
  504.    
  505.     if mon == nil then
  506.         error("[GCAPI] Monitor not found")
  507.     end
  508.    
  509.     mon.setTextScale(0.5)
  510.     mon.clear()
  511.     local max_x, max_y = mon.getSize()
  512.    
  513.     local filePath, ok, err = getImagePathFromURL(url, nil, max_x, max_y, true)
  514.     if not ok then
  515.         return false, err
  516.     end
  517.  
  518.     return printImageFromFile(filePath, mon, centered, true)
  519. end
  520.  
  521. function printAvatar(mon, player_name, x, y, max_side)
  522.     local xo = x
  523.     local yo = y
  524.    
  525.     local filePath, ok, err = getImagePathFromURL("https://minotar.net/avatar/" .. player_name .. "/"..max_side, nil, max_side, max_side, true)
  526.     if not ok then
  527.         return false, err
  528.     end
  529.    
  530.     numberLines = getNumberOfLinesFile(filePath)
  531.     local file = fs.open(filePath, "r")
  532.     for i=1,numberLines,1 do
  533.         linea = file.readLine(i)
  534.         lineaQ = {}
  535.         lineaQ = split(linea,",")
  536.         for x,colorSet in pairs(lineaQ) do
  537.             colors0 = split(colorSet,"-")
  538.             r = tonumber(colors0[1])
  539.             g = tonumber(colors0[2])
  540.             b = tonumber(colors0[3])
  541.            
  542.             if r and g and b then
  543.                 hcolor = colors.fromRGB(r, g, b)
  544.                 mon.setBackgroundColour(hcolor)
  545.                 mon.setCursorPos(x+xo,i+yo)
  546.                 mon.write(" ")
  547.             end
  548.         end
  549.     end
  550.     file.close()
  551.    
  552.     return true
  553. end
  554.  
  555. function printImageFromFile(filePath, monSelected, centered, monSetup)
  556.    
  557.     mon = monSelected
  558.    
  559.     if monSetup == nil or monSetup == false then
  560.         mon = getMonitor(monSelected)
  561.         if mon == nil then
  562.             error("[GCAPI] Monitor not found")
  563.         end
  564.     end
  565.    
  566.     mon.setTextScale(0.5)
  567.     mon.clear()
  568.     local max_x, max_y = mon.getSize()
  569.  
  570.     numberLines = getNumberOfLinesFile(filePath)
  571.    
  572.     xo = 0
  573.     yo = 0
  574.    
  575.     if centered and numberLines > 0 then
  576.         file = fs.open(filePath, "r")
  577.         real_x = #(split(file.readLine(1), ","))
  578.         file.close()
  579.         xo = getCenter(max_x, real_x)
  580.         yo = getCenter(max_y, numberLines)
  581.     end
  582.    
  583.    
  584.     file = fs.open(filePath, "r")
  585.     for i=1,numberLines,1 do
  586.         linea = file.readLine(i)
  587.         lineaQ = {}
  588.         lineaQ = split(linea,",")
  589.         for x,colorSet in pairs(lineaQ) do
  590.             colors0 = split(colorSet,"-")
  591.             r = tonumber(colors0[1])
  592.             g = tonumber(colors0[2])
  593.             b = tonumber(colors0[3])
  594.            
  595.             if r and g and b then
  596.                 hcolor = colors.fromRGB(r, g, b)
  597.                 mon.setBackgroundColour(hcolor)
  598.                 mon.setCursorPos(x+xo,i+yo)
  599.                 mon.write(" ")
  600.             end
  601.         end
  602.     end
  603.     file.close()
  604.    
  605.     return true
  606. end
  607.  
  608. --------------------------------------------
  609. -->             ImageDisplay for         <--
  610. -->            chunks of monitors        <--
  611. --------------------------------------------
  612. local chunksHeight = 0
  613. local chunksWidth = 0
  614. monitors = {}
  615.  
  616. function printPixel(x,y,color)
  617.    
  618. end
  619.  
  620.  
  621. --------------------------------------------
  622. -->            Tracker of players        <--
  623. -->          Just for craftersland       <--
  624. -->                  DYNMAP              <--
  625. --------------------------------------------
  626. function getPosPlayer(player, dataPlayers)
  627.     if player == nil or player == "" then
  628.         err = "User not found"
  629.         print("[GCAPI] " .. err)
  630.         return nil, false, err
  631.     end
  632.    
  633.     player = string.lower(player)
  634.    
  635.     if not dataPlayers then
  636.         dataPlayers, ok, err = getPosPlayers()
  637.     end
  638.    
  639.     for i,dataPlayer in pairs(dataPlayers) do
  640.         user = string.lower(dataPlayer["name"])
  641.         if string.match(user, player) then
  642.             return dataPlayer, true, nil
  643.         end
  644.     end
  645.    
  646.     err = "User not found"
  647.     return nil, false, err
  648. end
  649.  
  650. function getPosPlayers(password)
  651.     local url = "http://bmo.emx.cl/dynmapPos.php"
  652.     if password then
  653.         url = url .. "?password=" .. password
  654.     end
  655.     local dataWeb = http.get(url)
  656.     local dataPlayers = textutils.unserialize(dataWeb.readAll())
  657.     dataWeb.close()
  658.    
  659.     if not dataWeb then
  660.         return nil, false, "[GCAPI] Server Error"
  661.     end
  662.    
  663.     if dataPlayers["error"] ~= nil then
  664.         return nil, false, dataPlayers["error"]
  665.     end
  666.    
  667.     return dataPlayers, true, nil
  668. end
  669.  
  670. function getClosePlayers(user, range)
  671.     local url = "http://bmo.emx.cl/closePlayers.php?user=" .. user .. "&range=" .. range
  672.    
  673.     local dataWeb = http.get(url)
  674.     local closePlayers = textutils.unserialize(dataWeb.readAll())
  675.     dataWeb.close()
  676.    
  677.     if not dataWeb then
  678.         return nil, false, "[GCAPI] Server Error"
  679.     end
  680.    
  681.     if closePlayers["error"] ~= nil then
  682.         return nil, false, closePlayers["error"]
  683.     end
  684.    
  685.     return closePlayers, true, nil
  686. end
  687. --------------------------------------------
  688. -->            Chat tracker for          <--
  689. -->              Craftersland            <--
  690. --------------------------------------------
  691.  
  692. function getChat()
  693.     dataWeb = http.get("http://bmo.emx.cl/chatSpy.php")
  694.     dataChat = textutils.unserialize(dataWeb.readAll())
  695.     dataWeb.close()
  696.    
  697.     if not dataWeb then
  698.         return nil, false, "[GCAPI] Server Error"
  699.     end
  700.    
  701.     return dataChat, true, nil
  702. end
  703.  
  704.  
  705. --------------------------------------------
  706. -->                Economy               <--
  707. -->                                      <--
  708. -->         This is saved every use      <--
  709. -->           for safety purposes.       <--
  710. --------------------------------------------
  711.  
  712. function getMoney(player)
  713.     list = getListFromFile("/disk/economy")
  714.    
  715.     player = string.lower(player)
  716.    
  717.     for name,amount in pairs(list) do
  718.         if name == player then
  719.             return amount
  720.         end
  721.     end
  722.     setMoney(player, 0)
  723.     return 0
  724. end
  725.  
  726. function setMoney(player, amount)
  727.    
  728.     player = string.lower(player)
  729.    
  730.     list = getListFromFile("/disk/economy")
  731.    
  732.     fs.delete("/disk/economy")
  733.    
  734.     list[player]=amount
  735.    
  736.     saveListToFile("/disk/economy", list)
  737. end
  738.  
  739. function withdraw(player, amount)  
  740.     player = string.lower(player)
  741.    
  742.     if getMoney(player) < amount then
  743.         return false
  744.     end
  745.    
  746.     setMoney(player, (getMoney(player)-amount))
  747.     return true
  748. end
  749.  
  750. function addMoney(player, money)
  751.    
  752.     player = string.lower(player)
  753.    
  754.     setMoney(player,getMoney(player)+money)
  755. end
  756. --------------------------------------------
  757. -->          Admins for selling          <--
  758. --------------------------------------------
  759. admins = {"GravityCube", "Archmaestro", "Lancellot", "Freecss"}
  760. function hasPermissions(player, globalAdmins)
  761.     if globalAdmins == nil then
  762.         globalAdmins = true
  763.     end
  764.     for _,user in pairs(getAdmins(globalAdmins)) do
  765.         if user == player then
  766.             return true
  767.         end
  768.     end
  769.     return false
  770. end
  771.  
  772. function getAdmins(globalAdmins)
  773.     localAdmins = {}
  774.     if fs.exists("admins") then
  775.         localAdmins = getListFromFile("admins")
  776.     end
  777.    
  778.     if globalAdmins then
  779.         for _,admin in pairs(admins) do
  780.             table.insert(localAdmins, admin)
  781.         end
  782.     end
  783.    
  784.     return localAdmins
  785. end
  786. --------------------------------------------
  787. -->              EventHanlder            <--
  788. --------------------------------------------
  789. if not lastID then
  790.     lastID = 0
  791. end
  792. function startChatEventQueue()
  793.     while true do
  794.         chatData, ok, err = getChat()
  795.         if ok then
  796.             lastIDTemp = lastID
  797.             for i=1, 10, 1 do
  798.                 data = chatData[i]
  799.                 if data ~= nil then
  800.                     id = data["id"]
  801.                     if id > lastID then
  802.                         if id > lastIDTemp then
  803.                             lastIDTemp = id
  804.                         end
  805.                        
  806.                         player = data["name"]
  807.                         command = data["message"]
  808.                        
  809.                         if command ~= nil and string.starts(command, "!") then
  810.                             command = string.sub(command, 2)
  811.                             lastID = lastIDTemp
  812.                             os.queueEvent("chatEvent", player, command)
  813.                         end
  814.                     end    
  815.                 end
  816.             end
  817.             lastID = lastIDTemp
  818.         end
  819.         sleep(1)
  820.     end
  821. end
  822.  
  823.  
  824. --*--*--*--*--*--*--*--*--*--*--*--*--*--*--
  825. --*             RBG TO COLOUR            *--
  826. --*          by CrazedProgrammer         *--
  827. --*    (Used in the printImageFromURL)   *--
  828. --*   https://pastebin.com/BCSWghjR/rgb  *--
  829. --*--*--*--*--*--*--*--*--*--*--*--*--*--*--
  830. local hex = {"F0F0F0", "F2B233", "E57FD8", "99B2F2", "DEDE6C", "7FCC19", "F2B2CC", "4C4C4C", "999999", "4C99B2", "B266E5", "3366CC", "7F664C", "57A64E", "CC4C4C", "191919"}
  831. local rgb = {}
  832. for i=1,16,1 do
  833.   rgb[i] = {tonumber(string.sub(hex[i],1, 2), 16), tonumber(string.sub(hex[i],3, 4), 16), tonumber(string.sub(hex[i], 5, 6), 16)}
  834. end
  835.  
  836. colors.fromRGB = function (r, g, b)
  837.   local dist = 1e100
  838.   local d = 1e100
  839.   local color = -1
  840.   for i=1,16,1 do
  841.     d = math.sqrt((math.max(rgb[i][1], r) - math.min(rgb[i][1], r)) ^ 2 + (math.max(rgb[i][2], g) - math.min(rgb[i][2], g)) ^ 2 + (math.max(rgb[i][3], b) - math.min(rgb[i][3], b)) ^ 2)
  842.     if d < dist then
  843.       dist = d
  844.       color = i - 1
  845.     end
  846.   end
  847.   return 2 ^ color
  848. end
  849.  
  850. colours.fromRGB = colors.fromRGB
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top