mod_motd: Use presence/bare to catch a client's initial presence and send the MOTD then (fixes #282)
authorMatthew Wild <mwild1@gmail.com>
Sun, 22 Apr 2012 14:54:36 +0100
changeset 4654 0975505f5a54
parent 4653 0b055b588f75
child 4655 9159546cb2f3
mod_motd: Use presence/bare to catch a client's initial presence and send the MOTD then (fixes #282)
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);