Mercurial > prosody-hg
comparison plugins/mod_motd.lua @ 8135:e20c27e04ecc
mod_motd: Use initial presence event (saves some checking)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 27 Apr 2017 10:17:54 +0200 |
| parents | fad7084a0b35 |
| children | abd32bc33a9c |
comparison
equal
deleted
inserted
replaced
| 8134:b87e281a7d59 | 8135:e20c27e04ecc |
|---|---|
| 15 | 15 |
| 16 local st = require "util.stanza"; | 16 local st = require "util.stanza"; |
| 17 | 17 |
| 18 motd_text = motd_text:gsub("^%s*(.-)%s*$", "%1"):gsub("\n[ \t]+", "\n"); -- Strip indentation from the config | 18 motd_text = motd_text:gsub("^%s*(.-)%s*$", "%1"):gsub("\n[ \t]+", "\n"); -- Strip indentation from the config |
| 19 | 19 |
| 20 module:hook("presence/bare", function (event) | 20 module:hook("presence/initial", function (event) |
| 21 local session, stanza = event.origin, event.stanza; | 21 local session, stanza = event.origin, event.stanza; |
| 22 if session.username and not session.presence | 22 if not stanza.attr.type and not stanza.attr.to then |
| 23 and not stanza.attr.type and not stanza.attr.to then | |
| 24 local motd_stanza = | 23 local motd_stanza = |
| 25 st.message({ to = session.full_jid, from = motd_jid }) | 24 st.message({ to = session.full_jid, from = motd_jid }) |
| 26 :tag("body"):text(motd_text); | 25 :tag("body"):text(motd_text); |
| 27 module:send(motd_stanza); | 26 module:send(motd_stanza); |
| 28 module:log("debug", "MOTD send to user %s", session.full_jid); | 27 module:log("debug", "MOTD send to user %s", session.full_jid); |
