Advertisement
Oleshe

Angela (chat_box)

Feb 3rd, 2023 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | Source Code | 0 0
  1. fs = require('filesystem')
  2. chat = require('component').chat_box
  3. event = require('event')
  4. cmp = require('component')
  5. isNetwork = false
  6. args = {}
  7. function getRealTime(e123q)
  8. local handel = io.open("/time", "w")
  9. handel:close()
  10. local timestamp = fs.lastModified("/time") / 1000 + 4
  11. return timestamp
  12. end
  13. function answer()
  14. if isNetwork == true then
  15. _, _, _, _, _, e1,e2 = event.pull('modem_message')
  16. if e1 == 'chat_message' then
  17. return e2
  18. end
  19. else
  20. _,_,_,message = event.pull('chat_message')
  21. return message
  22. end
  23. end
  24. function say(message)
  25. if isNetwork == false then
  26. chat.say(message)
  27. else
  28. modem.broadcast(port,'tosay',message)
  29. end
  30. end
  31. local a = io.open('/timestamp.dat','r')
  32. local time = tonumber(a:read())
  33. a:close()
  34. print(getRealTime())
  35. print(time)
  36. if os.date('%d',getRealTime()) > os.date('%d',time) then
  37. a = io.open('/timestamp.dat',"w")
  38. a:write(getRealTime())
  39. a:close()
  40. print('Просмотрю обновление...')
  41. args[1] = 'get' args[2] = 'fKAgn16d' args[3] = '/tmp/Angela_version.dat'
  42. os.execute('/bin/pastebin.lua')
  43. local a = io.open('/usr/version.dat','r')
  44. curversion = a:read()
  45. a:close()
  46. local a = io.open('/tmp/Angela_version.dat','r')
  47. actversion = a:read()
  48. a:close()
  49. if tonumber(curversion) < tonumber(actversion) then
  50. say('Нашла обновление. Устанавливаю.')
  51. args[2] = 'MaBDZ6j4' args[3] = '/home/chat_box'
  52. os.execute('/bin/pastebin.lua')
  53. a = io.open('/usr/version.dat',"w")
  54. a:write(actversion)
  55. a:close()
  56. require('computer').shutdown(true)
  57. else
  58. require('term').clear()
  59. end
  60. fs.remove('/tmp/Angela_version.dat')
  61. end
  62. while true do
  63. e1 = answer()
  64. tbl = {}
  65. if type(e1) == 'string' then
  66. for part in string.gmatch(e1,"[^ ]+") do
  67. table.insert(tbl, part)
  68. end
  69. if tbl[1] == '!' then
  70. if tbl[2] == 'network' then
  71. if cmp.isAvailable('modem') == true then
  72. if isNetwork == false then
  73. say('Какой бы вы предпочли порт?')
  74. port = tonumber(answer())
  75. modem = cmp.modem
  76. modem.open(port)
  77. isNetwork = true
  78. else
  79. isNetworl = false
  80. modem.close(port) port = nil
  81. end
  82. else
  83. say('Вам нужна беспроводная плата.')
  84. end
  85. else
  86. args= {}
  87. for i = 3,#tbl do
  88. table.insert(args,tbl[i])
  89. end
  90. say('Запускаю программу по пути: /home/'..tbl[2])
  91. ifsucces, reason = pcall(function() end)
  92. os.execute('/home/'..tbl[2])
  93. if ifsucces == false or ifsucces == nil then
  94. say(reason)
  95. print('err')
  96. end
  97. end end end
  98. end
  99. -- ! внимание германия, к этой программе еще прилагается add который добавляет файл к функций компонента, сейчас надобности его сюда монтировать нету.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement