# HG changeset patch # User Kim Alvefur # Date 1621865909 -7200 # Node ID 174c7a3c819b16dca1ef18b3f9c1653d67ef0cb2 # Parent 3b2ae854842c822b70bdf8e1a25aee2d198ca63d 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. diff -r 3b2ae854842c -r 174c7a3c819b mod_muc_bot/mod_muc_bot.lua --- 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?");