58 lines
1.3 KiB
Lua
58 lines
1.3 KiB
Lua
-- JOIN ORG
|
|
-- Module that enables a user to join an org
|
|
|
|
JoinOrg = {}
|
|
|
|
JoinOrg.setup = {
|
|
name = "Join an org",
|
|
desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
|
|
votes_yes = 0
|
|
}
|
|
|
|
function JoinOrg:initiate(result)
|
|
modpol.interactions.binary_poll_user(
|
|
self.initiator,
|
|
"Would you like to join",
|
|
function (resp)
|
|
if resp == "Yes" then
|
|
for id, member in pairs(self.org.members) do
|
|
self.org:add_pending_action(self.id, member, "callback")
|
|
|
|
end
|
|
end
|
|
end
|
|
)
|
|
|
|
if result then result() end
|
|
|
|
end
|
|
|
|
function JoinOrg:callback(member)
|
|
modpol.interactions.binary_poll_user(
|
|
member,
|
|
"Do you want " .. self.initiator .. " to join?",
|
|
function (resp)
|
|
if resp == "Yes" then
|
|
self.votes_yes = self.votes_yes + 1
|
|
end
|
|
|
|
self:evaluate_vote()
|
|
|
|
end
|
|
)
|
|
end
|
|
|
|
|
|
|
|
function JoinOrg:evaluate_vote()
|
|
if self.votes_yes >= 1 then
|
|
print('added user')
|
|
self.org:add_member(self.initiator)
|
|
self.org:wipe_pending_actions(self.id)
|
|
end
|
|
end
|
|
|
|
-- ===================================
|
|
-- When calling a module internally
|
|
|
|
modpol.modules.join_org_class = JoinOrg |