processes.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. -- ===================================================================
  2. -- /processes.lua
  3. -- Process-related functions for Modular Politics
  4. -- Called by modpol.lua
  5. -- TKTK may need to create high-level modpol.processes table to hold ongoing processes
  6. -- TKTK in order to enable async processes. Rewrite all this as listeners
  7. -- ===================================================================
  8. -- Function: modpol.consent
  9. -- Params: org (string), proposal (string)
  10. -- Outputs: boolean - true if consent achieved or false; nil on error
  11. -- Also includes a table of responses
  12. -- This is the default decision-making routine for Modular Politics
  13. -- Stops at the first "No" vote
  14. modpol.consent = function(org, query)
  15. -- Check that org exists
  16. if modpol.orgs[org] == nil then
  17. return nil, "Error: Org does not exist"
  18. end
  19. -- Poll all members
  20. local responses = {}
  21. for index, value in ipairs(modpol.orgs[org]["members"]) do
  22. local response = modpol.binary_poll_user(value, query)
  23. responses[value] = response
  24. if response == "No" then
  25. return false, responses
  26. end
  27. end
  28. return true, responses
  29. end
  30. -- TKTK exploring modpol.initiate functions, which have no args
  31. -- Need to properly document these
  32. modpol.initiate = {}
  33. modpol.initiate.consent = function(org)
  34. print("What is your query?")
  35. local query = io.read()
  36. return modpol.consent(org, query)
  37. end
  38. -- Function: modpol.switchboard
  39. -- Params: org (string), routine (string)
  40. -- Outputs: Checks the org for any policies related to a given function;
  41. -- Calls the modpol.initiate.* function(org) based on policy
  42. -- Defaults to modpol.initiate.consent()
  43. modpol.switchboard = function(org, routine)
  44. if modpol.orgs[org]["policies"]
  45. and modpol.orgs[org]["policies"][routine] then
  46. -- TKTK if there exists a policy
  47. else
  48. modpol.initiate.consent(org)
  49. end
  50. end