Mercurial > prosody-modules
view mod_broadcast/mod_broadcast.lua @ 889:9901d267f938
mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
for clients which are not carbons-capable yet. This will not interfere with
clients which have support for regular Message Carbons (XEP-0280).
This module takes two optional parameters:
carbons_copies_default - if set to true, copies will be enabled by default
carbons_copies_adhoc - Enable Adhoc-commands to allow the user to
enable/disable copies
author | Michael Holzt <kju@fqdn.org> |
---|---|
date | Sun, 23 Dec 2012 19:34:29 +0100 |
parents | e318a341d332 |
children | 0fc9e1f086c1 |
line wrap: on
line source
local allowed_senders = module:get_option_set("broadcast_senders", {}); local jid_bare = require "util.jid".bare; function send_to_online(message) local c = 0; for hostname, host_session in pairs(hosts) do if host_session.sessions then for username in pairs(host_session.sessions) do c = c + 1; message.attr.to = username.."@"..hostname; module:send(message); end end end return c; end function send_message(event) local stanza = event.stanza; if allowed_senders:contains(jid_bare(stanza.attr.from)) then local c = send_to_online(stanza); module:log("debug", "Broadcast stanza from %s to %d online users", stanza.attr.from, c); return true; else module:log("warn", "Broadcasting is not allowed for %s", stanza.attr.from); end end module:hook("message/bare", send_message);