Further implementation of nested functions in interactions, including in consent module
This commit is contained in:
parent
74263b252b
commit
4e10d74bff
@ -172,3 +172,16 @@ function modpol.interactions.binary_poll_user(user, question, func)
|
|||||||
modpol.interactions.message(user, "Error: invalid response")
|
modpol.interactions.message(user, "Error: invalid response")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- COMPLEX INTERACTIONS
|
||||||
|
-- ====================
|
||||||
|
|
||||||
|
-- Function: modpol.interactions.message_org
|
||||||
|
-- input: initiator (string), org_id (number), message (string)
|
||||||
|
-- output: broadcasts message to all org members
|
||||||
|
|
||||||
|
-- Function: modpol.interactions.binary_poll_org
|
||||||
|
-- input: initator (user string), org_id (number)
|
||||||
|
-- output: gets question from initiator, asks all org members, broadcasts answers
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,12 +41,16 @@ end
|
|||||||
-- ============================
|
-- ============================
|
||||||
-- interact function for the consent module
|
-- interact function for the consent module
|
||||||
function modpol.modules.consent:interact(user)
|
function modpol.modules.consent:interact(user)
|
||||||
local resp = modpol.interactions.binary_poll_user(user, "How do you vote?")
|
-- TODO this needs more context on the vote at hand
|
||||||
if resp == 'yes' then
|
modpol.interactions.binary_poll_user(
|
||||||
self:approve(user, true)
|
user, "How do you vote?",
|
||||||
elseif resp == 'no' then
|
function(vote)
|
||||||
self:approve(user, false)
|
if vote == 'yes' then
|
||||||
end
|
self:approve(user, true)
|
||||||
|
elseif vote == 'no' then
|
||||||
|
self:approve(user, false)
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- =========================================
|
-- =========================================
|
||||||
|
@ -82,7 +82,7 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
modpol.interactions.binary_poll_user(
|
modpol.interactions.binary_poll_user(
|
||||||
pname, input,
|
pname, input,
|
||||||
function(vote)
|
function(vote)
|
||||||
modpol.interacts.message(
|
modpol.interactions.message(
|
||||||
pname, pname .. " voted " .. vote)
|
pname, pname .. " voted " .. vote)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
@ -196,21 +196,17 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
org:remove_member(pname)
|
org:remove_member(pname)
|
||||||
modpol.interactions.dashboard(pname)
|
modpol.interactions.dashboard(pname)
|
||||||
elseif fields.test_poll then
|
elseif fields.test_poll then
|
||||||
modpol.interactions.binary_poll_org(pname, _contexts.pname.current_org.id, "Poll question (yes/no):")
|
modpol.interactions.binary_poll_org(
|
||||||
|
pname, _contexts[pname].current_org.id,
|
||||||
|
"Poll question (yes/no):",
|
||||||
|
function(input)
|
||||||
|
modpol.interactions.message_org(
|
||||||
|
_contexts[pname].current_org.id,
|
||||||
|
pname .. " voted " .. input)
|
||||||
|
end)
|
||||||
elseif fields.add_child then
|
elseif fields.add_child then
|
||||||
--DEPRICATED pre-request version to remove:
|
modpol.interactions.add_org(
|
||||||
--modpol.interactions.add_org(pname, org.id)
|
pname, _contexts[pname].current_org.id)
|
||||||
modpol.interactions.text_query(pname, "Org name:")
|
|
||||||
-- local new_org_name = _contexts[pname]["new_org_name"]
|
|
||||||
_contexts[pname] = function(input)
|
|
||||||
local new_request = {
|
|
||||||
user = pname,
|
|
||||||
type = "add_org",
|
|
||||||
params = {input}
|
|
||||||
}
|
|
||||||
org:make_request(new_request)
|
|
||||||
_contexts[pname] = nil
|
|
||||||
end
|
|
||||||
elseif fields.remove_org then
|
elseif fields.remove_org then
|
||||||
modpol.interactions.remove_org(pname)
|
modpol.interactions.remove_org(pname)
|
||||||
elseif fields.back then
|
elseif fields.back then
|
||||||
@ -257,16 +253,19 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local input = fields.input
|
local input = fields.input
|
||||||
minetest.close_formspec(pname, formname)
|
minetest.close_formspec(pname, formname)
|
||||||
local func = _contexts[pname]["text_query_func"]
|
if not input then
|
||||||
if func then
|
-- no input, do nothing
|
||||||
func(input)
|
|
||||||
else
|
else
|
||||||
modpol.interactions.message(pname, "text_query: " .. input)
|
local func = _contexts[pname]["text_query_func"]
|
||||||
|
if func then
|
||||||
|
func(input)
|
||||||
|
else
|
||||||
|
modpol.interactions.message(pname, "text_query: " .. input)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
-- Function: dropdown_query
|
-- Function: dropdown_query
|
||||||
-- input: user (string), label (string), options (table of strings), func (function)
|
-- input: user (string), label (string), options (table of strings), func (function)
|
||||||
-- func input: choice (string)
|
-- func input: choice (string)
|
||||||
@ -330,7 +329,7 @@ function modpol.interactions.binary_poll_user(user, question, func)
|
|||||||
_contexts[user]["binary_poll_func"] = func
|
_contexts[user]["binary_poll_func"] = func
|
||||||
-- present to player
|
-- present to player
|
||||||
minetest.show_formspec(user, "modpol:binary_poll_user", formspec_string)
|
minetest.show_formspec(user, "modpol:binary_poll_user", formspec_string)
|
||||||
modpol.interactions.message(user,"should have showed formspec: " .. question)
|
modpol.interactions.message(user,"should have showed formspec: " .. question)
|
||||||
end
|
end
|
||||||
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
@ -342,8 +341,8 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
end
|
end
|
||||||
minetest.close_formspec(pname, formname)
|
minetest.close_formspec(pname, formname)
|
||||||
if vote then
|
if vote then
|
||||||
modpol.interactions.message(pname, "Vote recorded")
|
modpol.interactions.message(pname, "Voted " .. vote)
|
||||||
local func = _contexts[user]["binary_poll_func"]
|
local func = _contexts[pname]["binary_poll_func"]
|
||||||
func(vote)
|
func(vote)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -352,21 +351,31 @@ end)
|
|||||||
-- COMPLEX INTERACTIONS
|
-- COMPLEX INTERACTIONS
|
||||||
-- ====================
|
-- ====================
|
||||||
|
|
||||||
|
-- Function: modpol.interactions.message_org
|
||||||
|
-- input: initiator (string), org_id (number), message (string)
|
||||||
|
-- output: broadcasts message to all org members
|
||||||
|
function modpol.interactions.message_org(initiator, org_id, message)
|
||||||
|
local org = modpol.orgs.get_org(org_id)
|
||||||
|
local users = org:list_member()
|
||||||
|
for k,v in ipairs(users) do
|
||||||
|
modpol.interactions.message(v, message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Function: modpol.interactions.binary_poll_org
|
-- Function: modpol.interactions.binary_poll_org
|
||||||
-- input: initator (user string), org (number)
|
-- input: initator (user string), org_id (number)
|
||||||
-- output: interaction begins
|
-- output: gets question from initiator, asks all org members, broadcasts answers
|
||||||
function modpol.interactions.binary_poll_org(initiator, org)
|
function modpol.interactions.binary_poll_org(initiator, org_id)
|
||||||
-- start formspec
|
local org = modpol.orgs.get_org(org_id)
|
||||||
modpol.interactions.text_query(initiator, "Poll question (yes/no):")
|
local users = org:list_member()
|
||||||
-- set user's context to followup function
|
modpol.interactions.text_query(
|
||||||
_contexts[initiator] =
|
initiator, "Yes/no poll question:",
|
||||||
function(input)
|
function(input)
|
||||||
local users = modpol.list_users()
|
|
||||||
for k,v in ipairs(users) do
|
for k,v in ipairs(users) do
|
||||||
modpol.interactions.binary_poll_user(v, input)
|
modpol.interactions.binary_poll_user(v, input)
|
||||||
end
|
end
|
||||||
_contexts[initiator] = nil
|
end)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function: modpol.interactions.add_org
|
-- Function: modpol.interactions.add_org
|
||||||
|
Loading…
x
Reference in New Issue
Block a user