interactions.lua 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. -- ===================================================================
  2. -- /orgs.lua
  3. -- User interaction functions for Modular Politics
  4. -- Called by modpol.lua
  5. modpol.interactions = {}
  6. -- ===================================================================
  7. -- Function: modpol.dashboard(user)
  8. -- Params: user (string)
  9. -- Q: Should this return a menu of commands relevant to the specific user?
  10. -- Output: Displays a menu of commands to the user
  11. -- TKTK currently just prints all of modpol---needs major improvement
  12. function modpol.dashboard(user)
  13. local output = ""
  14. -- Org status
  15. output = output .. "Orgs:\n" ..
  16. table.concat(modpol.orgs.list_all(),"\n")
  17. -- Process status (ongoing processes)
  18. output = output .. "\nProcesses:\n" .. table.concat(modpol.processes)
  19. -- Command list (should be redone to be org-specific)
  20. output = output .. "\nCommand list:\n"
  21. for key,value in pairs(modpol) do
  22. output = output .. "modpol." .. key .. " "
  23. end
  24. print(output)
  25. end
  26. -- ===================================================================
  27. -- Function: modpol.interactions.message
  28. -- input: user (string), message (string)
  29. -- output: prints message to CLI
  30. function modpol.interactions.message(user, message)
  31. print(user .. ": " .. message)
  32. end
  33. -- ===================================================================
  34. -- Function: modpol.interactions.text_query
  35. -- input: Query (string)
  36. -- output: User response (string)
  37. function modpol.interactions.text_query(query)
  38. -- TODO
  39. end
  40. -- ===================================================================
  41. -- Function: modpol.binary_poll_user(user, question)
  42. -- Params: user (string), question (string)
  43. -- Output:
  44. -- presents a yes/no/abstain poll to a user, returns answer
  45. function modpol.interactions.binary_poll_user(user, question)
  46. local query = "Poll for " .. user .. " (y/n): ".. question
  47. local answer
  48. repeat
  49. print(query)
  50. answer = io.read()
  51. until answer == "y" or answer == "n" or answer == "a"
  52. if answer == "y" then
  53. return "Yes"
  54. elseif answer == "n" then
  55. return "No"
  56. else
  57. return "Abstain"
  58. end
  59. end