diff --git a/config.lua b/config.lua index 48847f5..00522bd 100644 --- a/config.lua +++ b/config.lua @@ -12,6 +12,7 @@ }, lang = { footer = "/pay @%name% ", + footerNoName = "/pay %addr% ", refundRemaining = "Here is the funds remaining after your purchase!", refundOutofStock = "Sorry, that item is out of stock!", refundAtLeastOne = "You must purchase at least one of this product!", diff --git a/core/ConfigValidator.lua b/core/ConfigValidator.lua index 17d1c28..f9b2405 100644 --- a/core/ConfigValidator.lua +++ b/core/ConfigValidator.lua @@ -14,6 +14,7 @@ }, lang = { footer = "string", + footerNoName = "string?", refundRemaining = "string", refundOutOfStock = "string", refundAtLeastOne = "string", @@ -87,7 +88,7 @@ id = "string", node = "string?", host = [[regex<^\w{10}$>: address]], - name = "string", + name = "string?", pkey = "string", pkeyFormat = "enum<'raw' | 'kristwallet'>: pkey format", value = "number?" diff --git a/core/ShopState.lua b/core/ShopState.lua index 5c75395..428fff8 100644 --- a/core/ShopState.lua +++ b/core/ShopState.lua @@ -29,12 +29,15 @@ local function parseMeta(transactionMeta) local meta = {} + local i = 1 for metaEntry in transactionMeta:gmatch("([^;]+)") do if metaEntry:find("=") then local key, value = metaEntry:match("([^=]+)=([^=]+)") meta[key] = value else meta[metaEntry] = true + meta[i] = metaEntry + i = i + 1 end end return meta @@ -92,7 +95,7 @@ if purchasedProduct.quantity and purchasedProduct.quantity > 0 then local productSources, available = ScanInventory.findProductItems(state.products, purchasedProduct, amountPurchased) local refundAmount = math.floor(transaction.value - (available * productPrice)) - print("Purchased " .. available .. " of " .. purchasedProduct.name .. " for " .. transaction.from .. " for " .. transaction.value .. " " .. transactionCurrency.name .. " (refund " .. refundAmount .. ")") + print("Purchased " .. available .. " of " .. purchasedProduct.name .. " for " .. transaction.from .. " for " .. transaction.value .. " " .. transactionCurrency.id .. " (refund " .. refundAmount .. ")") if available > 0 then for _, productSource in ipairs(productSources) do if state.config.peripherals.outputChest == "self" then @@ -173,11 +176,14 @@ local sentName = transaction.sent_name local sentMetaname = transaction.sent_metaname local nameSuffix = transactionCurrency.krypton.currency.name_suffix - if sentName and transactionCurrency.name:find(".") then + if sentName and transactionCurrency.name and transactionCurrency.name:find(".") then sentName = sentName .. "." .. nameSuffix end - if sentName and sentName:lower() == transactionCurrency.name:lower() then + if not transactionCurrency.name or sentName and sentName:lower() == transactionCurrency.name:lower() then local meta = parseMeta(transaction.metadata) + if transaction.to == transactionCurrency.host and not transactionCurrency.name and not sentMetaname then + sentMetaname = meta[1] + end if sentMetaname then local success, err = pcall(handlePurchase, transaction, meta, sentMetaname, transactionCurrency, transactionCurrency, state) if success then diff --git a/radon.lua b/radon.lua index 2dc6513..2034776 100644 --- a/radon.lua +++ b/radon.lua @@ -1,7 +1,7 @@ local oldPullEvent = os.pullEvent os.pullEvent = os.pullEventRaw -local version = "1.1.2" +local version = "1.1.3" --- Imports local _ = require("util.score") @@ -59,10 +59,9 @@ end local function getCurrencySymbol(currency, productTextSize) - local currencySymbol if currency.krypton and currency.krypton.currency then currencySymbol = currency.krypton.currency.currency_symbol - elseif not currencySymbol and currency.name:find("%.") then + elseif not currencySymbol and currency.name and currency.name:find("%.") then currencySymbol = currency.name:sub(currency.name:find("%.")+1, #currency.name) elseif currency.id == "tenebra" then currencySymbol = "tst" @@ -165,10 +164,21 @@ table.insert(flatCanvas, header) - local footerMessage = props.config.lang.footer - if footerMessage:find("%%name%%") then + local footerMessage + if props.shopState.selectedCurrency.name or not props.config.lang.footerNoName then + footerMessage = props.config.lang.footer + else + footerMessage = props.config.lang.footerNoName + end + if props.shopState.selectedCurrency.name and footerMessage:find("%%name%%") then footerMessage = footerMessage:gsub("%%name%%", props.shopState.selectedCurrency.name) end + if footerMessage:find("%%addr%%") then + footerMessage = footerMessage:gsub("%%addr%%", props.shopState.selectedCurrency.host) + end + if footerMessage:find("%%version%%") then + footerMessage = footerMessage:gsub("%%version%%", version) + end if props.shopState.selectedCurrency then local footer @@ -225,12 +235,16 @@ for i = 1, #shopProducts do local product = shopProducts[i] local productAddr = product.address .. "@" - if productTextSize == "small" then - if props.config.settings.smallTextKristPayCompatability then - productAddr = product.address .. "@" .. props.shopState.selectedCurrency.name - else - productAddr = product.address .. "@ " + if props.shopState.selectedCurrency.name then + if productTextSize == "small" then + if props.config.settings.smallTextKristPayCompatability then + productAddr = product.address .. "@" .. props.shopState.selectedCurrency.name + else + productAddr = product.address .. "@ " + end end + else + productAddr = product.address end product.quantity = product.quantity or 0 local productPrice = Pricing.getProductPrice(product, props.shopState.selectedCurrency) @@ -274,12 +288,20 @@ productNameColor = theme.colors.outOfStockNameColor end local productAddr = product.address .. "@" - if productTextSize == "small" then - if props.config.settings.smallTextKristPayCompatability then - productAddr = product.address .. "@" .. props.shopState.selectedCurrency.name - else - productAddr = product.address .. "@ " + if props.shopState.selectedCurrency.name then + if productTextSize == "small" then + if props.config.settings.smallTextKristPayCompatability then + productAddr = product.address .. "@" .. props.shopState.selectedCurrency.name + else + productAddr = product.address .. "@ " + end end + else + productAddr = product.address + end + local kristpayHelperText = props.shopState.selectedCurrency.host + if props.shopState.selectedCurrency.name then + kristpayHelperText = product.address .. "@" .. props.shopState.selectedCurrency.name end local productBgColor = theme.colors.productBgColors[((i-1) % #theme.colors.productBgColors) + 1] if productTextSize == "large" then @@ -330,13 +352,13 @@ table.insert(flatCanvas, BasicText { key="invis-" .. catName .. tostring(product.id), display=display, - text=product.address .. "@" .. props.shopState.selectedCurrency.name, + text=kristpayHelperText, x=1, y=1+(i*5), align="center", bg=productBgColor, color=productBgColor, - width=#(product.address .. "@" .. props.shopState.selectedCurrency.name) + width=#(kristpayHelperText) }) elseif productTextSize == "medium" then table.insert(flatCanvas, SmolText { @@ -386,13 +408,13 @@ table.insert(flatCanvas, BasicText { key="invis-" .. catName .. tostring(product.id), display=display, - text=product.address .. "@" .. props.shopState.selectedCurrency.name, + text=kristpayHelperText, x=1, y=3+(i*3), align="center", bg=productBgColor, color=productBgColor, - width=#(product.address .. "@" .. props.shopState.selectedCurrency.name) + width=#(kristpayHelperText) }) else table.insert(flatCanvas, BasicText {