commands.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. local function currency_exists() end
  2. minetest.register_privilege("currencies_admin", {
  3. description = "It allows you to use /currencies"
  4. })
  5. ChatCmdBuilder.new("currencies", function(cmd)
  6. cmd:sub("add :plname :currency :amount:int", function(name, pl_name, currency, amount)
  7. if not currency_exists(pl_name, currency) then return end
  8. currencies.add(currency, pl_name, amount)
  9. currencies.print_msg(
  10. name,
  11. "+ " .. amount .. ", ".. pl_name .. "'s " .. currency .. " balance: " .. currencies.get(currency, pl_name)
  12. )
  13. end)
  14. cmd:sub("sub :plname :currency :amount:int", function(name, pl_name, currency, amount)
  15. if not currency_exists(pl_name, currency) then return end
  16. currencies.sub(currency, pl_name, amount)
  17. currencies.print_msg(
  18. name,
  19. "- " .. amount .. ", ".. pl_name .. "'s " .. currency .. " balance: " .. currencies.get(currency, pl_name)
  20. )
  21. end)
  22. cmd:sub("set :plname :currency :amount:int", function(name, pl_name, currency, amount)
  23. if not currency_exists(pl_name, currency) then return end
  24. currencies.set(currency, pl_name, amount)
  25. currencies.print_msg(name, pl_name .. "'s " .. currency .. " balance: " .. currencies.get(currency, pl_name))
  26. end)
  27. cmd:sub("balance :plname :currency", function(name, pl_name, currency)
  28. if not currency_exists(pl_name, currency) then return end
  29. currencies.print_msg(name, pl_name .. "'s " .. currency .. " balance: " .. currencies.get(currency, pl_name))
  30. end)
  31. cmd:sub("clearunregistered", function(name)
  32. currencies.remove_unregistered()
  33. currencies.print_msg(name, "Removed unregistered currencies from the database")
  34. end)
  35. cmd:sub("clearbalance :plname :currency", function(name, pl_name, currency)
  36. if not currency_exists(pl_name, currency) then return end
  37. currencies.clear_balance(currency, pl_name)
  38. currencies.print_msg(name, "Cleared " .. pl_name .. "'s " .. currency .. " balance")
  39. end)
  40. cmd:sub("clearbalance :plname", function(name, pl_name)
  41. currencies.clear_balance(nil, pl_name)
  42. currencies.print_msg(name, "Cleared " .. pl_name .. "'s balances")
  43. end)
  44. end, {
  45. description = [[
  46. ADMIN COMMANDS
  47. (Use /help currencies to read it all)
  48. - balance <pl_name> <currency>
  49. - set <pl_name> <currency> <amount>
  50. - add <pl_name> <currency> <amount>
  51. - sub <pl_name> <currency> <amount>
  52. - clearunregistered: removes from the database every unregistered currency
  53. - clearbalance <pl_name> [currency]: if the currency isn't specified it'll reset each one of them
  54. ]],
  55. privs = {currencies_admin = true}
  56. })
  57. function currency_exists(pl_name, currency)
  58. if not currencies.exists(currency) then
  59. currencies.print_error(pl_name, "The " .. currency .. " currency doesn't exist")
  60. return false
  61. end
  62. return true
  63. end