processes.lua 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.switchboard
  9. -- Params: org (string), routine (string)
  10. -- Outputs: Checks the org for any policies related to a given function;
  11. -- Calls the modpol.initiate.* function(org) based on policy
  12. -- Defaults to modpol.initiate.consent()
  13. modpol.switchboard = function(org, routine)
  14. if modpol.orgs[org]["policies"]
  15. and modpol.orgs[org]["policies"][routine] then
  16. -- TKTK if there exists a policy, initiate that function
  17. else
  18. modpol.initiate.consent(org)
  19. end
  20. end
  21. -- ===================================================================
  22. -- TKTK
  23. -- Function: modpol.delegate
  24. -- Delegates a process from one org to another
  25. -- ===================================================================
  26. -- Basic decision functions
  27. -- ===================================================================
  28. -- ===================================================================
  29. -- Function: modpol.consent
  30. -- Params: org (string), proposal (string)
  31. -- Outputs: boolean - true if consent achieved or false; nil on error
  32. -- Also includes a table of responses
  33. -- This is the default decision-making routine for Modular Politics
  34. -- Stops at the first "No" vote
  35. modpol.consent = function(org, query)
  36. -- Check that org exists
  37. if modpol.orgs[org] == nil then
  38. return nil, "Error: Org does not exist"
  39. end
  40. -- Poll all members
  41. local responses = {}
  42. for index, value in ipairs(modpol.orgs[org]["members"]) do
  43. local response = modpol.binary_poll_user(value, query)
  44. responses[value] = response
  45. if response == "No" then
  46. return false, responses
  47. end
  48. end
  49. return true, responses
  50. end
  51. -- ===================================================================
  52. -- Function: modpol.approved
  53. -- A simple function for automatically approved processes
  54. -- Params: none
  55. -- Outputs: boolean - true
  56. modpol.approved = function()
  57. -- Check that org exists
  58. if modpol.orgs[org] == nil then
  59. return nil, "Error: Org does not exist"
  60. end
  61. return true
  62. end
  63. -- ===================================================================
  64. -- Experimental
  65. -- ===================================================================
  66. -- ===================================================================
  67. -- TKTK exploring modpol.initiate functions, which have no args
  68. -- Need to properly document these
  69. modpol.initiate = {}
  70. modpol.initiate.consent = function(org)
  71. print("What is your query?")
  72. local query = io.read()
  73. return modpol.consent(org, query)
  74. end