CLI interactions updated for modules-as-actions

This commit is contained in:
Nathan Schneider 2021-12-16 15:07:26 -07:00
parent fa7a0f82f6
commit 28e2710efc
3 changed files with 45 additions and 50 deletions

View File

@ -19,12 +19,12 @@ In the game, open the Modular Politics interface with the command `/modpol`.
Modular Politics can also be used independently of Minetest as a command-line tool. Currently command-line use of modpol requires a Unix-style system, but it is intended to become more fully platform independent.
The command-line version is in the `modpol` subdirectory. To interact with the interpreter on Unix systems in CLI mode, install lua or luajit and execute the following command in this directory:
The command-line version is in the `modpol` subdirectory. To interact with the interpreter on Unix systems in CLI mode, install lua or luajit and execute the following in this directory:
```
$ cd modpol/
$ cd modpol/interacctions/
$ lua [or luajit]
> dofile("modpol.lua")
> dofile("login.lua")
```
For a list of global functions and tables, use `modpol.menu()`.
@ -45,6 +45,7 @@ Other contributors include:
* [Luke Miller](https://gitlab.com/lukvmil) (main control flow, object orientation, module spec)
* [MisterE](https://gitlab.com/gbrrudmin) (project refactoring, core feature development)
* Robert Kiraly [[OldCoder](https://github.com/oldcoder/)] (ocutils.lua, storage-local.lua, project refactoring)
* Skylar Hew (documentation)
We'd love to welcome more contributors, particularly from the Minetest community! Please join the conversation in the [Issues](https://gitlab.com/medlabboulder/modpol/-/issues) or the [Minetest.net forum](https://forum.minetest.net/viewtopic.php?f=47&t=26037).

View File

@ -38,10 +38,12 @@ function modpol.interactions.dashboard(user)
local sel = io.read()
print()
local sel_org = modpol.orgs.array[tonumber(sel)].name
if not sel_org then return end
if modpol.orgs.array[tonumber(sel)] then
local sel_org = modpol.orgs.array[tonumber(sel)].name
else
return
end
modpol.interactions.org_dashboard(user, sel_org)
end
@ -53,6 +55,7 @@ function modpol.interactions.org_dashboard(user, org_name)
local org = modpol.orgs.get_org(org_name)
if not org then return nil end
-- identify parent
local parent = ""
if org.id == 1 then
parent = "none"
@ -60,66 +63,65 @@ function modpol.interactions.org_dashboard(user, org_name)
parent = modpol.orgs.get_org(org.parent).name
end
-- identify children
local children = {}
for k,v in ipairs(org.children) do
local this_child = modpol.orgs.get_org(v)
table.insert(children, this_child.name)
end
local process_msg = #org.processes .. " total"
-- list available modules
local org_modules = {}
for k,v in ipairs(org.modules) do
table.insert(org_modules, org.modules[k].slug)
end
-- list pending actions
local process_msg = #org.processes .. " total actions"
if org.pending[user] then
process_msg = process_msg .. " (" .. #org.pending[user] .. " pending)"
else
process_msg = process_msg .. " (0 pending)"
end
-- set up output
print("Org: " .. org_name)
print("Parent: " .. parent)
print("Members: " .. table.concat(org.members, ", "))
print("Children: " .. table.concat(children, ", "))
print("Processes: " .. process_msg)
print("Modules: " .. table.concat(org_modules, ", "))
print("Actions: " .. process_msg)
print()
print("Commands: (L)eave, (J)oin, (P)rocesses, (A)dd child, (D)elete org")
print("Commands: (M)odules, (A)ctions")
local sel = io.read()
print()
if sel == 'l' or sel == 'L' then
org:remove_member(user)
elseif sel == 'j' or sel == 'J' then
org:make_request({user=user, type="add_member", params={user}})
if sel == 'm' or sel == 'M' then
print("Type module name: ")
local module_sel = io.read()
print()
local module_result = false
for k,v in ipairs(org_modules) do
if v == module_sel then
module_result = true
end
end
if module_result then
org:call_module(module_sel, user)
else
print("Error: Module not found.")
end
elseif sel == 'a' or sel == 'A' then
print("What should the new org be named?")
local new_org_name = io.read()
org:make_request({user=user, type="add_org", params={new_org_name}})
elseif sel == 'd' or sel == 'D' then
org:make_request({user=user, type="delete", params={}})
elseif sel == 'p' or sel == 'P' then
local processes = {}
print("All processes: (* indicates pending action)")
for k,v in ipairs(org.processes) do
local this_request = org.requests[v.request_id]
if type(this_request) == "table" then
local active = ''
if org.pending[user] then
if org.pending[user][v.id] then
active = '*'
end
local active = ''
if org.pending[user] then
if org.pending[user][v.id] then
active = '*'
end
local req_str = "[" .. v.id .. "] " ..
active .. this_request.type
if this_request.params[1] then
req_str = req_str .. ": " ..
table.concat(this_request.params, ", ")
end
print(req_str)
end
end
print()
@ -129,14 +131,12 @@ function modpol.interactions.org_dashboard(user, org_name)
if not process then return end
if org:has_pending_actions(user) then
if org.pending[user][process.id] then
process:interact(user)
org:interact(process.id, user)
end
end
else
print("Command not found")
end
end
-- Function: modpol.interactions.policy_dashboard

View File

@ -11,14 +11,8 @@ function temp_org()
return {
id = nil,
name = nil,
policies = {
add_org={process_type='consent', must_be_member=false},
delete={process_type='consent', must_be_member=false},
add_member={process_type='consent', must_be_member=false},
remove_member={process_type='consent', must_be_member=false}
},
modules = modpol.modules,
processes = {},
-- requests = {},
pending = {},
members = {},
parent = nil,