chatcommands.lua 2.3 KB

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