diff --git a/c4mate b/c4mate index 7e28490..85366cc 100755 --- a/c4mate +++ b/c4mate @@ -271,6 +271,17 @@ function MatePad:buy(id) url_encode(self.USER), id, self.token)) end +-- Return id of last bought item in log. +function MatePad:last_bought() + local log = self:parse_log() + for i = 1, #log do + if log[i].method == "buy" then + return log[i].parameter + end + end + return nil +end + -- Set new balance (in cents). function MatePad:set_balance(amount) return self:fetch(string.format( @@ -301,14 +312,14 @@ Display current balance: c4mate Find and buy item (interactive): c4mate -Buy by item id (non-interactive): +Buy by item id (non-interactive, special id '0' will re-buy last item in log): c4mate -b|--buy Show log: c4mate -l|--log Add or subtract credits: c4mate +/- Give credits: - c4mate -g []]=]) + c4mate -g|--give []]=]) os.exit(0) end @@ -373,6 +384,8 @@ elseif arg[1] == "-b" or arg[1] == "--buy" then return end + if id == 0 then id = pad:last_bought() end + pad:init() if pad:buy(id) == "OK" then pad:update_balance()