Advertisement
LDDestroier

MCCI (Native Coroutine)

Dec 29th, 2017
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.84 KB | None | 0 0
  1. --[[
  2.   Modular Chatbox Command Interpreter
  3.     Made by LDDestroier
  4.   This version uses native Coroutines API instead of StateMachine.
  5.  
  6.   pastebin get 5tJM4Bf8 mcci  
  7. --]]
  8. local progname = fs.getName(shell.getRunningProgram())
  9. local baseDir = ".mcci" --all other directories are combined with this one, you see
  10. local commandDir = fs.combine(baseDir,"cmd") --a folder
  11. local commandHelpDir = fs.combine(baseDir,"cmdhelp") --a folder
  12. local chatlogDir = fs.combine(baseDir,"chatlog") --a file
  13. local banDir = fs.combine(baseDir,"banlist")
  14. local adminDir = fs.combine(baseDir,"adminlist")
  15. local configDir = fs.combine(baseDir,"config")
  16. local chatEvents = {"chat_message","chatbox_command","chat"}
  17. local _
  18.  
  19. local useMoarPeriphs = (peripheral.find("chatbox_admin") or peripheral.find("chatbox") or peripheral.find("chat_box")) and true or false --either moarperipherals/computronics xor peripherals++
  20.  
  21. if not fs.exists(commandDir) then fs.makeDir(commandDir) end
  22. if not fs.exists(commandHelpDir) then fs.makeDir(commandHelpDir) end
  23.  
  24. local adminUserTable = { --only one who can use admin commands. default values.
  25.     "EldidiStroyrr",
  26.     "Notch",
  27. }
  28. if pairs ~= _G.pairs then
  29.     pairs = function(tbl)
  30.         if type(tbl) ~= "table" then
  31.             error("expected a table here, but got "..type(tbl))
  32.         else
  33.             return _G.pairs(tbl)
  34.         end
  35.     end
  36. end
  37.  
  38. local doRestart = false
  39. local adminUser = function(u)
  40.     if type(u) ~= "string" then return false end
  41.     for a = 1, #adminUserTable do
  42.         if adminUserTable[a]:lower() == u:lower() then
  43.             return true
  44.         end
  45.     end
  46.     return false
  47. end
  48. --[[
  49. local getEvents = function(...)
  50.     local arg = table.pack(...)
  51.     local output
  52.     while true do
  53.         output = {os.pullEvent()}
  54.         for a = 1, #arg do
  55.             if output[1] == arg[a] then
  56.                 return table.unpack(output)
  57.             end
  58.         end
  59.     end
  60. end
  61. --]]
  62. --here's a more experimental getEvents...
  63. getEvents = function(...)
  64.     local arg, funky, output = table.pack(...), {}
  65.     if #arg <= 1 then
  66.         return os.pullEvent(table.unpack(arg))
  67.     else
  68.         for a = 1, #arg do
  69.             funky[a] = function() output = {os.pullEvent(arg[a])} end
  70.         end
  71.         parallel.waitForAny(table.unpack(funky))
  72.         return table.unpack(output)
  73.     end
  74. end
  75.  
  76. local mcci = {
  77.     prefix = "(>",
  78.     ignoreErrors = true,
  79.     mcciLabel = "MCCI",
  80. }
  81.  
  82. local chatbox
  83. local usingAdminChatbox = false
  84. local chatDelay = 0.1 --seconds. regular chatboxes in P+1 will error if you use them too fast
  85. local chatbox = peripheral.find("chatbox_admin") or peripheral.find("chatbox") or peripheral.find("chatBox") or peripheral.find("chat_box")
  86. local cLabel
  87. local setLabel = function(newLabel)
  88.     cLabel = newLabel
  89.     if chatbox.setLabel then
  90.         chatbox.setLabel(newLabel)
  91.     elseif chatbox.setName then
  92.         chatbox.setName(newLabel)
  93.     end
  94. end
  95. if useMoarPeriphs then setLabel(mcci.mcciLabel) end
  96. local SAY = commands.tellraw and function(user,message)
  97.     commands.tellraw("@a",'{"text":"['..cLabel..'] '..message..'"}')
  98. end or chatbox.say
  99. local WHISPER = commands.tellraw and function(user,message)
  100.     commands.tellraw(user,'{"text":"['..cLabel..'] '..message..'"}')
  101. end or chatbox.tell
  102. local parseListenEvent = function(evt)
  103.     return evt[3 - (useMoarPeriphs and 0 or 1)], evt[4 - (useMoarPeriphs and 0 or 1)]
  104. end
  105. local LISTEN = function(username,checkPrefix)
  106.     local evt, user, message
  107.     while true do
  108.         evt = {getEvents(table.unpack(chatEvents))}
  109.         user, message = parseListenEvent(evt)
  110.         if (user == (username or user)) then
  111.             if checkPrefix then
  112.                 if message:sub(1,#tostring(checkPrefix)) == checkPrefix then
  113.                     message = message:sub(#tostring(checkPrefix)+1)
  114.                     break
  115.                 end
  116.             else
  117.                 break
  118.             end
  119.         end
  120.     end
  121.     return user, message
  122. end
  123.  
  124. local checkit = function(check, ...) --checks if the first argument is equal to one of the others
  125.     local list = {...}
  126.     for a = 1, #list do
  127.         if list[a] == check then
  128.             return true
  129.         end
  130.     end
  131.     return false
  132. end
  133.  
  134. local explode = function(div,str)
  135.     if (div=='') then return false end
  136.     local pos,arr = 0,{}
  137.     for st,sp in function() return string.find(str,div,pos,false) end do
  138.         table.insert(arr,string.sub(str,pos,st-1))
  139.         pos = sp + 1
  140.     end
  141.     table.insert(arr,string.sub(str,pos))
  142.     return arr
  143. end
  144.  
  145. local chatlog = {}
  146. local blacklist = {}
  147. local whitelist = {}
  148. local userActions = {}
  149. local userActionNames = {}
  150.  
  151. local addToChatlog = function(user,message) --what the fuck do you think it does
  152.     if chatlog[1] then
  153.         if chatlog[#chatlog][1] == user and chatlog[#chatlog][2] == message then
  154.             chatlog[#chatlog] = {user,message,chatlog[#chatlog][3]+1}
  155.         else
  156.             chatlog[#chatlog+1] = {user,message,1}
  157.         end
  158.     else
  159.         chatlog[#chatlog+1] = {user,message,1}
  160.     end
  161. end
  162.  
  163. local writeChatlog = function() --appends chat output to the chat log
  164.     prettyOutput = "("..chatlog[#chatlog][3] or "0"..") <"..chatlog[#chatlog][1].."> "..chatlog[#chatlog][2]
  165.     local file = fs.open(chatlogDir,"a")
  166.     file.writeLine(prettyOutput)
  167.     file.close()
  168. end
  169.  
  170. local saveBanlist = function()
  171.     local file = fs.open(banDir,"w")
  172.     for k,v in pairs(blacklist) do
  173.         file.writeLine(k)
  174.         file.writeLine(v)
  175.         file.writeLine("")
  176.     end
  177.     file.close()
  178. end
  179.  
  180. local loadBanlist = function()
  181.     blacklist = {}
  182.     local file = fs.open(banDir,"r")
  183.     local name,reason = ""
  184.     while name do
  185.         name = file.readLine()
  186.         if name then
  187.             reason = file.readLine()
  188.             file.readLine() --blank space
  189.             blacklist[name] = reason
  190.         end
  191.     end
  192.     file.close()
  193.     return blacklist
  194. end
  195.  
  196. local saveAdminlist = function()
  197.     local file = fs.open(adminDir,"w")
  198.     for a = 1, #adminUserTable do
  199.         file.writeLine(adminUserTable[a])
  200.     end
  201.     file.close()
  202. end
  203.  
  204. local loadAdminlist = function()
  205.     adminUserTable = {}
  206.     local file = fs.open(adminDir,"r")
  207.     local line = ""
  208.     while line do
  209.         line = file.readLine()
  210.         if line then
  211.             adminUserTable[#adminUserTable+1] = line
  212.         end
  213.     end
  214.     file.close()
  215.     return adminUserTable
  216. end
  217.  
  218. local saveConfig = function()
  219.     local file = fs.open(configDir,"w")
  220.     file.writeLine("prefix:"..textutils.serialize(mcci.prefix))
  221.     file.writeLine("mcciLabel:"..textutils.serialize(mcci.mcciLabel))
  222.     file.writeLine("ignoreErrors:"..tostring(mcci.ignoreErrors))
  223.     file.close()
  224. end
  225.  
  226. local fixInput = function(input)
  227.     if tonumber(input) then
  228.         return tonumber(input)
  229.     elseif input == "false" then
  230.         return false
  231.     elseif input == "true" then
  232.         return true
  233.     elseif textutils.unserialize(input) then
  234.         return textutils.unserialize(input)
  235.     else
  236.         return tostring(input)
  237.     end
  238. end
  239.  
  240. loadConfig = function()
  241.     local file = fs.open(configDir,"r")
  242.     local line = ""
  243.     while line do
  244.         line = file.readLine()
  245.         if line then
  246.             local name = line:sub(1,line:find(":")-1)
  247.             local value = line:sub(line:find(":")+1)
  248.             value = fixInput(value)
  249.             mcci[name] = value
  250.         end
  251.     end
  252.     file.close()
  253. end
  254.  
  255. local scr_x, scr_y = term.getSize()
  256.  
  257. local render = function()
  258.     term.setTextColor(colors.white)
  259.     term.setBackgroundColor(colors.black)
  260.     term.clear()
  261.     term.setCursorPos(1,1)
  262.     print("("..mcci.mcciLabel.."/Prefix='"..mcci.prefix.."')")
  263.     print("(ignoreErrors="..tostring(mcci.ignoreErrors)..")")
  264.     print(("-"):rep(scr_x))
  265.     print("Active Users:")
  266.     for k,v in pairs(userActions) do
  267.         print("-"..k.." ("..userActionNames[k]..")")
  268.     end
  269. end
  270.  
  271. local initCommand = function(u,cmd,...)
  272.     local yarg = table.pack(...)
  273.     local golly_G = setmetatable({}, {__index=(_ENV or getfenv())})
  274.     golly_G.chatbox = chatbox
  275.     golly_G.WHISPER = WHISPER
  276.     golly_G.SAY = SAY
  277.     golly_G.LISTEN = LISTEN
  278.     golly_G._USERNAME = u
  279.     golly_G._PREFIX = mcci.prefix
  280.     golly_G._ADMIN = adminUser(u)
  281.     golly_G.pairs = pairs
  282.     userActions[u] = coroutine.create(function()
  283.         local func = loadfile(fs.combine(commandDir,cmd))
  284.         func = setfenv(func, golly_G)
  285.         local output = {pcall( function() return func(table.unpack(yarg)) end )}
  286.         if mcci.ignoreErrors and (output[1] == false) then
  287.             error(output[2])
  288.         end
  289.         return table.unpack(output)
  290.     end)
  291.     userActionNames[u] = cmd
  292.     render()
  293. end
  294.  
  295. local dCommands,dCommandsHelp
  296. dCommandsHelp = {
  297.     ["belay"] = mcci.prefix.."belay [playername] ; Belays all commands or a specific player's.",
  298.     ["ban"] = mcci.prefix.."ban playername ; Bans a player from using this chat command interpreter.",
  299.     ["unban"] = mcci.prefix.."unban playername ; Unbans a player who was banned from using this command interpreter.",
  300.     ["banlist"] = mcci.prefix.."banlist ; Lists every player banned from using this command interpreter.",
  301.     ["help"] = mcci.prefix.."help [commandname] ; Gives a more detailed description of a command.",
  302.     ["update"] = mcci.prefix.."update ; Redownloads the MCCI program and overwrites the source if it's different.",
  303.     ["restart"] = mcci.prefix.."restart ; Restarts the program. One would usually do this after updating.",
  304.     ["checkadmin"] = mcci.prefix.."checkadmin [username] ; Without argument, checks if you are an admin. Also can check if another user is an admin.",
  305.     ["admin"] = mcci.prefix.."admin username ; Sets a username as an administrator.",
  306.     ["sudo"] = mcci.prefix.."sudo username command ; Runs a command as a specific user. Can't be used to abdicate.",
  307.     ["abdicate"] = mcci.prefix.."abdicate ; Use with no arguments to tick yourself off the list of admins. Use with care, there's no confirming.",
  308. }
  309. dCommands = { --default commands
  310.     ["belay"] = function(u,username)
  311.         if adminUser(u) then
  312.             if username then
  313.                 if userActions[username] then
  314.                     userActions[username] = nil
  315.                     WHISPER(u,username.."'s command has been belayed.")
  316.                     WHISPER(username,"Your command has been belayed. Ready.")
  317.                     render()
  318.                 else
  319.                     WHISPER(u,"That user isn't executing a cancelable command.")
  320.                 end
  321.             else
  322.                 WHISPER(u,"All commands have been belayed.")
  323.                 for k,v in pairs(userActions) do
  324.                     WHISPER(k,"Your command has been belayed. Ready.")
  325.                 end
  326.                 userActions = {}
  327.                 render()
  328.             end
  329.         else
  330.             WHISPER(k,"You can't do that!")
  331.         end
  332.     end,
  333.     ["ban"] = function(u,baduser,...)
  334.         local arg = table.pack(...)
  335.         if adminUser(u) then
  336.             if adminUser(baduser) then
  337.                 WHISPER(u,"Very funny. You can't ban admins.")
  338.             elseif not baduser then
  339.                 WHISPER(u,"Do "..mcci.prefix.."ban [username]")
  340.             else
  341.                 if blacklist[baduser] then
  342.                     WHISPER(u,"That dude was already banned.")
  343.                 else
  344.                     blacklist[baduser] = table.concat(arg," ") or "Unspecified reason."
  345.                     userActions[baduser] = nil
  346.                     userActionNames[baduser] = nil
  347.                     render()
  348.                     WHISPER(u,"'"..baduser.."' has been banned from making commands.")
  349.                     WHISPER(baduser,"You are hereby BANNED from making MCCI commands!")
  350.                 end
  351.             end
  352.         else
  353.             WHISPER(u,"You can't do that!")
  354.         end
  355.     end,
  356.     ["banlist"] = function(u)
  357.         WHISPER(u,"## USERS BANNED FROM THIS CHAT AI ##")
  358.         for k,v in pairs(blacklist) do
  359.             WHISPER(u," * "..k.." ("..v..")")
  360.         end
  361.     end,
  362.     ["unban"] = function(u,baduser)
  363.         if adminUser(u) then
  364.             if adminUser(baduser) then
  365.                 WHISPER(u,"Admins can't be banned to begin with, you dolt.")
  366.             elseif (not baduser) then
  367.                 WHISPER(u,"Do "..mcci.prefix.."unban [username]")
  368.             else
  369.                 if (not blacklist[baduser]) then
  370.                     WHISPER(u,"That dude isn't banned.")
  371.                 else
  372.                     blacklist[baduser] = nil
  373.                     WHISPER(u,"'"..baduser.."' has been unbanned from making commands.")
  374.                     WHISPER(baduser,"You've been unbanned from making commands.")
  375.                 end
  376.             end
  377.         else
  378.             if blacklist[gooduser] then
  379.                 WHISPER(u,"You can't do that!")
  380.             else
  381.                 WHISPER(u,"You couldn't do that even if "..gooduser.." were banned!")
  382.             end
  383.         end
  384.     end,
  385.     ["order"] = function(u)
  386.         WHISPER(u,"What, do I look like a pizzeria to you?")
  387.     end,
  388.     ["help"] = function(u,cmd)
  389.         if cmd then
  390.             if dCommands[cmd] then
  391.                 WHISPER(u,dCommandsHelp[cmd])
  392.             else
  393.                 if not fs.exists(fs.combine(commandDir,cmd)) then
  394.                     WHISPER(u,"That command doesn't exist, internally or externally.")
  395.                 else
  396.                     if fs.exists(fs.combine(commandHelpDir,cmd)) then
  397.                         local file = fs.open(fs.combine(commandHelpDir,cmd),"r")
  398.                         local cont = file.readAll(file)
  399.                         file.close()
  400.                         cont = cont:gsub("$PREFIX",mcci.prefix):gsub("\n"," ; ")
  401.                         WHISPER(u,cont)
  402.                     else
  403.                         WHISPER(u,"That external command does not have a help file.")
  404.                     end
  405.                 end
  406.             end
  407.         else
  408.             local list = {}
  409.             local cmdlist = fs.list(commandDir)
  410.             for k,v in pairs(dCommands) do
  411.                 list[#list+1] = k
  412.             end
  413.             for a = 1, #cmdlist do
  414.                 list[#list+1] = cmdlist[a]
  415.             end
  416.             for a = 1, #list do
  417.                 WHISPER(u,mcci.prefix..list[a])
  418.             end
  419.         end
  420.     end,
  421.     ["update"] = function(u)
  422.         if adminUser(u) then
  423.             WHISPER(u,"Downloading latest version...")
  424.             local foyle = http.get("https://pastebin.com/raw/5tJM4Bf8")
  425.             if foyle then
  426.                 local cont = foyle.readAll()
  427.                 local mccifoyle = fs.open(shell.getRunningProgram(),"r")
  428.                 local mccicont = mccifoyle.readAll()
  429.                 mccifoyle.close()
  430.                 if mccicont == cont then
  431.                     WHISPER(u,"You were using the latest version. Aborting.")
  432.                 else
  433.                     local file = fs.open(shell.getRunningProgram(),"w")
  434.                     file.write(cont)
  435.                     file.close()
  436.                     WHISPER(u,"Update complete. Use "..mcci.prefix.."restart to run the latest version.")
  437.                 end
  438.             end
  439.         else
  440.             WHISPER(u,"Yeah, try that again as an admin, doofus.")
  441.         end
  442.     end,
  443.     ["restart"] = function(u)
  444.         if adminUser(u) then
  445.             doRestart = true
  446.         end
  447.     end,
  448.     ["checkadmin"] = function(u,user)
  449.         if not user then
  450.             if adminUser(u) then
  451.                 WHISPER(u,"You're an admin.")
  452.             else
  453.                 WHISPER(u,"You're decidedly not an admin.")
  454.             end
  455.         else
  456.             if adminUser(user) then
  457.                 WHISPER(u,"'"..user.."' is an admin.")
  458.             else
  459.                 WHISPER(u,"'"..user.."' is decidedly not an admin.")
  460.             end
  461.         end
  462.     end,
  463.     ["admin"] = function(u,user)
  464.         if not user then
  465.             if adminUser(u) then
  466.                 WHISPER(u,"Expected an argument with who you wish to make an admin, dunce.")
  467.             else
  468.                 WHISPER(u,"Only admins can make other people admins, you twat.")
  469.             end
  470.         else
  471.             if adminUser(u) then
  472.                 if adminUser(user) then
  473.                     if user == u then
  474.                         WHISPER(u,"Oh my god, stop it.")
  475.                     else
  476.                         WHISPER(u,"That person is already an admin.")
  477.                     end
  478.                 else
  479.                     table.insert(adminUserTable,user)
  480.                     WHISPER(u,"'"..user.."' is now an admin.")
  481.                 end
  482.             else
  483.                 WHISPER(u,"This is an admin command, lamebrain.")
  484.             end
  485.         end
  486.     end,
  487.     ["abdicate"] = function(u,user)
  488.         if adminUser(u) then
  489.             if user then
  490.                 WHISPER(u,"You can't abdicate another user from their adminship.")
  491.             else
  492.                 for a = 1, #adminUserTable do
  493.                     if adminUserTable[a] == u then
  494.                         table.remove(adminUserTable,a)
  495.                         WHISPER(u,"Lo, you have abdicated the throne of adminship.")
  496.                         return
  497.                     end
  498.                 end
  499.                 WHISPER(u,"That's weird. You weren't on the list, but you still did this command.")
  500.             end
  501.         else
  502.             if user then
  503.                 WHISPER(u,"If you really don't like an admin, don't go complaining to me.")
  504.             else
  505.                 WHISPER(u,"Abdicate from what? Only admins can do this!")
  506.             end
  507.         end
  508.     end,
  509.     ["sudo"] = function(u,user,cmd,...)
  510.         if adminUser(u) then
  511.             if cmd == "abdicate" then
  512.                 WHISPER(u,"You can't use sudo to abdicate people!")
  513.             else
  514.                 if user then
  515.                     if userActions[user] then
  516.                         WHISPER(u,"That user is already in a command.")
  517.                     else
  518.                         if cmd then
  519.                             initCommand(user,cmd,...)
  520.                             WHISPER(u,"Ran '"..cmd.."' as '"..user.."'.")
  521.                         else
  522.                             WHISPER(u,"Sudo requires a second argument for the command.")
  523.                         end
  524.                     end
  525.                 else
  526.                     WHISPER(u,"Sudo requires a first argument for the user.")
  527.                 end
  528.             end
  529.         else
  530.             WHISPER(u,"Sudo is an admin's command!")
  531.         end
  532.     end,
  533. }
  534.  
  535. local handleDcommands = function(u,f,...) --heh heh heh
  536.     local arg = table.pack(...)
  537.     if dCommands[f] then
  538.         return true, dCommands[f](u,table.unpack(arg))
  539.     else
  540.         return false
  541.     end
  542. end
  543.  
  544. local handleNormalCommands = function(u,cmd,...)
  545.     local yarg = table.pack(...)
  546.     local cmdlist = fs.list(commandDir)
  547.     for a = 1, #cmdlist do
  548.         if cmdlist[a] == cmd then
  549.             initCommand(u,cmd,table.unpack(yarg))
  550.             if useMoarPeriphs then setLabel(mcci.mcciLabel..":"..userActionNames[u]) end
  551.             return true
  552.         end
  553.     end
  554.     return false
  555. end
  556.  
  557. local fuckingDoIt = function(user,message)
  558. --  local user, message
  559.     local isDcommand, isNormalCommand
  560. --  while true do
  561. --      user, message = LISTEN()
  562. --      sleep(0) --to ensure that chatbox output comes AFTER player chat
  563.         addToChatlog(user,message)
  564.         writeChatlog()
  565.         loadBanlist()
  566.         loadAdminlist()
  567.         loadConfig()
  568.         if useMoarPeriphs then setLabel(mcci.mcciLabel) end
  569.         render()
  570.         if not blacklist[user] then
  571.             if message:sub(1,#mcci.prefix) == mcci.prefix then
  572.                 message = message:sub(#mcci.prefix+1)
  573.                 if userActions[user] then
  574.                     if message == "nvm" then
  575.                         userActions[user] = nil
  576.                         userActionNames[user] = nil
  577.                         WHISPER(user,"Command cancelled. Ready.")
  578.                         render()
  579.                     else
  580.                         return "followup_command_"..user, message
  581.                     end
  582.                 else
  583.                     isNormalCommand = handleNormalCommands(user,table.unpack(explode(" ",message)))
  584.                     if not isNormalCommand then
  585.                         isDcommand = handleDcommands(user,table.unpack(explode(" ",message)))
  586.                         if doRestart then
  587.                             return
  588.                         else
  589.                             if not isDcommand then
  590.                                 WHISPER(user,"No such command exists, internally or externally.")
  591.                             end
  592.                         end
  593.                     end
  594.                 end
  595.             end
  596.             saveBanlist()
  597.             saveAdminlist()
  598.             saveConfig()
  599.         end
  600. --  end
  601. end
  602.  
  603. if not fs.exists(adminDir) then
  604.     saveAdminlist()
  605. end
  606. if not fs.exists(banDir) then
  607.     saveBanlist()
  608. end
  609. if not fs.exists(configDir) then
  610.     saveConfig()
  611. end
  612.  
  613. loadAdminlist()
  614. loadBanlist()
  615. loadConfig()
  616.  
  617. render()
  618.  
  619. local doBreak, vres, grodyList --grodyList is the list of coroutines that will be purged after each queuing
  620. local rootEvent = {}
  621. local followUpEvent = {}
  622. local doUserActions = function()
  623.     while true do
  624.         rootEvent = {os.pullEvent()}
  625.         if checkit(rootEvent[1], table.unpack(chatEvents)) then
  626.             followUpEvent = {fuckingDoIt(parseListenEvent(rootEvent))}
  627.         end
  628.         grodyList = {}
  629.         for k,v in pairs(userActions) do
  630.             if useMoarPeriphs then setLabel(mcci.mcciLabel..":"..userActionNames[k]) end
  631.             if (coroutine.status(v) == "dead") then
  632.                 if useMoarPeriphs then setLabel(mcci.mcciLabel) end
  633.                 WHISPER(k,"Ready.")
  634.                 grodyList[#grodyList+1] = k
  635.             else
  636.                 _,vres = coroutine.resume(v,table.unpack(rootEvent))
  637.             end
  638.         end
  639.         for a = 1, #grodyList do
  640.             userActions[grodyList[a]] = nil
  641.             userActionNames[grodyList[a]] = nil
  642.         end
  643.         grodyList = {}
  644.         if #followUpEvent > 0 then
  645.             for k,v in pairs(userActions) do
  646.                 if useMoarPeriphs then setLabel(mcci.mcciLabel..":"..userActionNames[k]) end
  647.                 _,vres = coroutine.resume(v,table.unpack(rootEvent))
  648.                 if (coroutine.status(v) == "dead") then
  649.                     if useMoarPeriphs then setLabel(mcci.mcciLabel) end
  650.                     WHISPER(k,"Ready.")
  651.                     grodyList[#grodyList+1] = k
  652.                 end
  653.             end
  654.         end
  655.         for a = 1, #grodyList do
  656.             userActions[grodyList[a]] = nil
  657.             userActionNames[grodyList[a]] = nil
  658.         end
  659.         render()
  660.         if doRestart then return true end
  661.     end
  662. end
  663.  
  664. doUserActions()
  665.  
  666. if doRestart then
  667.     SAY("MCCI Restarting.")
  668.     shell.run(shell.getRunningProgram())
  669. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement