2
0

chatcommands.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. -- /menu
  14. -- Presents a menu of options to users
  15. regchat(
  16. "menu", {
  17. privs = {},
  18. func = function(user)
  19. local result = modpol.menu(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.reset_orgs();
  32. return true, "Reset orgs"
  33. end,
  34. })
  35. -- ===================================================================
  36. -- /addorg /add_org
  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. chat_table = {
  41. privs = {} ,
  42. func = function (user, param)
  43. local success, message = modpol.add_org (param, { user })
  44. return true, message
  45. end
  46. }
  47. regchat ("addorg" , chat_table)
  48. regchat ("add_org" , chat_table)
  49. -- ===================================================================
  50. -- /listorg /listorgs /list_org /list_orgs
  51. -- In Minetest mode, this code defines a chat command which lists the
  52. -- existing "orgs".
  53. -- The list shows one "org" per line in the following format:
  54. -- org_name (member, member, ...)
  55. chat_table = {
  56. privs = {} ,
  57. func = function (user, param)
  58. return true, "Orgs:\n" .. modpol.list_orgs()
  59. end
  60. }
  61. regchat ("listorg" , chat_table)
  62. regchat ("listorgs" , chat_table)
  63. regchat ("list_org" , chat_table)
  64. regchat ("list_orgs" , chat_table)
  65. -- ===================================================================
  66. -- /listplayers
  67. regchat(
  68. "listplayers", {
  69. privs = {},
  70. func = function(user)
  71. local result = table.concat(modpol.list_users(),", ")
  72. return true, "All players: " .. result
  73. end,
  74. })
  75. -- ===================================================================
  76. -- /joinorg
  77. regchat(
  78. "joinorg", {
  79. privs = {},
  80. func = function(user, param)
  81. local org_id = modpol.get_org_id_by_name(param)
  82. local success, result = modpol.add_member(org_id, user)
  83. return true, result
  84. end,
  85. })
  86. -- ===================================================================
  87. -- /pollself [question]
  88. -- asks the user a question specified in param
  89. regchat(
  90. "pollself", {
  91. privs = {},
  92. func = function(user, param)
  93. modpol.binary_poll_user(user, param)
  94. return true, result
  95. end,
  96. })