Mercurial > prosody-hg
comparison plugins/mod_announce.lua @ 5776:bd0ff8ae98a8
Remove all trailing whitespace
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Fri, 09 Aug 2013 17:48:21 +0200 |
| parents | 7838acadb0fa |
| children | 1cc9a293e958 |
comparison
equal
deleted
inserted
replaced
| 5775:a6c2b8933507 | 5776:bd0ff8ae98a8 |
|---|---|
| 1 -- Prosody IM | 1 -- Prosody IM |
| 2 -- Copyright (C) 2008-2010 Matthew Wild | 2 -- Copyright (C) 2008-2010 Matthew Wild |
| 3 -- Copyright (C) 2008-2010 Waqas Hussain | 3 -- Copyright (C) 2008-2010 Waqas Hussain |
| 4 -- | 4 -- |
| 5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
| 6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
| 7 -- | 7 -- |
| 8 | 8 |
| 9 local st, jid = require "util.stanza", require "util.jid"; | 9 local st, jid = require "util.stanza", require "util.jid"; |
| 37 | 37 |
| 38 -- Old <message>-based jabberd-style announcement sending | 38 -- Old <message>-based jabberd-style announcement sending |
| 39 function handle_announcement(event) | 39 function handle_announcement(event) |
| 40 local origin, stanza = event.origin, event.stanza; | 40 local origin, stanza = event.origin, event.stanza; |
| 41 local node, host, resource = jid.split(stanza.attr.to); | 41 local node, host, resource = jid.split(stanza.attr.to); |
| 42 | 42 |
| 43 if resource ~= "announce/online" then | 43 if resource ~= "announce/online" then |
| 44 return; -- Not an announcement | 44 return; -- Not an announcement |
| 45 end | 45 end |
| 46 | 46 |
| 47 if not is_admin(stanza.attr.from) then | 47 if not is_admin(stanza.attr.from) then |
| 48 -- Not an admin? Not allowed! | 48 -- Not an admin? Not allowed! |
| 49 module:log("warn", "Non-admin '%s' tried to send server announcement", stanza.attr.from); | 49 module:log("warn", "Non-admin '%s' tried to send server announcement", stanza.attr.from); |
| 50 return; | 50 return; |
| 51 end | 51 end |
| 52 | 52 |
| 53 module:log("info", "Sending server announcement to all online users"); | 53 module:log("info", "Sending server announcement to all online users"); |
| 54 local message = st.clone(stanza); | 54 local message = st.clone(stanza); |
| 55 message.attr.type = "headline"; | 55 message.attr.type = "headline"; |
| 56 message.attr.from = host; | 56 message.attr.from = host; |
| 57 | 57 |
| 58 local c = send_to_online(message, host); | 58 local c = send_to_online(message, host); |
| 59 module:log("info", "Announcement sent to %d online users", c); | 59 module:log("info", "Announcement sent to %d online users", c); |
| 60 return true; | 60 return true; |
| 61 end | 61 end |
| 62 module:hook("message/host", handle_announcement); | 62 module:hook("message/host", handle_announcement); |
| 81 local fields = announce_layout:data(data.form); | 81 local fields = announce_layout:data(data.form); |
| 82 | 82 |
| 83 module:log("info", "Sending server announcement to all online users"); | 83 module:log("info", "Sending server announcement to all online users"); |
| 84 local message = st.message({type = "headline"}, fields.announcement):up() | 84 local message = st.message({type = "headline"}, fields.announcement):up() |
| 85 :tag("subject"):text(fields.subject or "Announcement"); | 85 :tag("subject"):text(fields.subject or "Announcement"); |
| 86 | 86 |
| 87 local count = send_to_online(message, data.to); | 87 local count = send_to_online(message, data.to); |
| 88 | 88 |
| 89 module:log("info", "Announcement sent to %d online users", count); | 89 module:log("info", "Announcement sent to %d online users", count); |
| 90 return { status = "completed", info = ("Announcement sent to %d online users"):format(count) }; | 90 return { status = "completed", info = ("Announcement sent to %d online users"):format(count) }; |
| 91 else | 91 else |
| 92 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = announce_layout }, "executing"; | 92 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = announce_layout }, "executing"; |
| 93 end | 93 end |
