Advertisement
TwiXon4ik

Логи

Oct 20th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.95 KB | None | 0 0
  1. local component = require("component")
  2. local computer = require("computer")
  3. local term = require("term")
  4. local event = require("event")
  5. local chat = component.chat_box
  6. local gpu = component.gpu
  7. local con = component.me_controller
  8. local serialization = require("serialization")
  9. local unicode = require("unicode")
  10. local shell = require("shell")
  11. local os = require("os")
  12.  
  13. chat.setName("L")
  14. masters = {
  15. ["AlexSavex"] = "AlexSavex",
  16. ["Dima0299"] = "Dima0299",
  17. ["SoriBro"] = "SoriBro",
  18. }
  19.  
  20. craftables = {}
  21. recentCraft = nil
  22.  
  23. function say(msg)
  24. chat.say("§bМЭ§a Ассистент§7: " .. msg)
  25. end
  26.  
  27. function getNumber(item)
  28. local a = con.getItemsInNetwork()
  29. for i = 1,#a do
  30. if isEqual(a[i].label,item) then
  31. return a[i].size, a[i].label
  32. end
  33. end
  34. return "error no such item"
  35. end
  36.  
  37.  
  38. function displayNumber(item)
  39. local num,label = getNumber(item)
  40. if num and label then
  41. say("в царской сокровищнице §d" .. num .. " §9" .. label .. "§7, " .. masters[name])
  42. end
  43. end
  44.  
  45. function displayNumber3(item)
  46. if item == "" or string.len(item) <= 1 then
  47. return true
  48. end
  49. local a = con.getItemsInNetwork()
  50. for i = 1,#a do
  51. if isEqual(a[i].label,item) then
  52. say("в царской сокровищнице §d" .. a[i].size .. " §9" .. a[i].label .. "§7, " .. masters[name])
  53. return true
  54. end
  55. end
  56.  
  57. local results = {}
  58.  
  59. for i = 1,#a do
  60. if string.find(string.lower(a[i].label),string.lower(item)) then
  61. results[a[i].label] = a[i].size
  62. end
  63. end
  64. for k,v in pairs(results) do
  65. say("§9" .. k .. "§7: §d" .. v)
  66. end
  67. end
  68.  
  69. function displayNumber2(item)
  70. if item == "" or string.len(item) <= 1 then
  71. return true
  72. end
  73.  
  74. local a = con.getItemsInNetwork()
  75. local line = ""
  76. local line0 = ""
  77. local lineF = ""
  78. local skip = 0
  79. for i = 1,#a do
  80. if isEqual(a[i].label,item) then
  81. line0 = "§9" .. a[i].label .. "§7: §d" .. a[i].size
  82. skip = i
  83. break
  84. end
  85. end
  86.  
  87. for i = 1,#a do
  88. if i ~= skip then
  89. if string.find(string.lower(a[i].label),string.lower(item)) then
  90. line = line .. "§9" .. a[i].label .. "§7: §d" .. a[i].size .. "§7, "
  91. end
  92. end
  93. end
  94.  
  95.  
  96. if line ~= "" then
  97. line = string.sub(line,0,-3)
  98. if string.len(line) > 1000 then
  99. line = "слишком много результатов"
  100. end
  101. end
  102. if line0 ~= "" then
  103. lineF = line0 .. "§7, " .. line
  104. else
  105. lineF = line
  106. end
  107.  
  108. if lineF ~= ", " and lineF ~= "" then
  109. say(lineF)
  110. end
  111. end
  112.  
  113. function isEqual(item1,item2)
  114. if string.lower(item1) == string.lower(item2) then
  115. return true
  116. else
  117. return false
  118. end
  119. end
  120.  
  121. function assignPBS(msg)
  122. if string.find(msg,"=") ~= nil then
  123. prefix = string.sub(msg,1,string.find(msg,"=")-1)
  124. if string.find(msg,":") ~= nil then
  125. body = string.sub(msg,string.find(msg,"=")+1,string.find(msg,":")-1)
  126. suffix = string.sub(msg,string.find(msg,":")+1)
  127. if suffix == ""
  128. then suffix = nil
  129. end
  130. else
  131. body = string.sub(msg,string.find(msg,"=")+1)
  132. end
  133. else
  134. prefix,body,suffix = nil,nil,nil
  135. end
  136. return prefix, body, suffix
  137. end
  138.  
  139. function isDone()
  140. if recentCraft == nil then
  141. say("ты еще не заказывал крафтов")
  142. return true
  143. end
  144. if recentCraft.isCanceled() == true then
  145. say("последний крафт был отменен")
  146. return true
  147. end
  148. if recentCraft.isDone() == true then
  149. say("последний крафт уже завершен")
  150. else
  151. say("последний крафт еще в прогрессе")
  152. end
  153. end
  154.  
  155. function recalculateCraftables()
  156. say("пересчет таблицы крафтов . . .")
  157. local t = con.getCraftables()
  158. for i = 1,#t do
  159. craftables[i] = t[i].getItemStack().label
  160. end
  161. local f,err = io.open("craftables","w")
  162. if err then
  163. say("не могу открыть файл дампа таблицы, таблица не будет записана")
  164. return true
  165. end
  166. f:write(serialization.serialize(craftables))
  167. f:close()
  168. say("таблица крафтов обновлена")
  169. end
  170.  
  171. function longCraft(item,number)
  172. local ttt = con.getCraftables()
  173. for i = 1,#ttt do
  174. if isEqual(ttt[i].getItemStack().label,item) then
  175. recentCraft = ttt[i].request(number,true)
  176. os.sleep(0.2)
  177. if recentCraft.isCanceled() == false then
  178. say("-заказан крафт §9" .. item .. " §dx" .. number)
  179. else
  180. say("-ошибка, крафт отменен")
  181. end
  182. return true
  183. end
  184. end
  185. say("-нет крафтабельного рецепта для " .. item)
  186. end
  187.  
  188. function pcraft(item,number)
  189. if type(item) ~= "string" or type(number) ~= "number" then
  190. say("неправильная команда для крафта")
  191. return true
  192. end
  193. local t = con.getCraftables()
  194. for i = 1,#craftables do
  195. if isEqual(craftables[i],item) then
  196. if isEqual(t[i].getItemStack().label,item) then
  197. recentCraft = t[i].request(number,true)
  198. os.sleep(0.2)
  199. if recentCraft.isCanceled() == false then
  200. say("заказан крафт §9" .. item .. " §dx" .. number)
  201. else
  202. say("ошибка, крафт отменен")
  203. end
  204. return true
  205. else
  206. longCraft(item,number)
  207. return true
  208. end
  209. end
  210. end
  211. longCraft(item,number)
  212. end
  213.  
  214. function getKeys(table)
  215. local count = 0
  216. for k,v in pairs(table) do
  217. count = count +1
  218. end
  219. return count
  220. end
  221.  
  222. function craft(item,number)
  223. if type(item) ~= "string" or type(number) ~= "number" then
  224. say("неправильная команда для крафта")
  225. return true
  226. end
  227. local t = con.getCraftables()
  228. for i = 1,#craftables do
  229. if isEqual(craftables[i],item) then
  230. if isEqual(t[i].getItemStack().label,item) then
  231. recentCraft = t[i].request(number,true)
  232. os.sleep(0.2)
  233. if recentCraft.isCanceled() == false then
  234. say("заказан крафт §9" .. item .. " §dx" .. number)
  235. else
  236. say("ошибка, крафт отменен")
  237. end
  238. return true
  239. end
  240. end
  241. end
  242.  
  243. local res = {}
  244.  
  245. for i = 1,#craftables do
  246. if string.find(string.lower(craftables[i]),string.lower(item)) then
  247. print(craftables[i])
  248. res[i] = craftables[i]
  249. end
  250. end
  251.  
  252. if getKeys(res) == 1 then
  253. for i,v in pairs(res) do
  254. if isEqual(res[i],t[i].getItemStack().label) then
  255. recentCraft = t[i].request(number,true)
  256. os.sleep(0.2)
  257. if recentCraft.isCanceled() == false then
  258. say("+заказан крафт §9" .. res[i] .. " §dx" .. number)
  259. else
  260. say("+ошибка, крафт отменен")
  261. end
  262. return true
  263. else
  264. say("+проблема с таблицами крафта, рекомендовано пересчитать")
  265. end
  266. end
  267. elseif getKeys(res) == 0 then
  268. say("нет результатов для " .. item)
  269. return true
  270. else
  271. say("найдено §9" .. getKeys(res) .. "§7 результатов, уточни запрос")
  272. return true
  273. end
  274. say("нет крафтабельного рецепта для " .. item)
  275. end
  276.  
  277.  
  278. function checkCraftables()
  279. say("проверка таблиц крафта . . .")
  280. if not craftables then
  281. say("файл таблиц craftables поврежден, обнуление. необходимо пересчитать таблицы")
  282. craftables = {}
  283. return true
  284. end
  285. if #craftables ~= #con.getCraftables() then
  286. say("таблицы крафтов не совпадают по размеру " .. #craftables .. " - " .. #con.getCraftables())
  287. return true
  288. end
  289. local tt = con.getCraftables()
  290. for i = 1,#craftables do
  291. if craftables[i] ~= tt[i].getItemStack().label then
  292. say("таблицы крафтов не совпадают по содержанию")
  293. return true
  294. end
  295. end
  296. say("таблицы крафтов совпадают")
  297. end
  298.  
  299. function cpu()
  300. local busy = 0
  301. local free = 0
  302. local t = con.getCraftingCPUs()
  303. for i = 1,#t do
  304. if t[i].busy == true then
  305. busy = busy +1
  306. else
  307. free = free +1
  308. end
  309. end
  310. say("статус процессоров: §a" .. free .. "§7/§c" .. busy)
  311. end
  312.  
  313. function loadCraftables()
  314. local f,err = io.open("craftables","r")
  315. if err then
  316. say("не могу открыть файл дампа таблицы для чтения")
  317. return true
  318. end
  319. craftables = serialization.unserialize(f:read())
  320. f:close()
  321. say("таблица крафтов инициализирована")
  322. end
  323.  
  324. function paste(text1,text2,text3,text4)
  325. local len = 10-(unicode.len(text1))
  326. if len > 0 then
  327. io.write(string.rep(" ",len))
  328. end
  329. gpu.setForeground(0x00D60D)
  330. io.write(text1)
  331. gpu.setForeground(0xF8C471)
  332. io.write(text2)
  333. gpu.setForeground(0xA747F3)
  334. io.write(text3)
  335. gpu.setForeground(0xF8F9F9)
  336. io.write(" - " .. text4 .. "\n")
  337. gpu.setForeground(0xFFFFFF)
  338. end
  339.  
  340. function memoryUsed()
  341. say("занято оперативной памяти: " .. math.floor((computer.totalMemory()-computer.freeMemory())/1024) .. "KB")
  342. end
  343.  
  344. function scan(pname)
  345. local line = ""
  346. if component.openperipheral_sensor.getPlayerByName(pname) then
  347. local a = component.openperipheral_sensor.getPlayerByName(pname).all()
  348. say("сканирую §9" .. a.name .. "§7 . . .")
  349. say("хп: §9" .. a.living.health .. "/" .. a.living.maxHealth)
  350. say("опыт: §9" .. a.player.experience.level .. "§7 ур. (" .. math.floor(a.player.experience.levelProgress*100) .. "%)")
  351. say("насыщение: §9" .. a.player.foodLevel)
  352. say("взгляд: направление: §9" .. math.floor(a.living.yaw) .. "°§7, угол: §9" .. math.floor(a.living.pitch) .. "°")
  353. if a.player.isCreativeMode == true then
  354. say("у этого пидора §4бескнечные ресы, бля")
  355. end
  356. line = line .. "зелья: §9"
  357. if a.living.potion_effects then
  358. p=a.living.potion_effects
  359. if #p ~= 0 then
  360. for i=1,#p do
  361. line = line .. "§9" .. p[i].effect.name .. "§7 - §9" .. p[i].duration .. "§7 сек, "
  362. end
  363. line = string.sub(line,0,-2)
  364. else line = "зелья: §9нет"
  365. end
  366. end
  367. say(line)
  368. else
  369. say("не вижу " .. pname)
  370. end
  371. end
  372.  
  373. function iscan(pname)
  374. local line = ""
  375. local a = ""
  376. if component.openperipheral_sensor.getPlayerByName(pname) then
  377. a = component.openperipheral_sensor.getPlayerByName(pname).all()
  378. a = a.player.inventory
  379. end
  380. say("§dБроня:")
  381. for i = 40,37,-1 do
  382. if a[i] then
  383. local x = a[i].all()
  384. line = " §9" .. x.display_name
  385. if x.electric then
  386. line = line .. "§7 (" .. math.floor((x.electric.charge/x.electric.maxCharge)*100) .. "%)"
  387. end
  388. say(line)
  389. else
  390. say(" -- ")
  391. end
  392. end
  393. say("§dПанель быстрого доступа:")
  394. for i = 1,9 do
  395. if a[i] then
  396. local x = a[i].all()
  397. line = " §9" .. x.display_name .. "§7: " .. x.qty
  398. if x.electric then
  399. line = line .. "§7 (" .. math.floor((x.electric.charge/x.electric.maxCharge)*100) .. "%)"
  400. end
  401. say(line)
  402. end
  403. end
  404. say("§dИнвентарь:")
  405. for i = 10,36 do
  406. if a[i] then
  407. local x = a[i].all()
  408. line = " §9" .. x.display_name .. "§7: " .. x.qty
  409. if x.electric then
  410. line = line .. " заряд: " .. (x.electric.Charge/x.electric.macCharge)*100 .. "%"
  411. end
  412. say(line)
  413. end
  414. end
  415. end
  416.  
  417. --[[function shellExec()
  418. shell.execute("pastebin get -f Dt0kbk77 assistant.lua")
  419. shell.execute("assistant.lua")
  420. end]]--
  421.  
  422. function restart()
  423. if (nickname == "Astro") then
  424. say("рестарт . . .")
  425. timer = event.timer(3,shellExec)
  426. os.exit()
  427. end
  428. end
  429.  
  430. function printCommands()
  431. paste("=","item","","кол-во предмета в сети (только точное название)")
  432. paste("d=","item","","кол-во предмета в сети (поиск по фильтру)")
  433. paste("dd=","item","","кол-во предмета в сети (поиск по фильтру) - результаты в столбик")
  434. paste("craft=","item",":number","заказ крафта по фильтру (можно писать часть названия)")
  435. paste("pcraft=","item",":number","старая ф-я крафта (длинный поиск по всем предметам, только точное название)")
  436. paste("status=","","","статус последнего заказа")
  437. paste("cpu=","","","статистика занятых и свободных CPU крафта")
  438. paste("recalc=","","","пересчитать таблицу крафта и записать в файл (полезно если меняется конфигурация шаблонов крафта в сети)")
  439. paste("reload=","","","инициализировать таблицу крафта из файла (необязательно, выполняется каждый раз при старте программы)")
  440. paste("check=","","","проверить, соответствует ли текущая таблица крафта в оперативной памяти реальным крафтам МЭ сети")
  441. paste("ram=","","","показать количество занятой оперативной памяти")
  442. --paste("restart=","","","обновить программу через pastebin и перезапустить")
  443. paste("scan=","player","","отсканировать пидрилу")
  444. paste("iscan=","player","","отсканировать его инвентарь")
  445. end
  446.  
  447.  
  448.  
  449. commands = {
  450. [""] = displayNumber,
  451. ["craft"] = craft,
  452. ["pcraft"] = pcraft,
  453. ["status"] = isDone,
  454. ["check"] = checkCraftables,
  455. ["cpu"] = cpu,
  456. ["recalc"] = recalculateCraftables,
  457. ["reload"] = loadCraftables,
  458. ["d"] = displayNumber2,
  459. ["dd"] = displayNumber3,
  460. ["ram"] = memoryUsed,
  461. ["restart"] = restart,
  462. ["scan"] = scan,
  463. ["iscan"] = iscan,
  464. }
  465. --
  466. if timer then
  467. timer.kill(timer)
  468. end
  469. term.clear()
  470. loadCraftables()
  471. printCommands()
  472. local nickname = ""
  473. while true do
  474. _,_,name,msg = event.pull("chat_message")
  475. nickname=name
  476. if masters[name] then
  477. prefix,body,suffix = nil,nil,nil
  478. prefix,body,suffix = assignPBS(msg)
  479. if commands[prefix] then
  480. commands[prefix](body,tonumber(suffix))
  481. end
  482. end
  483. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement