Mercurial > prosody-modules
comparison 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 |
| parents | e318a341d332 |
| children | 9f7c97e55593 |
comparison
equal
deleted
inserted
replaced
| 1014:ed7431fd3b47 | 1015:0fc9e1f086c1 |
|---|---|
| 1 local is_admin = require "core.usermanager".is_admin; | |
| 1 local allowed_senders = module:get_option_set("broadcast_senders", {}); | 2 local allowed_senders = module:get_option_set("broadcast_senders", {}); |
| 2 | 3 |
| 3 local jid_bare = require "util.jid".bare; | 4 local jid_bare = require "util.jid".bare; |
| 4 | 5 |
| 5 function send_to_online(message) | 6 function send_to_online(message) |
| 16 return c; | 17 return c; |
| 17 end | 18 end |
| 18 | 19 |
| 19 function send_message(event) | 20 function send_message(event) |
| 20 local stanza = event.stanza; | 21 local stanza = event.stanza; |
| 21 if allowed_senders:contains(jid_bare(stanza.attr.from)) then | 22 local from = stanza.attr.from; |
| 23 if is_admin(from) or allowed_senders:contains(jid_bare(from)) then | |
| 22 local c = send_to_online(stanza); | 24 local c = send_to_online(stanza); |
| 23 module:log("debug", "Broadcast stanza from %s to %d online users", stanza.attr.from, c); | 25 module:log("debug", "Broadcast stanza from %s to %d online users", from, c); |
| 24 return true; | 26 return true; |
| 25 else | 27 else |
| 26 module:log("warn", "Broadcasting is not allowed for %s", stanza.attr.from); | 28 module:log("warn", "Broadcasting is not allowed for %s", from); |
| 27 end | 29 end |
| 28 end | 30 end |
| 29 | 31 |
| 30 module:hook("message/bare", send_message); | 32 module:hook("message/bare", send_message); |
