local user, slots, fromLabel, toLabel = ... local sn = require("api") if not (user or slots) then local out = { {colors.lightGray, "Quickly send items from one Shironeko box to another. Requires having at least 1 box. See ", colors.white, "\\sn", colors.lightGray, " for more info.", colors.white, " Usage:"}, {colors.lightGray, "send", colors.yellow, " ", colors.lime, " [fromSlot=\"main\"] [toSlot=\"main\"]"}, {colors.lightGray, "Examples:"}, {colors.lightGray, "send", colors.yellow, " hugeblank all", colors.lightGray, " - Sends all contents of your ", colors.lightBlue, "\"main\"", colors.lightGray, " box to hugeblank's ", colors.lightBlue, "\"main\"", colors.lightGray, " box."}, {colors.lightGray, "send", colors.yellow, " hypergenome", colors.yellow, " 1,2,3", colors.lime, " stone", colors.lightGray, " - Sends slots 1, 2, and 3 of your ", colors.lightBlue, "\"stone\"", colors.lightGray, " box to hypergenome's ", colors.lightBlue, "\"main\"", colors.lightGray, " box."}, {colors.lightGray, "send", colors.yellow, " ssh2", colors.yellow, " 1", colors.lime, " leather books", colors.lightGray, " - Sends slot 1 of your ", colors.lightBlue, "\"leather\"", colors.lightGray, " box to ssh2's ", colors.lightBlue, "\"books\"", colors.lightGray, " box."}, {colors.lightGray, "send", colors.yellow, " gplv3", colors.yellow, " 1=5,5=10,11=32", colors.lightGray, " - Sends 5 items from slot 1, 10 items from slot 5, and 32 items from slot 11 of your ", colors.lightBlue, "\"main\"", colors.lightGray, " box to gplv3's ", colors.lightBlue, "\"main\"", colors.lightGray, " box."}, {colors.lightGray, "Note that all labels besides ", colors.lightBlue, "\"main\"", colors.lightGray, " are hypothetical for the sake of demonstration."} } for i = 1, #out do local row = out[i] for i = 1, #row, 2 do term.setTextColor(row[i]) write(row[i+1]) end print() end return end fromLabel, toLabel = fromLabel or "main", toLabel or "main" if slots == "all" then slots = {} for i = 1, 27 do slots[i] = 64 end else local tslots = {} local _, suc = slots:gsub("(%d+)=?(%d*),?", function(k, v) local num = tonumber(k) if not num then printError("Cannot convert "..str.." to a slot number.") return end tslots[num] = v and tonumber(v) or 64 end) if suc == 0 then printError("Cannot parse slot listing '"..slots.."'.") end slots = tslots end local modem = settings.get("shironeko.send.modem") settings.define("shironeko.send.modem", { description = "Name of the modem that the send CLI scripts use. If unset, scripts will automatically find a suitable wireless modem.", type = "string" }) if modem then if not peripheral.isPresent(modem) then printError("Modem "..modem.." from 'shironeko.send.modem' does not exist. Please set a valid modem or unset the setting.") return end else for _, m in ipairs(table.pack(peripheral.find("modem"))) do if m.isWireless() then modem = peripheral.getName(m) break end end if not (modem and peripheral.isPresent(modem)) then printError("Suitable modem not found! Either place a wireless modem, or set a modem using 'shironeko.send.modem'.") return end end local errmap = { no_such_label_sender = "No such sender label \""..(fromLabel or "main").."\".", no_outbound_storage = "Label \""..(fromLabel or "main").."\" lacks a tagged outbound storage.", no_such_label_recipient = "No such recipient label \""..(toLabel or "main").."\".", no_inbound_storage = "Label \""..(toLabel or "main").."\" lacks a tagged inbound storage.", no_such_user = "User "..user.." is not a registered Shironeko user.", blocked = "You have been blocked from sending to this recipient and label.", recipient_full = "Recipient box is full and cannot accept any more items.", same_storage = "Cannot send to the same storage.", version = "Please update shironeko! Use the same command you used to install the programs (found with \\sn me).", timeout = "No response from Shironeko." } local api = sn.init(modem) local ok, res = api.send(user, slots, fromLabel, toLabel) if not ok then printError(errmap[res] or "Unknown error "..res) else local total = 0 for _, item in ipairs(res.items) do total = total+item.count end print("Sent "..total.." items to "..user.."'s "..(fromLabel or "main").." label from your "..(toLabel or "main").." label.") end api.close()