Changeset

2887:65082d91950e

Many modules: Simplify st.message(…):tag("body"):text(…):up() into st.message(…, …)
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 17 Feb 2018 08:42:10 +0100
parents 2886:5ca6d53d3186
children 2888:59cc6f9e8e68
files mod_admin_message/mod_admin_message.lua mod_alias/mod_alias.lua mod_manifesto/mod_manifesto.lua mod_motd_sequential/mod_motd_sequential.lua mod_sms_clickatell/mod_sms_clickatell.lua mod_twitter/mod_twitter.lua mod_watchuntrusted/mod_watchuntrusted.lua
diffstat 7 files changed, 17 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mod_admin_message/mod_admin_message.lua	Tue Feb 20 17:30:17 2018 +0100
+++ b/mod_admin_message/mod_admin_message.lua	Sat Feb 17 08:42:10 2018 +0100
@@ -89,8 +89,7 @@
 
 	-- Send the reply stanza
 	local reply_stanza = st.message({ from = host, to = userjid,
-					type = "chat" });
-	reply_stanza = reply_stanza:body(session.fulltext);
+					type = "chat" }, session.fulltext);
 	module:send(reply_stanza);
 
 	return true;
--- a/mod_alias/mod_alias.lua	Tue Feb 20 17:30:17 2018 +0100
+++ b/mod_alias/mod_alias.lua	Sat Feb 17 08:42:10 2018 +0100
@@ -26,7 +26,7 @@
 			local error_message = alias_response:gsub("%$([%w_]+)", function (v)
 					return replacements[v] or nil;
 				end);
-			local message = st.message{ type = "chat", from = alias, to = event.stanza.attr.from }:tag("body"):text(error_message);
+			local message = st.message({ type = "chat", from = alias, to = event.stanza.attr.from }, error_message);
 			module:send(message);
 			return event.origin.send(st.error_reply(event.stanza, "cancel", "gone", error_message));
 		end
--- a/mod_manifesto/mod_manifesto.lua	Tue Feb 20 17:30:17 2018 +0100
+++ b/mod_manifesto/mod_manifesto.lua	Sat Feb 17 08:42:10 2018 +0100
@@ -103,7 +103,7 @@
 				SERVICES = "    "..table.concat(bad_hosts, "\n    ");
 				CONTACTVIA = contact_method, CONTACT = contact;
 			};
-			session.send(st.message({ type = "headline", from = host }):tag("body"):text(message:gsub("$(%w+)", vars)));
+			session.send(st.message({ type = "headline", from = host }, message:gsub("$(%w+)", vars)));
 			notified[session.username] = now;
 		end
 	end);
--- a/mod_motd_sequential/mod_motd_sequential.lua	Tue Feb 20 17:30:17 2018 +0100
+++ b/mod_motd_sequential/mod_motd_sequential.lua	Sat Feb 17 08:42:10 2018 +0100
@@ -29,8 +29,8 @@
     local mod_stanza;
     for i = alreadyseen, max do
             motd_stanza =
-                    st.message({ to = session.username..'@'..session.host, from = motd_jid })
-                            :tag("body"):text(motd_messagesets[i]);
+                    st.message({ to = session.username..'@'..session.host, from = motd_jid },
+                            motd_messagesets[i]);
             core_route_stanza(hosts[host], motd_stanza);
             module:log("debug", "MOTD send to user %s@%s", session.username, session.host);
     end
--- a/mod_sms_clickatell/mod_sms_clickatell.lua	Tue Feb 20 17:30:17 2018 +0100
+++ b/mod_sms_clickatell/mod_sms_clickatell.lua	Sat Feb 17 08:42:10 2018 +0100
@@ -150,7 +150,7 @@
 function dmsg(jid, msg)
 	module:log("debug", msg or "nil");
 	if jid ~= nil then
-		send_stanza(st.message({to=jid, from=component_host, type='chat'}):tag("body"):text(msg or "nil"):up());
+		send_stanza(st.message({to=jid, from=component_host, type='chat'}, msg or "nil"));
 	end
 end
 
@@ -498,7 +498,7 @@
 	-- Now parse the message
 	if stanza.attr.to == component_host then
 		-- Messages directly to the component jget echoed
-		origin.send(st.message({to=stanza.attr.from, from=component_host, type='chat'}):tag("body"):text(msg.body):up());
+		origin.send(st.message({to=stanza.attr.from, from=component_host, type='chat'}, msg.body));
 	elseif users[from_bjid].data.roster[to.node] ~= nil then
 		-- If message contains a body, send message to SMS Test User
 		if msg.body ~= nil then
--- a/mod_twitter/mod_twitter.lua	Tue Feb 20 17:30:17 2018 +0100
+++ b/mod_twitter/mod_twitter.lua	Sat Feb 17 08:42:10 2018 +0100
@@ -25,7 +25,7 @@
 function dmsg(jid, msg)
 	module:log("debug", msg or "nil");
 	if jid ~= nil then
-		module:send(st.message({to=jid, from=component_host, type='chat'}):tag("body"):text(msg or "nil"):up());
+		module:send(st.message({to=jid, from=component_host, type='chat'}, msg or "nil"));
 	end
 end
 
@@ -100,7 +100,7 @@
 			timer.add_task(self.data.refreshrate, function() return users[self.jid]:sync(); end)
 		end
 	else
-		module:send(st.message({to=self.jid, from=component_host, type='chat'}):tag("body"):text("You are not signed in."));
+		module:send(st.message({to=self.jid, from=component_host, type='chat'}, "You are not signed in."));
 	end
 end
 
@@ -196,17 +196,17 @@
 		end
 		http_add_action(line, url, action.method, post, function(...) self:twitterActionResult(...) end);
 	else
-		module:send(st.message({to=self.jid, from=component_host, type='chat'}):tag("body"):text("Wrong twitter action!"):up());
+		module:send(st.message({to=self.jid, from=component_host, type='chat'}, "Wrong twitter action!"));
 	end
 end
 
 local twitterActionResultMap = {
 	PublicTimeline = {exec=function(jid, response)
-		--module:send(st.message({to=jid, from=component_host, type='chat'}):tag("body"):text(print_r(response)):up());
+		--module:send(st.message({to=jid, from=component_host, type='chat'}, print_r(response)));
 		return
 	end},
 	HomeTimeline = {exec=function(jid, response)
-		--module:send(st.message({to=jid, from=component_host, type='chat'}):tag("body"):text(print_r(response)):up());
+		--module:send(st.message({to=jid, from=component_host, type='chat'}, print_r(response)));
 		return
 	end},
 	FriendsTimeline = {function(jid, response)
@@ -416,7 +416,7 @@
 	if stanza.attr.to == component_host then
 		if msg.body == "!myinfo" then
 			if users[from_bjid] ~= nil then
-				origin.send(st.message({to=stanza.attr.from, from=component_host, type='chat'}):tag("body"):text(print_r(users[from_bjid])):up());
+				origin.send(st.message({to=stanza.attr.from, from=component_host, type='chat'}, print_r(users[from_bjid])));
 			end
 		end
 		-- Other messages go to twitter
--- a/mod_watchuntrusted/mod_watchuntrusted.lua	Tue Feb 20 17:30:17 2018 +0100
+++ b/mod_watchuntrusted/mod_watchuntrusted.lua	Sat Feb 17 08:42:10 2018 +0100
@@ -49,11 +49,10 @@
 			errors = error_message
 		};
 
-		local message = st.message{ type = "chat", from = local_host }
-			:tag("body")
-				:text(untrusted_fail_notification:gsub("%$([%w_]+)", function (v)
-					return event[v] or session and session[v] or replacements and replacements[v] or nil;
-				end));
+		local message = st.message({ type = "chat", from = local_host },
+			untrusted_fail_notification:gsub("%$([%w_]+)", function (v)
+				return event[v] or session and session[v] or replacements and replacements[v] or nil;
+			end));
 		for jid in untrusted_fail_watchers do
 			module:log("debug", "Notifying %s", jid);
 			message.attr.to = jid;