Comparison

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
parent 4565:3b2ae854842c
child 4567:bcf4518d18d4
comparison
equal deleted inserted replaced
4565:3b2ae854842c 4566:174c7a3c819b
53 event.origin.send(st.error_reply(event.stanza, "modify", "policy-violation", "Only known bots may use the [bot] suffix", room.jid)); 53 event.origin.send(st.error_reply(event.stanza, "modify", "policy-violation", "Only known bots may use the [bot] suffix", room.jid));
54 return true; 54 return true;
55 end 55 end
56 end, 3); 56 end, 3);
57 57
58 if not module:get_option_boolean("bots_get_messages", true) then
59 module:hook("muc-broadcast-message", function (event)
60 event.room:broadcast(event.stanza, function (nick, occupant)
61 if nick:sub(-5, -1) == "[bot]" or bots:contains(occupant.bare_jid) or bots:contains(jid.host(occupant.bare_jid)) then
62 return false;
63 else
64 return true;
65 end
66 end);
67 return true;
68 end, -100);
69 end
70
58 assert(string.sub("foo[bot]", -5, -1) == "[bot]", "substring indicies, how do they work?"); 71 assert(string.sub("foo[bot]", -5, -1) == "[bot]", "substring indicies, how do they work?");