Option to re-buy items
This commit is contained in:
parent
590ccdec1f
commit
3c2ddf20e1
1 changed files with 15 additions and 2 deletions
17
c4mate
17
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 <query>
|
||||
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 <id>
|
||||
Show log:
|
||||
c4mate -l|--log
|
||||
Add or subtract credits:
|
||||
c4mate +/-<amount>
|
||||
Give credits:
|
||||
c4mate -g <amount> <user> [<reason>]]=])
|
||||
c4mate -g|--give <amount> <user> [<reason>]]=])
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue