diff mod_muc_bot/mod_muc_bot.lua @ 4566:174c7a3c819b

mod_muc_bot: Add option to not send any messages to bots Useful for write-only bots that don't care about what's said in the chat.
author Kim Alvefur <zash@zash.se>
date Mon, 24 May 2021 16:18:29 +0200
parents 3b2ae854842c
children bcf4518d18d4
line wrap: on
line diff
--- a/mod_muc_bot/mod_muc_bot.lua	Sat Apr 10 19:23:25 2021 +0200
+++ b/mod_muc_bot/mod_muc_bot.lua	Mon May 24 16:18:29 2021 +0200
@@ -55,4 +55,17 @@
 	end
 end, 3);
 
+if not module:get_option_boolean("bots_get_messages", true) then
+	module:hook("muc-broadcast-message", function (event)
+		event.room:broadcast(event.stanza, function (nick, occupant)
+			if nick:sub(-5, -1) == "[bot]" or bots:contains(occupant.bare_jid) or bots:contains(jid.host(occupant.bare_jid)) then
+				return false;
+			else
+				return true;
+			end
+		end);
+		return true;
+	end, -100);
+end
+
 assert(string.sub("foo[bot]", -5, -1) == "[bot]", "substring indicies, how do they work?");