Changeset

5936:9d0270680d1f

mod_muc_restrict_pm: fix lua warnings
author Nicholas George <wirlaburla@worlio.com>
date Wed, 22 May 2024 21:11:24 -0500
parents 5935:e7584fd5b191
children 5937:d82c0383106a
files mod_muc_restrict_pm/mod_muc_restrict_pm.lua
diffstat 1 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_restrict_pm/mod_muc_restrict_pm.lua	Tue May 21 01:09:12 2024 -0500
+++ b/mod_muc_restrict_pm/mod_muc_restrict_pm.lua	Wed May 22 21:11:24 2024 -0500
@@ -50,14 +50,14 @@
 			{ value = 'none', label = 'Everyone', default = affilpm == 'none' }
 		}
 	});
-	
+
 	table.insert(event.form, {
 		name = 'muc#restrict_pm_to';
 		type = 'boolean';
 		label = 'Allow PMs to everyone';
 		value = can_pm_anyone(event.room);
 	});
-	
+
 	table.insert(event.form, {
 		name = 'muc#restrict_pm_visitor';
 		type = 'boolean';
@@ -91,19 +91,26 @@
 end
 
 module:hook("muc-private-message", function(event)
-	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);
-	
+	local stanza, room = event.stanza, event.room;
+	local from_occupant = room:get_occupant_by_nick(stanza.attr.from);
+	local to_occupant = room:get_occupant_by_nick(stanza.attr.to);
+
 	-- To self is always okay
 	if to_occupant.bare_jid == from_occupant.bare_jid then return; end
-	
+
 	-- To moderation is okay
 	if to_occupant and to_occupant.role == 'moderator' then return; end
-	
-	if not is_visitor_pm_off(event.room) or (from_occupant == nil or from_occupant.role ~= 'visitor') then
+
+	if not is_visitor_pm_off(room) or (from_occupant == nil or from_occupant.role ~= 'visitor') then
 		-- If visitors disabled
-		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;
+		if can_user_pm(room, from_occupant.bare_jid) and (can_pm_anyone(room) or can_user_pm(room, to_occupant.bare_jid)) then
+			return;
+		end;
 	end
-	
-	event.room:route_to_occupant(from_occupant, st.error_reply(event.stanza, "cancel", "policy-violation", "Private messages are disabled", event.room.jid));
+
+	room:route_to_occupant(
+		from_occupant,
+		st.error_reply(stanza, "cancel", "policy-violation", "Private messages are disabled", room.jid)
+	);
 	return false;
 end, 1);