chatcommands.lua 2.6 KB

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