Advertisement
programcreator

Aware

Mar 18th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. --[[
  2.     The Aware Project
  3.     by Creator
  4.     for TheOS
  5. ]]--
  6. --[[
  7.     First I am doing the mechanics of the program, afterwards I will do the GUI
  8. ]]--
  9.  
  10. --GUI
  11. --if _G.Interact == nil then os.loadAPI("TheOS/API/Interact") end
  12. --local gui = Interact.Initialize()
  13.  
  14. --Variables--
  15. local input = {}
  16. local Commands = {}
  17. local path = "TheOS/Programs/Aware.app/"
  18. --Functions--
  19.  
  20.  
  21. function split(str,sep)
  22.     local buffer = {}
  23.     for token in str:gmatch(sep) do
  24.         buffer[#buffer+1] = token
  25.     end
  26.     return buffer
  27. end
  28.  
  29. function getData()
  30.     local var = http.get("https://raw.githubusercontent.com/TheOnlyCreator/Aware/master/Test/Test")
  31.     print(var.readAll())
  32.     os.pullEvent()
  33.     error()
  34. end
  35.  
  36. local function readFile(_path)
  37.     local file = fs.open(_path,"r")
  38.     local data = file.readAll()
  39.     file.close()
  40.     return data
  41. end
  42.  
  43. function filter()
  44.    
  45. end
  46.  
  47. function redirect(word)
  48.     print("Your word is "..word)
  49.     oneWordCommand(word)
  50. end
  51.  
  52. function respond(arg)
  53.     print(_G[arg][math.random(1,#_G[arg])])
  54. end
  55.  
  56. function oneWordCommand(word)
  57.     if Commands[word] ~= nil then
  58.         local func = loadstring(Commands[word])
  59.         func()
  60.     else
  61.         local firstLetter = string.sub(word,1,1)
  62.         print(firstLetter)
  63.         local fromWeb = http.get("https://raw.githubusercontent.com/TheOnlyCreator/Aware/master/Actions/"..firstLetter)
  64.         local buffer = fromWeb.readAll()
  65.         local tableFromWeb = textutils.unserialize(buffer)
  66.         print(tableFromWeb[word])
  67.         local func = loadstring(tableFromWeb[word])
  68.         func()
  69.     end
  70. end
  71.  
  72. function main()
  73.     print("I am listening...")
  74.     local buffer = read()
  75.     input = split(buffer,"[^%s]+")
  76.     for i,v in pairs(input) do
  77.         input[i] = string.lower(v)
  78.     end
  79.     for i,v in pairs(input) do
  80.         print(v)
  81.     end
  82.     if #input == 1 then
  83.         oneWordCommand(input[1])
  84.     else
  85.    
  86.     end
  87. end
  88.  
  89.  
  90. --Code--
  91. local buffer = readFile(path.."Commands")
  92. Commands = textutils.unserialize(buffer)
  93.  
  94. term.setCursorPos(1,1)
  95. term.setBackgroundColor(colors.black)
  96. term.setTextColor(colors.white)
  97. term.clear()
  98.  
  99. while true do
  100.     main()
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement