chatcommands.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. -- ===================================================================
  2. -- Minetest commands
  3. -- ===================================================================
  4. command_list = {} -- user-facing table of commands
  5. local chat_table -- MT chat command definitions table
  6. local regchat -- Chat-command registration function
  7. regchat = minetest.register_chatcommand
  8. regchat = function(name, command_table)
  9. minetest.register_chatcommand(name, command_table)
  10. table.insert(command_list, name)
  11. end
  12. -- ===================================================================
  13. -- /dashboard
  14. -- Presents a menu of options to users
  15. regchat(
  16. "dashboard", {
  17. privs = {},
  18. func = function(user)
  19. local result = modpol.dashboard(user)
  20. return true, result
  21. end,
  22. })
  23. -- ===================================================================
  24. -- /reset
  25. -- For testing only
  26. -- Clears the system and recreates instance with all players
  27. regchat(
  28. "reset", {
  29. privs = {},
  30. func = function(user)
  31. modpol.orgs.reset();
  32. return true, "Reset orgs"
  33. end,
  34. })
  35. -- ===================================================================
  36. -- /addorg
  37. -- This code defines a chat command which creates a new
  38. -- "org". Presently, the command makes the user the sole member of the
  39. -- "org".
  40. regchat(
  41. "addorg", {
  42. privs = {} ,
  43. func = function (user, param)
  44. local success, message = modpol.instance:add_org (param)
  45. return true, message
  46. end
  47. })
  48. -- ===================================================================
  49. -- /listorg
  50. -- In Minetest mode, this code defines a chat command which lists the
  51. -- existing "orgs".
  52. -- The list shows one "org" per line in the following format:
  53. -- org_name (member, member, ...)
  54. regchat(
  55. "listorg", {
  56. privs = {} ,
  57. func = function (user, param)
  58. return true, "Orgs:\n" .. modpol.orgs.list_all()
  59. end
  60. })
  61. -- ===================================================================
  62. -- /listplayers
  63. regchat(
  64. "listplayers", {
  65. privs = {},
  66. func = function(user)
  67. local result = table.concat(modpol.list_users(),", ")
  68. return true, "All players: " .. result
  69. end,
  70. })
  71. -- ===================================================================
  72. -- /joinorg
  73. regchat(
  74. "joinorg", {
  75. privs = {},
  76. func = function(user, param)
  77. local org = modpol.orgs.get_org(param)
  78. local success, result = org:add_member(user)
  79. return true, result
  80. end,
  81. })
  82. -- ===================================================================
  83. -- /pollself [question]
  84. -- asks the user a question specified in param
  85. regchat(
  86. "pollself", {
  87. privs = {},
  88. func = function(user, param)
  89. modpol.binary_poll_user(user, param)
  90. return true, result
  91. end,
  92. })