diff --git a/clients/terminal.lua b/clients/terminal.lua index 438f5dc..b00cb90 100644 --- a/clients/terminal.lua +++ b/clients/terminal.lua @@ -640,7 +640,28 @@ end ---Read some number from the user ---@param input number|string ---@return number + + + + local function scroll_read(input) + correctChars = { + "*","/","+","-","(",")", + } + + local function isCorrectChar(char) + if tonumber(char) then return true end + for i,correctChar in ipairs(correctChars) do + if char == correctChar then + return true + end + end + return false + + end + + + ---@type string input = tostring(input) local shiftHeld = false @@ -651,13 +672,15 @@ local function scroll_read(input) term.setCursorPos(x, y) term.write(input) local e, char = os.pullEvent() - if e == "char" and tonumber(char) then - input = input .. char + if e == "char" then + if isCorrectChar(char) then + input = input .. char + end elseif e == "key" then if char == keys.backspace then input = input:sub(1, -2) elseif char == keys.enter then - return tonumber(input) or 0 + return tonumber(loadstring("return " .. input)()) or 0 elseif char == keys.leftShift then shiftHeld = true end @@ -680,7 +703,8 @@ end function INFO(item) mode = "INFO" - local itemAmount = math.min(item.maxCount, item.count) + --local itemAmount = math.min(item.maxCount, item.count) + local itemAmount = "" draw(function() setColors(headerFg, headerBg) clearLine(2) @@ -1179,15 +1203,6 @@ modeLookup = { SEARCH = SEARCH, CRAFT = CRAFT, CONFIG = CONFIG, SYSINFO = SYSINF local funcs = { lib.subscribe, SEARCH } -local watchdogAvaliable = fs.exists("watchdogLib.lua") -if watchdogAvaliable then - local watchdogLib = require '.watchdogLib' - local wdFunc = watchdogLib.watchdogLoopFromSettings() - if wdFunc ~= nil then - funcs[#funcs+1] = wdFunc - end -end - if turtleMode then funcs[#funcs + 1] = debounceTurtleInventory funcs[#funcs + 1] = processTurtleInventory diff --git a/modules/chatbox.lua b/modules/chatbox.lua index f589b33..ef8e706 100644 --- a/modules/chatbox.lua +++ b/modules/chatbox.lua @@ -1,9 +1,15 @@ ---@class modules.chatbox ---@field interface modules.chatbox.interface +hopper = require("/rom/programs/hopper") return { id = "chatbox", version = "1.0.0", config = { + useEnderChestDeposit = { + default = false, + description = "Items within vanilla enderchest will automatically be deposited into storage", + type = "boolean", + }, whitelist = { default = {}, description = @@ -32,7 +38,7 @@ return { }, ---@param loaded {inventory: modules.inventory, introspection: modules.introspection} init = function(loaded, config) - sleep(1) + sleep(1) assert(chatbox and chatbox.isConnected(), "This module requires a registered chatbox.") local function sendMessage(user, message, ...) chatbox.tell(user, message:format(...), config.chatbox.name.value, nil, "format") @@ -77,10 +83,16 @@ return { sendMessage(user, "usage: withdraw [name] ") end local periph = peripheral.wrap(introspection) --[[@as table]] + local ogItem = args[1] args[1] = getBestMatch(loaded.inventory.interface.listNames(), args[1]) - local count = loaded.inventory.interface.pushItems(false, periph.getInventory(), args[1], - tonumber(args[2]), nil, args[3], { allowBadTransfers = true }) - sendMessage(user, "Pushed &9%s &f%s.", count, args[1]) + + if args[1] ~= nil then + local count = loaded.inventory.interface.pushItems(false, periph.getInventory(), args[1], + tonumber(args[2]), nil, args[3], { allowBadTransfers = true }) + sendMessage(user, "Pushed &9%s &f%s.", count, args[1]) + else + sendMessage(user,"%s not found",ogItem) + end end, balance = function(user, args) if #args < 1 then @@ -128,13 +140,44 @@ return { end sendMessage(user, ms) end + } + + + + function depositIntoEnderChest(user) + local introspection = getIntrospection(user) + local enderChest = peripheral.wrap(introspection).getEnder() + for i=1,enderChest.size(),1 do + loaded.inventory.interface.performTransfer() + if enderChest.getItemDetail(i) == nil then + goto continue + end + loaded.inventory.interface.pullItems(false, enderChest, i, nil, nil, nil, { optimal = true }) + --loaded.inventory.interface.pullItems(false, enderChest,i, 64) + loaded.inventory.interface.performTransfer() + + ::continue:: + + end + sendMessage(user,"Ender Chest deposited") + end + + ---@class modules.chatbox.interface return { start = function() + if config.chatbox.useEnderChestDeposit.value then + commands["enderdeposit"] = function(user,args) + depositIntoEnderChest(user) + end + end while true do local event, user, command, args, data = os.pullEvent("command") local verified = data.ownerOnly + + + if not verified and config.chatbox.whitelist.value[user] then verified = true end