Software /
code /
prosody-modules
Comparison
mod_muc_restrict_pm/mod_muc_restrict_pm.lua @ 5936:9d0270680d1f
mod_muc_restrict_pm: fix lua warnings
author | Nicholas George <wirlaburla@worlio.com> |
---|---|
date | Wed, 22 May 2024 21:11:24 -0500 |
parent | 5934:7358d1b64b1d |
child | 5937:d82c0383106a |
comparison
equal
deleted
inserted
replaced
5935:e7584fd5b191 | 5936:9d0270680d1f |
---|---|
48 { value = 'administrator', label = 'Administrators', default = affilpm == 'administrator' }, | 48 { value = 'administrator', label = 'Administrators', default = affilpm == 'administrator' }, |
49 { value = 'member', label = 'Members', default = affilpm == 'member' }, | 49 { value = 'member', label = 'Members', default = affilpm == 'member' }, |
50 { value = 'none', label = 'Everyone', default = affilpm == 'none' } | 50 { value = 'none', label = 'Everyone', default = affilpm == 'none' } |
51 } | 51 } |
52 }); | 52 }); |
53 | 53 |
54 table.insert(event.form, { | 54 table.insert(event.form, { |
55 name = 'muc#restrict_pm_to'; | 55 name = 'muc#restrict_pm_to'; |
56 type = 'boolean'; | 56 type = 'boolean'; |
57 label = 'Allow PMs to everyone'; | 57 label = 'Allow PMs to everyone'; |
58 value = can_pm_anyone(event.room); | 58 value = can_pm_anyone(event.room); |
59 }); | 59 }); |
60 | 60 |
61 table.insert(event.form, { | 61 table.insert(event.form, { |
62 name = 'muc#restrict_pm_visitor'; | 62 name = 'muc#restrict_pm_visitor'; |
63 type = 'boolean'; | 63 type = 'boolean'; |
64 label = 'Disable PMs from Visitors'; | 64 label = 'Disable PMs from Visitors'; |
65 value = is_visitor_pm_off(event.room); | 65 value = is_visitor_pm_off(event.room); |
89 if affil >= pmval then return true; end | 89 if affil >= pmval then return true; end |
90 return false; | 90 return false; |
91 end | 91 end |
92 | 92 |
93 module:hook("muc-private-message", function(event) | 93 module:hook("muc-private-message", function(event) |
94 local from_occupant, to_occupant = event.room:get_occupant_by_nick(event.stanza.attr.from), event.room:get_occupant_by_nick(event.stanza.attr.to); | 94 local stanza, room = event.stanza, event.room; |
95 | 95 local from_occupant = room:get_occupant_by_nick(stanza.attr.from); |
96 local to_occupant = room:get_occupant_by_nick(stanza.attr.to); | |
97 | |
96 -- To self is always okay | 98 -- To self is always okay |
97 if to_occupant.bare_jid == from_occupant.bare_jid then return; end | 99 if to_occupant.bare_jid == from_occupant.bare_jid then return; end |
98 | 100 |
99 -- To moderation is okay | 101 -- To moderation is okay |
100 if to_occupant and to_occupant.role == 'moderator' then return; end | 102 if to_occupant and to_occupant.role == 'moderator' then return; end |
101 | 103 |
102 if not is_visitor_pm_off(event.room) or (from_occupant == nil or from_occupant.role ~= 'visitor') then | 104 if not is_visitor_pm_off(room) or (from_occupant == nil or from_occupant.role ~= 'visitor') then |
103 -- If visitors disabled | 105 -- If visitors disabled |
104 if can_user_pm(event.room, from_occupant.bare_jid) and (can_pm_anyone(event.room) or can_user_pm(event.room, to_occupant.bare_jid)) then return; end; | 106 if can_user_pm(room, from_occupant.bare_jid) and (can_pm_anyone(room) or can_user_pm(room, to_occupant.bare_jid)) then |
107 return; | |
108 end; | |
105 end | 109 end |
106 | 110 |
107 event.room:route_to_occupant(from_occupant, st.error_reply(event.stanza, "cancel", "policy-violation", "Private messages are disabled", event.room.jid)); | 111 room:route_to_occupant( |
112 from_occupant, | |
113 st.error_reply(stanza, "cancel", "policy-violation", "Private messages are disabled", room.jid) | |
114 ); | |
108 return false; | 115 return false; |
109 end, 1); | 116 end, 1); |