processes.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. -- ===================================================================
  2. -- /processes.lua
  3. -- Process-related functions for Modular Politics
  4. -- Called by modpol.lua
  5. -- ===================================================================
  6. -- modpol.processes, a high-level table of active processes
  7. -- Process table structure:
  8. -- [name]: unique name
  9. -- [org]: org
  10. -- [update_functions]: table of available update functions
  11. -- [state]: table of relevant data on the state of the function
  12. modpol.processes = {}
  13. -- ===================================================================
  14. -- Function: modpol.register_process
  15. -- Adds a process to modpol.processes
  16. -- ===================================================================
  17. -- Function: modpol.delegate_process
  18. -- Delegates a process from one org to another
  19. -- ===================================================================
  20. -- Function: modpol.begin_process
  21. -- Params: user (string), org (string), action (string)
  22. -- Outputs: Checks the org for any policies related to a given action;
  23. -- Calls the modpol.initiate.* function(org) based on policy
  24. -- Defaults to modpol.initiate.consent()
  25. modpol.begin_process = function(user, org, action)
  26. if modpol.orgs[org]["policies"]
  27. and modpol.orgs[org]["policies"][routine] then
  28. -- check user org membership is satisfied
  29. -- register process
  30. -- start the appropriate process
  31. else
  32. -- register process (or does .initiate.* do that?)
  33. modpol.initiate.consent(org)
  34. end
  35. end
  36. -- ===================================================================
  37. -- Function: modpol.update_process
  38. -- ===================================================================
  39. -- Function: modpol.end_process
  40. -- ===================================================================
  41. -- Basic decision functions
  42. -- ===================================================================
  43. -- ===================================================================
  44. -- Function: modpol.consent
  45. -- Params: org (string), proposal (string)
  46. -- Outputs: boolean - true if consent achieved or false; nil on error
  47. -- Also includes a table of responses
  48. -- This is the default decision-making routine for Modular Politics
  49. -- Stops at the first "No" vote
  50. modpol.consent = function(org, query)
  51. -- Check that org exists
  52. if modpol.orgs[org] == nil then
  53. return nil, "Error: Org does not exist"
  54. end
  55. -- Poll all members
  56. local responses = {}
  57. for index, value in ipairs(modpol.orgs[org]["members"]) do
  58. local response = modpol.binary_poll_user(value, query)
  59. responses[value] = response
  60. if response == "No" then
  61. return false, responses
  62. end
  63. end
  64. return true, responses
  65. end
  66. -- ===================================================================
  67. -- Function: modpol.approved
  68. -- A simple function for automatically approved processes
  69. -- Params: none
  70. -- Outputs: boolean - true
  71. modpol.approved = function()
  72. -- Check that org exists
  73. if modpol.orgs[org] == nil then
  74. return nil, "Error: Org does not exist"
  75. end
  76. return true
  77. end
  78. -- ===================================================================
  79. -- Experimental
  80. -- ===================================================================
  81. -- ===================================================================
  82. -- TKTK exploring modpol.initiate functions, which have no args
  83. -- Need to properly document these
  84. modpol.initiate = {}
  85. modpol.initiate.consent = function(org)
  86. print("What is your query?")
  87. local query = io.read()
  88. return modpol.consent(org, query)
  89. end