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. -- /modpol
  14. -- Presents a menu of options to users
  15. regchat(
  16. "modpol", {
  17. privs = {},
  18. func = function(user)
  19. modpol.interactions.dashboard(user)
  20. end,
  21. })
  22. -- ===================================================================
  23. -- /reset
  24. -- For testing only
  25. -- Clears the system and recreates instance with all players
  26. regchat(
  27. "reset", {
  28. privs = {},
  29. func = function(user)
  30. modpol.orgs.reset();
  31. return true, "Reset orgs"
  32. end,
  33. })
  34. -- ===================================================================
  35. -- /addorg
  36. -- This code defines a chat command which creates a new
  37. -- "org". Presently, the command makes the user the sole member of the
  38. -- "org".
  39. regchat(
  40. "addorg", {
  41. privs = {} ,
  42. func = function (user, param)
  43. local success, message = modpol.instance:add_org (param)
  44. return true, message
  45. end
  46. })
  47. -- ===================================================================
  48. -- /listorgs
  49. -- In Minetest mode, this code defines a chat command which lists
  50. -- existing "orgs".
  51. -- The list shows one "org" per line in the following format:
  52. -- org_name (member, member, ...)
  53. regchat(
  54. "listorgs", {
  55. privs = {} ,
  56. func = function (user, param)
  57. return true, "Orgs: " ..
  58. table.concat(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.interactions.binary_poll_user(user, param)
  90. return true, result
  91. end,
  92. })