# HG changeset patch
# User Matthew Wild <mwild1@gmail.com>
# Date 1335102876 -3600
# Node ID 0975505f5a54877dfd05b5c6b6ed32588f624a7a
# Parent  0b055b588f75eeaca98d0c6dd42e98ee6bb3331a
mod_motd: Use presence/bare to catch a client's initial presence and send the MOTD then (fixes #282)

diff -r 0b055b588f75 -r 0975505f5a54 plugins/mod_motd.lua
--- a/plugins/mod_motd.lua	Sat Apr 21 22:54:55 2012 +0100
+++ b/plugins/mod_motd.lua	Sun Apr 22 14:54:36 2012 +0100
@@ -18,12 +18,13 @@
 
 motd_text = motd_text:gsub("^%s*(.-)%s*$", "%1"):gsub("\n%s+", "\n"); -- Strip indentation from the config
 
-module:hook("resource-bind", function (event)
-		local session = event.session;
-		local motd_stanza =
-			st.message({ to = jid_join(session.username, session.host, session.resource), from = motd_jid })
-				:tag("body"):text(motd_text);
-		core_route_stanza(hosts[host], motd_stanza);
-		module:log("debug", "MOTD send to user %s@%s", session.username, session.host);
-
-end);
+module:hook("presence/bare", function (event)
+		local session, stanza = event.origin, event.stanza;
+		if not session.presence and not stanza.attr.type then
+			local motd_stanza =
+				st.message({ to = session.full_jid, from = motd_jid })
+					:tag("body"):text(motd_text);
+			core_route_stanza(hosts[host], motd_stanza);
+			module:log("debug", "MOTD send to user %s", session.full_jid);
+		end
+end, 1);