Advertisement
nagoL2015

chatbot

Oct 1st, 2017
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.46 KB | None | 0 0
  1. if fs.exists("password") then
  2.   f = fs.open("password", "r")
  3.   password = f.readAll()
  4. else
  5.   error("Please create a file named 'password' and put your password in it.", 0)
  6. end
  7.  
  8. energyEnabled = true
  9.  
  10. local version = 0.6
  11. local send = 121
  12. local receive = 119
  13.  
  14. os.pullEvent = os.pullEventRaw
  15.  
  16. bannedPlayers = {
  17.     osmarks = true,
  18.     Keanu73 = true,
  19. }
  20.  
  21. cmd = {}
  22. modem = peripheral.find("modem")
  23. modem.open(receive)
  24. file = fs.open("chatlog", fs.exists("chatlog") and "a" or "w")
  25.  
  26. function say(text)
  27.   modem.transmit(send, receive, text)
  28. end
  29.  
  30. function pass()
  31.   local event, p1 = os.pullEvent("key")
  32.   if p1 == 25 then
  33.     sleep(0.1)
  34.     print("Please Enter Password:")
  35.     input = read("*")
  36.     if password == input then
  37.       error("Correct Password", 0)
  38.     else
  39.       os.reboot()
  40.     end
  41.   end
  42. end
  43.  
  44. cmds = { "help", "update", "games", "changelog", "download", "energy" }
  45.  
  46. cmdFunc = {
  47.   help = function()
  48.     say("Here is all of our commands currently:")
  49.     say("+ update - Updates all of our systems to the latest pastebin")
  50.     say("+ games - Shows a list of all the current games on the DLA network and how to install them")
  51.     say("+ changelog - shows the changelog and current version of DLA")
  52.     say("+ download - downloads the programs you want")
  53.     say("+ energy - If enabled, tells you the current level of energy in your energy cells")
  54.   end,
  55.  
  56.   update = function()
  57.     say("updated")
  58.     say("update")
  59.     os.reboot()
  60.   end,
  61.  
  62.   games = function()
  63.     say("Here is our current list of games:")
  64.     say("")
  65.     say("Minesweeper by GopherAtl")
  66.     say("Stacker by KingofGamesYami")
  67.     say("BBTetris by BombBloke")
  68.     say("CCOthello by KingofGamesYami")
  69.     say("KnightsTour by RoD")
  70.     say("SnakeMaze by nitrogenfingers")
  71.     say("MiniatureCraft by Detective_Smith")
  72.     say("BingoCraft by theTanco")
  73.     say("BBCards by BombBloke")
  74.     say("")
  75.     say("To download any of these games simply run the program: pastebin run Vu6niFSr.  To get DLA to send you this file just type the command: + download games [name of the program you want to download] and make sure you have the receive program running.")
  76.   end,
  77.  
  78.   changelog = function()
  79.     say("Current version: "..version)
  80.     say("Changelog:")
  81.     say("")
  82.     say("v0.5:")
  83.     say("Added changelog")
  84.     say("Added games command")
  85.     say("Now supports arguments")
  86.     say("Added downloading feature")
  87.   end,
  88.  
  89.   download = function()
  90.     if cmd[2] == "game" then
  91.       if cmd[3] == "Minesweeper" then
  92.         say("pastebin get nsKrHTbN minesweeper")
  93.         say("Sent")
  94.       elseif cmd[3] == "Stacker" then
  95.         say("pastebin get HC1MjHVq stacker")
  96.         say("Sent")
  97.       elseif cmd[3] == "BBTetris" then
  98.         say("pastebin get nKQZwgtv bbtetris")
  99.         say("Sent")
  100.       elseif cmd[3] == "CCOthello" then
  101.         say("pastebin get rMeh1Kag ccothello")
  102.         say("Sent")
  103.       elseif cmd[3] == "KnightsTour" then
  104.         say("pastebin get G5FqHanB knightstour")
  105.         say("Sent")
  106.       elseif cmd[3] == "SnakeMaze" then
  107.         say("pastebin run 9cdEwcZB")
  108.         say("Sent")
  109.       elseif cmd[3] == "MiniatureCraft" then
  110.         say("pastebin run FgAggvy1|pastebin run Q2TsPJfh")
  111.         say("Sent")
  112.       elseif cmd[3] == "BingoCraft" then
  113.         say("pastebin get 3v130WkD game|pastebin get ngA8d9PQ restartgame")
  114.         say("Sent")
  115.       elseif cmd[3] == "BBCards" then
  116.         say("pastebin get T7a1Yp7S bbcards|pastebin get 0TC3qyGV card")
  117.         say("Sent")
  118.       end
  119.     end
  120.   end,
  121.  
  122.   energy = function()
  123.     if energyEnabled == true then
  124.       if fs.exists("cells") then
  125.         totalStored = 0
  126.         totalCapacity = 0
  127.  
  128.         file = fs.open("cells", "r")
  129.         table = textutils.unserialize(file.readAll())
  130.         file.close()
  131.         for i = table[1], #table + (table[1] - 1) do
  132.           cellNum = table[i]
  133.           cell = peripheral.wrap("minecraft:thermalexpansion_storage_cell_"..i)
  134.           energy = cell.getMetadata()
  135.           stored = energy.energy.stored
  136.           capacity = energy.energy.capacity
  137.           totalStored = totalStored + stored
  138.           totalCapacity = totalCapacity + capacity
  139.           powerPercentage = totalStored / totalCapacity * 100
  140.           modem.transmit(send, receive, powerPercentage.."%")
  141.         end
  142.       else
  143.         say("Please create a file named 'cells' and write a table of the numbers of your energy cells in it.")
  144.       end
  145.     else
  146.       say("The energy command is not enabled, please contact the person who is hosting the DLA to turn it on.")
  147.     end
  148.   end,
  149. }
  150.  
  151. function mainLoop()
  152.   while true do
  153.     local _, _, _, _, info = os.pullEvent("modem_message")
  154.  
  155.     if info ~= nil then
  156.       text = info[2]
  157.       usr = info[1]
  158.  
  159.       if usr ~= nil and text ~= nil then
  160.         file.writeLine(usr..": "..text)
  161.         file.flush()
  162.       end
  163.  
  164.       chat_string = string.sub(text, 1, (-string.len(text)) + 1)
  165.       s = string.sub(text, 3)
  166.  
  167.       for chat in s:gmatch("%w+") do
  168.         table.insert(cmd, chat)
  169.       end
  170.  
  171.       if not bannedPlayers[usr] and chat_string == "+ " then
  172.         for k, v in pairs(cmds) do
  173.           if v == cmd[1] then
  174.             cmdFunc[cmd[1]]()
  175.           end
  176.         end
  177.       elseif bannedPlayers[usr] and chat_string == "+ " then
  178.         say("Your request shall not be processed "..usr)
  179.       end
  180.       for i = 1, #cmd do
  181.         cmd[i] = nil
  182.       end
  183.     end
  184.   end
  185. end
  186.  
  187. parallel.waitForAll(mainLoop, pass)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement