Software /
code /
prosody-modules
File
mod_broadcast/mod_broadcast.lua @ 1015:0fc9e1f086c1
mod_broadcast: Allow admins to broadcast
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 19 May 2013 22:09:54 +0100 |
parent | 786:e318a341d332 |
child | 1016:9f7c97e55593 |
line wrap: on
line source
local is_admin = require "core.usermanager".is_admin; 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; local from = stanza.attr.from; if is_admin(from) or allowed_senders:contains(jid_bare(from)) then local c = send_to_online(stanza); module:log("debug", "Broadcast stanza from %s to %d online users", from, c); return true; else module:log("warn", "Broadcasting is not allowed for %s", from); end end module:hook("message/bare", send_message);