Advertisement
Reavik

SkyBot

Jan 16th, 2023 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.42 KB | Gaming | 0 0
  1. -- By Reavik and Player_rs V1.9s
  2.  
  3. local cb = peripheral.find("chatBox")
  4. if cb == nil then print("chatBox no found") end
  5.  
  6. local nameBot = "Eterium Sky"
  7.  
  8. local function Split(s, delimiter)
  9.     local result = {};
  10.     for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
  11.         table.insert(result, match)
  12.     end
  13.     return result
  14. end
  15.  
  16. local function loadTabela()
  17.     local f = fs.open("EteriumSky/priceTable.lua", "r")
  18.     local data = textutils.unserialize(f.readAll())
  19.     f.close()
  20.     return data
  21. end
  22.  
  23. local function sendMessage(msg, player)
  24.     cb.sendMessageToPlayer(msg, player, nameBot)
  25. end
  26.  
  27. local function findItem(str, table)
  28.     local out = {}
  29.     for _, v in pairs(table) do
  30.         if string.find(v.name:lower(), str) then
  31.             out[#out+1] = v
  32.         end
  33.     end
  34.     if #out == 0 then
  35.         return false, {}
  36.     else
  37.         return true, out
  38.     end
  39. end
  40.  
  41. local function _downloadList()
  42.     if not fs.exists("EteriumSky") then
  43.         fs.makeDir("EteriumSky")
  44.     end
  45.     shell.run("wget https://raw.githubusercontent.com/Playerrs/CCrepo/master/EteriumLoja/EteriumTable.lua EteriumSky/priceTable.lua")
  46. end
  47.  
  48. -- Main
  49. if not fs.exists("EteriumSky/priceTable.lua") then _downloadList() end
  50. local tabela = loadTabela()
  51. print("Tudo certo e funcionando!\n["..nameBot.."]")
  52.  
  53. while true do
  54.     local e, player, msg = os.pullEvent("chat")
  55.     print("["..player.."]: "..msg)
  56.     local split_string = Split(msg, " ")
  57.     msg = (split_string[1]):lower()
  58.  
  59.     if msg == "preço" or msg == "preco" or msg == "price" then
  60.         local item
  61.         local stats, result
  62.         if split_string[2] then
  63.             item = split_string[2]:lower()
  64.             stats, result = findItem(item, tabela)
  65.         else
  66.             sendMessage("Para mais informações digit \"sky\" ou \"help\" no chat", player)
  67.         end
  68.  
  69.         if stats then
  70.             for i, v in pairs(result) do
  71.                 sendMessage(("[Tier %s] [%s]:\n %s"):format(v.tier, v.name, v.info), player)
  72.                 sleep(1)
  73.             end
  74.         else
  75.             sendMessage(("[%s] não foi encontrado na tabela\nTente pesquisar por outro nome\nOu calcule o proço baseado nos item usado para o craft\nUse \"help\" para mais informações"):format(item), player)
  76.         end
  77.     end
  78.     if msg == "sky" then
  79.         sendMessage("------------------ [Eterium Sky]\nExiste um delay de 1s entre um comando e outro\nAss: Reavik, Player_rs", player)
  80.     end
  81.     if msg == "help" then
  82.         sendMessage("----------------- [Eterium Sky]\nDigite no chat local os comandos a seguir sem usar /\nprice\ncalc\nsky\nhelp", player)
  83.     end
  84.     -- split_string[1] = calc
  85.     -- split_string[2] = int
  86.     -- split_string[3] = parametro
  87.     -- split_string[4] = int
  88.     if msg == "calc" or msg == "c" then
  89.         if split_string[2] then
  90.             item = split_string[2]:lower()
  91.             stats, result = findItem(item, tabela)
  92.             local error = "[X] Você deve digitar apenas numeros e parametros matematicos"
  93.         if split_string[3] == "+" then
  94.             if tonumber(split_string[2]) and tonumber(split_string[4]) then
  95.                 sendMessage("A soma de "..split_string[2].." mais "..split_string[4].." é ["..tonumber(split_string[2]) + tonumber(split_string[4]).."]", player)
  96.             else
  97.                 sendMessage(error,player)
  98.             end
  99.         end
  100.         if split_string[3] == "-" then
  101.             if tonumber(split_string[2]) and tonumber(split_string[4]) then
  102.                 sendMessage("A subitração de "..split_string[4].." de "..split_string[2].." é ["..tonumber(split_string[2]) - tonumber(split_string[4]).."]", player)
  103.             else
  104.                 sendMessage(error,player)
  105.             end
  106.         end
  107.         if split_string[3] == "/" or split_string[3] == "%" then
  108.             if tonumber(split_string[2]) and tonumber(split_string[4]) then
  109.                 sendMessage("A divisão de "..split_string[2].." por "..split_string[4].." é ["..tonumber(split_string[2]) / tonumber(split_string[4]).."]", player)
  110.             else
  111.                 sendMessage(error,player)
  112.             end
  113.         end
  114.         if split_string[3] == "*" or split_string[3] == "x" then
  115.             if tonumber(split_string[2]) and tonumber(split_string[4]) then
  116.                 sendMessage("A divisão de "..split_string[2].." por "..split_string[4].." é ["..tonumber(split_string[2]) * tonumber(split_string[4]).."]", player)
  117.             else
  118.                 sendMessage(error,player)
  119.             end
  120.         end
  121.         if split_string[3] == "^" then
  122.             if tonumber(split_string[2]) and tonumber(split_string[4]) then
  123.                 sendMessage("A potência de "..split_string[2].." elevado "..split_string[4].." é ["..tonumber(split_string[2]) ^ tonumber(split_string[4]).."]", player)
  124.             else
  125.                 sendMessage(error,player)
  126.             end
  127.         end
  128.         if split_string[2] == "v" then
  129.             if tonumber(split_string[3]) then
  130.                 sendMessage("A raiz quadrada de "..split_string[3].." é ["..math.sqrt(tonumber(split_string[3])).."]", player)
  131.             else
  132.                 sendMessage(error,player)
  133.             end
  134.         end
  135.         else
  136.             sendMessage("Os parametros validos para a calculadora são:\n+ Soma\n- Subtração\n/ % Divisão\n* x Multilicação\n^ Potência\nv Raiz quadrada", player)
  137.         end
  138.         sleep(1)
  139.     end
  140. end
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement