Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- DisenchantBot v1.2 - No Movement Library, Refined Cycle Logic
- Uses direct turtle API for movement.
- Adjusted disenchanting steps for item processing and final count.
- ]]
- --#region Configuration
- local CHAT_BOX_PERIPHERAL_NAME = "chatBox"
- local COMMAND_PREFIX = "@disenchant"
- local CHAT_BOT_NAME = "DisenchantBot"
- local CHAT_BOT_BRACKETS = "[]"
- local CHAT_BOT_BRACKET_COLOR = "&3" -- Cyan
- local DEBUG_LOGGING_ENABLED = true
- local LOG_FILE_NAME = "disenchant.log"
- local AUTOMATA_PERIPHERAL_NAME = "endAutomata" -- For goHome()
- --#endregion
- --#region Global State
- local chatBox = nil
- local chatBoxFunctional = true
- local isDisenchantRunning = false
- local fuelWarningSent = false -- Kept for general fuel awareness
- local automataPeripheral = nil -- Store the automata peripheral
- --#endregion
- --#region Logger Setup
- local function writeToLogFile(message) if not DEBUG_LOGGING_ENABLED then return end; local f,e=fs.open(LOG_FILE_NAME,"a"); if f then f.write(string.format("[%s] %s\n",os.date("%Y-%m-%d %H:%M:%S"),message));f.close() else print("LOG ERR: "..tostring(e))end end
- local function botLog(msg)local fm="["..CHAT_BOT_NAME.."-Debug] "..msg; print(fm); writeToLogFile(fm)end
- --#endregion
- --#region Basic Turtle Functions (No ML)
- local function goHome()
- if not automataPeripheral then
- automataPeripheral = peripheral.find(AUTOMATA_PERIPHERAL_NAME)
- if not automataPeripheral then
- botLog("CRITICAL WARN: EndAutomata peripheral ('"..AUTOMATA_PERIPHERAL_NAME.."') not found. Cannot warp home.")
- return false
- end
- end
- botLog("Warping home via EndAutomata...")
- local success, reason = pcall(function() return automataPeripheral.warpToPoint("home") end)
- if success and reason then -- pcall returns true for success, 'reason' is the actual return value of warpToPoint
- botLog("Warp home successful.")
- -- Assuming home position sets turtle facing North (standard for many setups)
- return true
- else
- botLog("Failed to warp home: " .. tostring(reason or "pcall error"))
- return false
- end
- end
- --#endregion
- --#region DisenchantBot Peripherals and Helpers
- local function sendFormattedChat(messageComponents)
- local plainText = ""
- if type(messageComponents) == "table" then
- for _,c_comp in ipairs(messageComponents) do plainText = plainText .. (type(c_comp) == "table" and c_comp.text or tostring(c_comp) or "") end
- elseif messageComponents ~= nil then plainText = tostring(messageComponents)
- else plainText = "nil_message_components_to_sendFormattedChat" end
- if not chatBoxFunctional or not chatBox then botLog("[NoChat] " .. plainText); return false end
- local jsonMessage_success, jsonMessage = pcall(textutils.serialiseJSON, messageComponents)
- if not jsonMessage_success then botLog("!!! textutils.serialiseJSON FAILED: " .. tostring(jsonMessage)); print("ERROR: Could not serialize chat message!"); return false end
- local peripheral_call_success, peripheral_error = pcall(function() return chatBox.sendFormattedMessage(jsonMessage, CHAT_BOT_NAME, CHAT_BOT_BRACKETS, CHAT_BOT_BRACKET_COLOR) end)
- if not peripheral_call_success then botLog("!!! chatBox.sendFormattedMessage FAILED: " .. tostring(peripheral_error)); print("ERROR: Failed to send formatted message via chatBox: " .. tostring(peripheral_error)); return false end
- return true
- end
- local function announce(messageComponents)
- if not sendFormattedChat(messageComponents) then botLog("Announce: sendFormattedChat failed for: " .. textutils.serialize(messageComponents, {compact=true, max_depth=2})) end
- sleep(0.3)
- end
- local COLORS={GOLD="gold",AQUA="aqua",GRAY="gray",RED="red",GREEN="green",YELLOW="yellow",WHITE="white",DARK_RED="dark_red",DARK_GRAY="dark_gray"}
- local function critical_error_handler(message, doTurnRightForThisError) -- Changed second param
- announce({{text = "CRITICAL ERROR: " .. message .. " Halting " .. CHAT_BOT_NAME .. ".", c = COLORS.DARK_RED, b = true}})
- botLog("CRITICAL ERROR: " .. message)
- if doTurnRightForThisError then
- botLog("Performing specific turnRight for this error.")
- turtle.turnRight()
- end
- isDisenchantRunning = false
- end
- local function check_stop_signal()
- if not isDisenchantRunning then botLog("Stop signal detected during cycle."); return true end
- sleep(0) -- Yield
- return false
- end
- --#endregion
- --#region DisenchantBot Command Handlers
- local commandHandlers = {}
- commandHandlers.help = function(u,_)
- announce({{text="--- "..CHAT_BOT_NAME.." Cmds ("..COMMAND_PREFIX..") ---",c=COLORS.GOLD,b=true}})
- announce({{text=COMMAND_PREFIX.." help",c=COLORS.AQUA},{text=" - Shows this help message.",c=COLORS.GRAY}})
- announce({{text=COMMAND_PREFIX.." start",c=COLORS.AQUA},{text=" - Starts the disenchanting loop.",c=COLORS.GRAY}})
- announce({{text=COMMAND_PREFIX.." stop",c=COLORS.AQUA},{text=" - Stops the current disenchanting loop.",c=COLORS.GRAY}})
- announce({{text=COMMAND_PREFIX.." cmd <lua_code>",c=COLORS.AQUA},{text=" - Executes Lua code (e.g., turtle.forward()).",c=COLORS.GRAY}})
- announce({{text=COMMAND_PREFIX.." fuel",c=COLORS.AQUA},{text=" - Shows current fuel level.",c=COLORS.GRAY}})
- announce({{text=COMMAND_PREFIX.." unstuck",c=COLORS.AQUA},{text=" - Tries to warp home (stops current cycle).",c=COLORS.GRAY}})
- end
- commandHandlers.cmd = function(u,a)
- if #a == 0 then announce({{text="Usage: "..COMMAND_PREFIX.." cmd <lua_code_to_run>",c=COLORS.YELLOW}}); return end
- if #a == 1 and string.lower(a[1]) == "help" then
- announce({{text="--- "..COMMAND_PREFIX.." cmd Help ---",c=COLORS.GOLD,b=true}})
- announce({{text="Usage: "..COMMAND_PREFIX.." cmd <lua_code_to_run>",c=COLORS.WHITE}})
- announce({{text="Executes Lua code. Examples:",c=COLORS.AQUA}})
- announce({{text=" "..COMMAND_PREFIX.." cmd turtle.turnRight()",c=COLORS.WHITE}})
- announce({{text=" "..COMMAND_PREFIX.." cmd return turtle.getFuelLevel()",c=COLORS.WHITE}})
- return
- end
- local cs=table.concat(a," "); botLog("User "..u.." executing raw command: "..cs)
- local fn,e=load("return "..cs,"raw_user_command","t",{turtle=turtle, peripheral=peripheral, os=os, fs=fs, textutils=textutils, sleep=sleep, print=print, announce=announce, COLORS=COLORS, goHome=goHome})
- if not fn then announce({{text="Error parsing cmd: ",c=COLORS.RED},{text=tostring(e),c=COLORS.YELLOW}}); botLog("Parse error for raw cmd '"..cs.."': "..tostring(e)); return end
- local s,r=pcall(fn)
- if s then announce({{text="Cmd executed. Result: ",c=COLORS.GREEN},{text=tostring(r),c=COLORS.WHITE}}); botLog("Raw cmd '"..cs.."' result: "..tostring(r))
- else announce({{text="Error executing cmd: ",c=COLORS.RED},{text=tostring(r),c=COLORS.YELLOW}}); botLog("Execution error for raw cmd '"..cs.."': "..tostring(r)) end
- end
- commandHandlers.fuel = function(u,_) local l,lm=turtle.getFuelLevel(),turtle.getFuelLimit(); announce({{text="Fuel: ",c=COLORS.AQUA},{text=tostring(l)..(lm>0 and(" / "..tostring(lm))or" (Unlimited)"),c=COLORS.WHITE}}) end
- commandHandlers.unstuck = function(u,_)
- announce({{text="Unstuck: Attempting to warp home...",c=COLORS.YELLOW}});botLog(u.." used unstuck command.")
- isDisenchantRunning = false
- if goHome()then announce({{text="Warped home successfully.",c=COLORS.GREEN}}) else announce({{text="Failed to warp home.",c=COLORS.RED}})end
- end
- --#endregion
- --#region DisenchantBot Core Logic
- function performSingleDisenchantCycle()
- botLog("== Starting new Disenchant Cycle ==")
- if check_stop_signal() then return "stopped_by_user" end
- botLog("Step 1: Warping home.")
- if not goHome() then critical_error_handler("Failed to warp home at cycle start.", false); return "error" end
- -- Assuming home faces North.
- if check_stop_signal() then return "stopped_by_user" end
- botLog("Step 2: Dropping all inventory items (slots 1-16).")
- for i = 1, 16 do turtle.select(i); if turtle.getItemCount(i) > 0 then botLog("Dropping from slot " .. i); turtle.drop() end end
- if check_stop_signal() then return "stopped_by_user" end
- botLog("Step 3: Checking fuel.")
- local fuelLevel = turtle.getFuelLevel(); local fuelLimit = turtle.getFuelLimit()
- if fuelLimit > 0 and (fuelLevel / fuelLimit) < 0.50 then
- announce({{text="Fuel under 50% ("..fuelLevel.."/"..fuelLimit.."). Refueling...", c=COLORS.YELLOW}})
- botLog("Attempting to suck, refuel, drop excess from below.")
- turtle.select(1) -- Use slot 1 for fuel operations
- if not turtle.suck() then announce({{text="Failed to suck fuel item from below.", c=COLORS.RED}}); botLog("Failed to suck fuel from below.")
- else
- botLog("Sucked an item, attempting to refuel.")
- if not turtle.refuel() then announce({{text="Refuel failed. Item might not be fuel.", c=COLORS.RED}}); botLog("turtle.refuel() failed.")
- else botLog("Refuel successful. Fuel: " .. turtle.getFuelLevel()) end
- turtle.drop() -- Drop remaining/unburnable item
- botLog("Dropped item from slot 1 after refuel attempt.")
- end
- else botLog("Fuel OK ("..fuelLevel.."/"..fuelLimit.."). Skipping refuel.") end
- if check_stop_signal() then return "stopped_by_user" end
- botLog("Step 4: Turning right (to face East - Input Chest).")
- turtle.turnRight()
- if check_stop_signal() then return "stopped_by_user" end
- botLog("Step 5: Sucking up to 16 items (1 by 1) from Input Chest (East).")
- local itemsSuckedInStep5_ops = 0
- for i = 1, 16 do
- local emptySlotFound = false; local originalSelection = turtle.getSelectedSlot()
- for slotIdx = 1, 16 do if turtle.getItemCount(slotIdx) == 0 then turtle.select(slotIdx); emptySlotFound = true; break end end
- if not emptySlotFound then botLog("No empty slot to suck item into."); turtle.select(originalSelection); break end
- if turtle.suck(1) then itemsSuckedInStep5_ops = itemsSuckedInStep5_ops + 1; botLog("Sucked item op " .. itemsSuckedInStep5_ops .. " into slot " .. turtle.getSelectedSlot())
- else turtle.select(originalSelection); botLog("Failed to suck more from Input Chest after " .. itemsSuckedInStep5_ops .. " ops."); break end
- end
- announce({{text="Sucked "..itemsSuckedInStep5_ops.." item(s)/stacks from Input Chest.", c=COLORS.GRAY}})
- if check_stop_signal() then return "stopped_by_user" end
- botLog("Step 6: Verifying sucked items and counting non-stackables.")
- local slotsWithValidNonStackableItems = {}
- for slot = 1, 16 do
- turtle.select(slot)
- if turtle.getItemCount(slot) > 0 then
- local space = turtle.getItemSpace(slot)
- if space == 0 then table.insert(slotsWithValidNonStackableItems, slot); botLog("Slot " .. slot .. ": Non-stackable item found. Name: " .. (turtle.getItemDetail() and turtle.getItemDetail().name or "N/A"))
- elseif space == 64 then critical_error_handler("Inv check contradiction: Slot " .. slot .. " has items but getItemSpace is 64.", false); return "error" -- Error means don't turn right
- else critical_error_handler("Inv check: Slot " .. slot .. " has unexpected stackable item (space=" .. space .. "). Expected only non-stackables.", false); return "error"
- end
- end
- end
- local expectedNonStackableCount = #slotsWithValidNonStackableItems
- botLog("Found " .. expectedNonStackableCount .. " non-stackable item(s) to process in slots: " .. table.concat(slotsWithValidNonStackableItems, ", "))
- if expectedNonStackableCount == 0 then
- if itemsSuckedInStep5_ops > 0 then announce({{text="No valid non-stackable items out of "..itemsSuckedInStep5_ops.." sucked. Restarting after delay.", c=COLORS.YELLOW}})
- else announce({{text="No items found in Input Chest to process. Restarting after delay.", c=COLORS.YELLOW}}) end
- botLog("Turning left (to face North) before 60s wait.")
- turtle.turnLeft()
- botLog("Waiting 60 seconds.")
- for _=1,60 do if check_stop_signal() then return "stopped_by_user" end; sleep(1) end
- return "continue_looping"
- end
- announce({{text="Processing "..expectedNonStackableCount.." non-stackable item(s).", c=COLORS.AQUA}})
- if check_stop_signal() then return "stopped_by_user" end
- -- Step 7a: Drop items into Disenchanter (tryOutputchest)
- botLog("Step 7a: Turning right (to face South - Disenchanter Input).")
- turtle.turnRight()
- botLog("Dropping " .. expectedNonStackableCount .. " non-stackable items into Disenchanter.")
- for _, slotIdx in ipairs(slotsWithValidNonStackableItems) do
- turtle.select(slotIdx)
- if turtle.getItemCount(slotIdx) > 0 then
- if not turtle.drop() then critical_error_handler("Failed to drop item from slot " .. slotIdx .. " into Disenchanter.", false); return "error" end
- end
- end
- botLog("Waiting 5 seconds after dropping items into Disenchanter.")
- for _=1,5 do if check_stop_signal() then return "stopped_by_user" end; sleep(1) end
- -- Step 7b: Extractor Loop (Processing items with Disenchanter)
- local items_to_expect_back_from_disenchanter = expectedNonStackableCount
- local items_retrieved_from_disenchanter_this_pass = 0
- local itemsSuccessfullyProcessedOverallByDisenchanter = false
- while items_to_expect_back_from_disenchanter > 0 do
- if check_stop_signal() then return "stopped_by_user" end
- botLog("Disenchanter Loop: Expecting to retrieve up to " .. items_to_expect_back_from_disenchanter .. " item(s).")
- items_retrieved_from_disenchanter_this_pass = 0
- local slots_with_retrieved_items_this_pass = {}
- for i = 1, items_to_expect_back_from_disenchanter do
- local emptySlotFound = false; local originalSelection = turtle.getSelectedSlot()
- for slotIdx = 1, 16 do if turtle.getItemCount(slotIdx) == 0 then turtle.select(slotIdx); emptySlotFound = true; break end end
- if not emptySlotFound then botLog("Disenchanter loop: Turtle inventory full. Cannot suck more."); turtle.select(originalSelection); break end
- if turtle.suck(1) then
- items_retrieved_from_disenchanter_this_pass = items_retrieved_from_disenchanter_this_pass + 1
- table.insert(slots_with_retrieved_items_this_pass, turtle.getSelectedSlot())
- botLog("Disenchanter loop: Sucked item " .. items_retrieved_from_disenchanter_this_pass .. " (from Disenchanter) into slot " .. turtle.getSelectedSlot())
- else
- turtle.select(originalSelection)
- botLog("Disenchanter loop: Failed to suck more (Disenchanter empty after " .. items_retrieved_from_disenchanter_this_pass .. " items).")
- break
- end
- end
- if items_retrieved_from_disenchanter_this_pass < items_to_expect_back_from_disenchanter then
- itemsSuccessfullyProcessedOverallByDisenchanter = true
- local processed_this_round = items_to_expect_back_from_disenchanter - items_retrieved_from_disenchanter_this_pass
- announce({{text="Disenchanter processed "..processed_this_round.." item(s). " .. items_retrieved_from_disenchanter_this_pass .. " returned/remaining.", c=COLORS.GRAY}})
- if items_retrieved_from_disenchanter_this_pass > 0 then
- botLog("Dropping the " .. items_retrieved_from_disenchanter_this_pass .. " returned items back into Disenchanter.")
- for _, slotIdx in ipairs(slots_with_retrieved_items_this_pass) do
- turtle.select(slotIdx)
- if turtle.getItemCount(slotIdx) > 0 then if not turtle.drop() then botLog("WARN: Failed to re-drop item from slot " .. slotIdx) end end
- end
- end
- items_to_expect_back_from_disenchanter = items_retrieved_from_disenchanter_this_pass
- if items_to_expect_back_from_disenchanter == 0 then announce({{text="All items batch processed by Disenchanter.", c=COLORS.GREEN}}); botLog("All items in batch processed."); break end
- botLog("Waiting 20 seconds before next Disenchanter check.")
- for _=1,20 do if check_stop_signal() then return "stopped_by_user" end; sleep(1) end
- else
- announce({{text="Disenchanter did not process " .. items_retrieved_from_disenchanter_this_pass .. " item(s). Assuming unprocessable.", c=COLORS.YELLOW}})
- botLog("Disenchanter loop: No items lost. These " .. items_retrieved_from_disenchanter_this_pass .. " items remain in turtle.")
- -- These items are now in the turtle and considered "unprocessable originals".
- break
- end
- end
- if check_stop_signal() then return "stopped_by_user" end
- -- Step 8: Conditional Wait & Turn
- if itemsSuccessfullyProcessedOverallByDisenchanter then
- botLog("Step 8: Items processed by Disenchanter. Waiting 15 seconds.")
- for _=1,15 do if check_stop_signal() then return "stopped_by_user" end; sleep(1) end
- else botLog("Step 8: No items processed by Disenchanter. Skipping 15s wait.") end
- botLog("Turning right (to face West - Disenchanter Output Chest).")
- turtle.turnRight()
- if check_stop_signal() then return "stopped_by_user" end
- -- Step 9: Suck 17x from Disenchanter Output Chest (West)
- botLog("Step 9: Sucking 17x from Disenchanter Output Chest (West).")
- local suck_ops_step9 = 0
- for i = 1, 17 do
- local emptySlotFound = false; local originalSelection = turtle.getSelectedSlot()
- for slotIdx = 1, 16 do if turtle.getItemCount(slotIdx) == 0 then turtle.select(slotIdx); emptySlotFound = true; break end end
- if not emptySlotFound then botLog("Output suck: Inventory full."); turtle.select(originalSelection); break end
- if turtle.suck() then suck_ops_step9 = suck_ops_step9 + 1; botLog("Output suck op "..i.." successful into slot " .. turtle.getSelectedSlot())
- else turtle.select(originalSelection); botLog("Output suck: Chest empty after " .. suck_ops_step9 .. " ops."); break end
- sleep(0.1)
- end
- botLog("Finished sucking from Disenchanter Output. Performed " .. suck_ops_step9 .. " suck operations.")
- if check_stop_signal() then return "stopped_by_user" end
- -- Step 10: Final Inventory Check (Non-stackable items count)
- botLog("Step 10: Final inventory check (expecting " .. expectedNonStackableCount .. " non-stackable items total).")
- local finalNonStackableItemsInTurtle = 0
- for slot = 1, 16 do
- turtle.select(slot)
- if turtle.getItemCount(slot) > 0 then
- if turtle.getItemSpace(slot) == 0 then finalNonStackableItemsInTurtle = finalNonStackableItemsInTurtle + 1
- else botLog("Slot " .. slot .. " has stackable item. Name: " .. (turtle.getItemDetail() and turtle.getItemDetail().name or "N/A") .. ". Not counted.") end
- end
- end
- botLog("Final count of non-stackable items in inventory: " .. finalNonStackableItemsInTurtle)
- if finalNonStackableItemsInTurtle ~= expectedNonStackableCount then
- -- Error case: Turn Right, then give warning & stop. critical_error_handler has 'doTurnRightForThisError'
- critical_error_handler("Final non-stackable count (" .. finalNonStackableItemsInTurtle .. ") != initial (" .. expectedNonStackableCount .. ").", true);
- return "error"
- end
- announce({{text="Final non-stackable item count ("..expectedNonStackableCount..") matches. Proceeding.", c=COLORS.GREEN}})
- if check_stop_signal() then return "stopped_by_user" end
- -- Step 11: Deposit Upwards
- botLog("Step 11: Turning right (to face North - Deposit Chest Above).")
- turtle.turnRight()
- botLog("Dropping all items upwards (from slots 1-16).")
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- if turtle.dropUp() then botLog("Dropped up items from slot " .. i)
- else botLog("Failed to dropUp from slot " .. i .. " (chest above full or no item).") end
- end
- end
- if check_stop_signal() then return "stopped_by_user" end
- botLog("== Disenchant Cycle Iteration Complete ==")
- announce({{text="Disenchant cycle iteration finished. Starting next.",c=COLORS.GRAY}})
- return "continue_looping" -- Signal to immediately start the next cycle
- end
- commandHandlers.start = function(u,a)
- if isDisenchantRunning then announce({{text=CHAT_BOT_NAME.." is already running.",c=COLORS.YELLOW}}); return end
- isDisenchantRunning = true; fuelWarningSent = false
- announce({{text="Starting "..CHAT_BOT_NAME.." loop...",c=COLORS.GOLD,b=true}})
- botLog(u.." initiated "..CHAT_BOT_NAME.." start.")
- end
- commandHandlers.stop = function(u,a)
- if not isDisenchantRunning then announce({{text=CHAT_BOT_NAME.." is not currently running.",c=COLORS.GRAY}}); return end
- announce({{text="Stop signal sent. Will stop after current major step/cycle.",c=COLORS.YELLOW}})
- botLog(u.." initiated "..CHAT_BOT_NAME.." stop.")
- isDisenchantRunning = false
- end
- --#endregion
- --#region DisenchantBot Main Loop
- local function run()
- if DEBUG_LOGGING_ENABLED then local f, err = fs.open(LOG_FILE_NAME, "w"); if f then f.write(string.format("[%s] %s Log Initialized.\n", os.date("%Y-%m-%d %H:%M:%S"), CHAT_BOT_NAME)); f.close() else print("LOG ERR: "..tostring(err)) end end
- term.clear();term.setCursorPos(1,1);
- automataPeripheral = peripheral.find(AUTOMATA_PERIPHERAL_NAME) -- Initial find for goHome()
- if not automataPeripheral then botLog("WARN: EndAutomata ('"..AUTOMATA_PERIPHERAL_NAME.."') not found at startup. `goHome` will fail.") end
- chatBox = peripheral.find(CHAT_BOX_PERIPHERAL_NAME)
- botLog(CHAT_BOT_NAME .. " initializing..."); botLog("Initial ChatBox peripheral check: " .. tostring(chatBox))
- if chatBox and chatBox.sendFormattedMessage then chatBoxFunctional = true; botLog("ChatBox FUNCTIONAL.")
- else chatBoxFunctional = false; botLog("ChatBox IS NIL or missing methods. Non-functional.") end
- botLog(CHAT_BOT_NAME.." online."); print(CHAT_BOT_NAME.." online. Use '"..COMMAND_PREFIX.." help'.")
- if not announce({{text=CHAT_BOT_NAME.." online, ready for disenchanting!",c=COLORS.GREEN}}) then botLog("Initial online announcement FAILED.") end
- while true do
- local event, p1, p2
- if isDisenchantRunning then event, p1, p2 = os.pullEventRaw(); if not event then sleep(0.05) end -- Non-blocking when running cycle
- else event, p1, p2 = os.pullEvent() end -- Blocking when idle
- if event then
- if event == "chat" then
- local user, message = p1, p2
- if message then
- if string.lower(message) == "@all" then botLog("@all from "..user); announce({{text="'"..COMMAND_PREFIX.." help' for my cmds.",c=COLORS.GREEN}})
- elseif string.sub(message,1,#COMMAND_PREFIX) == COMMAND_PREFIX then
- botLog("Chat cmd from "..user..": "..message)
- local params={};for pt in string.gmatch(message,"[^%s]+")do table.insert(params,pt)end
- local cmdName=""; if params[2]then cmdName=string.lower(params[2])end
- local cmdArgs={};for i=3,#params do table.insert(cmdArgs,params[i])end
- if commandHandlers[cmdName]then commandHandlers[cmdName](user,cmdArgs)
- elseif cmdName ~= "" then announce({{text="Unknown Cmd: '",c=COLORS.RED},{text=cmdName,c=COLORS.YELLOW},{text="'. Try '",c=COLORS.RED},{text=COMMAND_PREFIX.." help",c=COLORS.AQUA},{text="'.",c=COLORS.RED}}) end
- end
- end
- elseif event == "terminate" then botLog("Terminate event. Shutting down."); isDisenchantRunning=false; if chatBoxFunctional then announce({{text=CHAT_BOT_NAME.." shutting down.",c=COLORS.YELLOW}}) end; return end
- end
- if isDisenchantRunning then -- Check if should run a cycle iteration
- local cycleStatus = performSingleDisenchantCycle()
- if cycleStatus == "error" or cycleStatus == "stopped_by_user" then
- botLog(CHAT_BOT_NAME .." loop explicitly stopped due to: " .. cycleStatus)
- isDisenchantRunning = false -- Ensure it's stopped
- end
- -- If "continue_looping", the outer while true and isDisenchantRunning handles the next iteration.
- if not isDisenchantRunning then announce({{text=CHAT_BOT_NAME.." loop has stopped.",c=COLORS.GOLD}}); botLog(CHAT_BOT_NAME.." processing fully stopped.") end
- end
- end
- end
- run()
- --#endregion
Add Comment
Please, Sign In to add comment