From ac6bae3f85c7b42b048aca077f847c9733774067 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Sun, 14 Mar 2021 22:51:53 -0600 Subject: [PATCH 1/5] Added modpol.menu() functions modpol and modpol_minetest. Not sure if latter works. --- README.md | 16 +++++++++++----- modpol/interactions/interactions.lua | 14 ++++++++++++++ modpol/modpol.lua | 1 - modpol_minetest/chatcommands/chatcommands.lua | 12 ++++++++++++ .../overrides/interactions/interactions.lua | 15 ++++++++++++++- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a982acc..3b7a145 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# modpol: Modular Politics Prototype for Minetest +# Modular Politics Prototype for Minetest This is a mod for [Minetest](https://minetest.net) that enables diverse governance mechanisms. It seeks to implement the [Modular Politics](https://metagov.org/modpol) proposal. Ideally, in the future, it will be possible to use this framework to simulate governance in a @@ -20,6 +20,8 @@ $ lua > dofile("modpol.lua") ``` +For a list of global functions and tables, use `modpol.menu()`. + ## Minetest To use this in Minetest, simply install it as a Minetest mod. Minetest @@ -42,7 +44,8 @@ By default, a data directory named "data" will be created in this director Another storage method may be chosen in modpol.lua. A StorageRef-based method for Minetest 5.* is included: storage-mod_storage.lua. -## Stand-alone Modular Politics + +## Standalone Modular Politics To separate the Modular Politics core from the Minetest mod, simply remove these files: @@ -58,13 +61,16 @@ depends.txt Eventually the stand-alone modpol package will be published as a separate repo. -## Authorship +## Credits Initiated by [Nathan Schneider](https://nathanschneider.info) of the [Media Enterprise Design Lab](https://colorado.edu/lab/medlab) at the University of Colorado Boulder, as part of the [Metagovernance Project](https://metagov.org). Based on the paper "[Modular Politics: Toward a Governance Layer for Online Communities](https://metagov.org/modpol)." -We'd love to have 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). +Thanks to contributors: -Thanks to contributors: Robert Kiraly [[OldCoder](https://github.com/oldcoder/)] (ocutils.lua, storage-local.lua, project refactoring), [MisterE](https://gitlab.com/gbrrudmin) (project refactoring, core feature development) +* [MisterE](https://gitlab.com/gbrrudmin) (project refactoring, core feature development) +* Robert Kiraly [[OldCoder](https://github.com/oldcoder/)] (ocutils.lua, storage-local.lua, project refactoring) + +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). ## Licenses diff --git a/modpol/interactions/interactions.lua b/modpol/interactions/interactions.lua index 85feeb4..35ab67c 100644 --- a/modpol/interactions/interactions.lua +++ b/modpol/interactions/interactions.lua @@ -3,6 +3,20 @@ -- User interaction functions for Modular Politics -- Called by modpol.lua +-- =================================================================== +-- Function: modpol.menu(user) +-- Params: user (string) +-- Q: Should this return a menu of commands relevant to the specific user? +-- Output: Displays a menu of commands to the user +-- TKTK currently just prints all of modpol---needs major improvement +modpol.menu = function(user) + local output = "Command list:\n" + for key,value in pairs(modpol) do + output = output .. "- modpol." .. key .. "\n" + end + print(output) +end + -- =================================================================== -- Function: modpol.binary_poll_user(user, question) -- Params: user (string), question (string) diff --git a/modpol/modpol.lua b/modpol/modpol.lua index b0d2ce7..0035a09 100644 --- a/modpol/modpol.lua +++ b/modpol/modpol.lua @@ -70,7 +70,6 @@ modpol.load_storage() -- =================================================================== -- ModPol core features - dofile (topdir .. "/api.lua") diff --git a/modpol_minetest/chatcommands/chatcommands.lua b/modpol_minetest/chatcommands/chatcommands.lua index 4c848e4..774c044 100644 --- a/modpol_minetest/chatcommands/chatcommands.lua +++ b/modpol_minetest/chatcommands/chatcommands.lua @@ -7,6 +7,18 @@ local regchat -- Chat-command registration function regchat = minetest.register_chatcommand +-- =================================================================== +-- /menu +-- Presents a menu of options to users +minetest.register_chatcommand( + "menu", { + privs = {}, + func = function(user) + local result = modpol.menu(user) + return true, result + end, +}) + -- =================================================================== -- /addorg /add_org -- This code defines a chat command which creates a new diff --git a/modpol_minetest/overrides/interactions/interactions.lua b/modpol_minetest/overrides/interactions/interactions.lua index 34560fe..eaf9dff 100644 --- a/modpol_minetest/overrides/interactions/interactions.lua +++ b/modpol_minetest/overrides/interactions/interactions.lua @@ -1,4 +1,17 @@ +-- =================================================================== +-- Function: modpol.menu(user) +-- Params: user (string) +-- Q: Should this return a menu of commands relevant to the specific user? +-- Output: Displays a menu of commands to the user +-- TKTK currently a manually curated list---needs major improvement +modpol.menu = function(user) + local output = "Command list:" + for key,value in pairs(chat_table) do + output = output .. "/" .. key .. "\n" + end + return output +end -- =================================================================== -- Function: modpol.binary_poll_user(user, question) @@ -41,4 +54,4 @@ modpol.binary_poll_user = function(user, question) else -- if the form is not a recognized name return end -end) \ No newline at end of file +end) From ebfd270b25eafb226344084664c2a6e9836a4214 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Sun, 14 Mar 2021 22:52:57 -0600 Subject: [PATCH 2/5] Slight README update --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 3b7a145..c563ce3 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,7 @@ To use this in Minetest, simply install it as a Minetest mod. Minetest will load init.lua. See the source code for information about chat commands which can then be used. -Most of these commands will later be buried under other commands that -do more privilege checking. These are mainly for testing purposes. - -* `/addorg [orgname]` - Create a new org -* `/listorgs` - Lists the orgs (and their members) currently in existence -* `/listplayers` - Lists all the players currently in the game -* `/joinorg [orgname]` - Adds the user to the specified org -* `/pollself [question]` - Asks the player a yes/no/abstain question +Use the `/menu` command to see a list of registered chat commands. ## Storage From f255a057e516735190667b05f3275f9daa165f11 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Mon, 15 Mar 2021 19:26:16 +0000 Subject: [PATCH 3/5] changed minetest chat function regchat to create command_list table --- modpol_minetest/chatcommands/chatcommands.lua | 14 ++++++++++---- .../overrides/interactions/interactions.lua | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modpol_minetest/chatcommands/chatcommands.lua b/modpol_minetest/chatcommands/chatcommands.lua index 774c044..b8e801f 100644 --- a/modpol_minetest/chatcommands/chatcommands.lua +++ b/modpol_minetest/chatcommands/chatcommands.lua @@ -4,13 +4,19 @@ local chat_table -- MT chat command definitions table local regchat -- Chat-command registration function +local command_list -- user-facing list of commands regchat = minetest.register_chatcommand +regchat = function(name, command_table) + minetest.register_chatcommand(name, command_table) + table.insert(command_list, name) +end + -- =================================================================== -- /menu -- Presents a menu of options to users -minetest.register_chatcommand( +regchat( "menu", { privs = {}, func = function(user) @@ -56,7 +62,7 @@ regchat ("list_orgs" , chat_table) -- =================================================================== -- /listplayers -minetest.register_chatcommand( +regchat( "listplayers", { privs = {}, func = function(user) @@ -67,7 +73,7 @@ minetest.register_chatcommand( -- =================================================================== -- /joinorg -minetest.register_chatcommand( +regchat( "joinorg", { privs = {}, func = function(user, param) @@ -81,7 +87,7 @@ minetest.register_chatcommand( -- =================================================================== -- /pollself [question] -- asks the user a question specified in param -minetest.register_chatcommand( +regchat( "pollself", { privs = {}, func = function(user, param) diff --git a/modpol_minetest/overrides/interactions/interactions.lua b/modpol_minetest/overrides/interactions/interactions.lua index eaf9dff..800cea9 100644 --- a/modpol_minetest/overrides/interactions/interactions.lua +++ b/modpol_minetest/overrides/interactions/interactions.lua @@ -7,7 +7,7 @@ -- TKTK currently a manually curated list---needs major improvement modpol.menu = function(user) local output = "Command list:" - for key,value in pairs(chat_table) do + for key,value in pairs(command_list) do output = output .. "/" .. key .. "\n" end return output From 3b31dffe670a97049598b51706ea5e71d2d41def Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Mon, 15 Mar 2021 19:28:05 +0000 Subject: [PATCH 4/5] Made command_list a table --- modpol_minetest/chatcommands/chatcommands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modpol_minetest/chatcommands/chatcommands.lua b/modpol_minetest/chatcommands/chatcommands.lua index b8e801f..e9e633f 100644 --- a/modpol_minetest/chatcommands/chatcommands.lua +++ b/modpol_minetest/chatcommands/chatcommands.lua @@ -4,7 +4,7 @@ local chat_table -- MT chat command definitions table local regchat -- Chat-command registration function -local command_list -- user-facing list of commands +local command_list = {} -- user-facing list of commands regchat = minetest.register_chatcommand From 1b770a987b470c574789e821e75ca5f0e01ee752 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Mon, 15 Mar 2021 18:08:06 -0600 Subject: [PATCH 5/5] Various bugfixes on orgs and minetest chatcommands --- init.lua | 1 - modpol_minetest/chatcommands/chatcommands.lua | 18 +++++++++++++++++- modpol_minetest/orgs/instance.lua | 4 ++-- .../overrides/interactions/interactions.lua | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 06928af..08bbb39 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,5 @@ modpol = {} - -- =================================================================== --preoverrides: certain things must be predefined in the global table for them to have effect (or cmd line version defualts are used) -- =================================================================== diff --git a/modpol_minetest/chatcommands/chatcommands.lua b/modpol_minetest/chatcommands/chatcommands.lua index e9e633f..3d07033 100644 --- a/modpol_minetest/chatcommands/chatcommands.lua +++ b/modpol_minetest/chatcommands/chatcommands.lua @@ -2,9 +2,10 @@ -- Minetest commands -- =================================================================== +command_list = {} -- user-facing table of commands + local chat_table -- MT chat command definitions table local regchat -- Chat-command registration function -local command_list = {} -- user-facing list of commands regchat = minetest.register_chatcommand @@ -25,6 +26,21 @@ regchat( end, }) +-- =================================================================== +-- /reset +-- For testing only +-- Clears the system and recreates instance with all players +regchat( + "reset", { + privs = {}, + func = function(user) + modpol.reset_orgs(); + return true, "Reset orgs" + end, +}) + + + -- =================================================================== -- /addorg /add_org -- This code defines a chat command which creates a new diff --git a/modpol_minetest/orgs/instance.lua b/modpol_minetest/orgs/instance.lua index 8e2ea50..99c1d98 100644 --- a/modpol_minetest/orgs/instance.lua +++ b/modpol_minetest/orgs/instance.lua @@ -2,5 +2,5 @@ minetest.register_on_joinplayer(function(player) local p_name = player:get_player_name() - modpol.add_member("instance", p_name) -end) \ No newline at end of file + modpol.add_member(1, p_name) +end) diff --git a/modpol_minetest/overrides/interactions/interactions.lua b/modpol_minetest/overrides/interactions/interactions.lua index 800cea9..7e37b6b 100644 --- a/modpol_minetest/overrides/interactions/interactions.lua +++ b/modpol_minetest/overrides/interactions/interactions.lua @@ -8,7 +8,7 @@ modpol.menu = function(user) local output = "Command list:" for key,value in pairs(command_list) do - output = output .. "/" .. key .. "\n" + output = output .. "/" .. value .. " " end return output end