Changeset

122:1dfd28db10bd

Merge with MattJ
author Kim Alvefur <zash@zash.se>
date Mon, 08 Sep 2014 12:20:24 +0200
parents 121:45843df81db0 (diff) 119:896a25ed6b1b (current diff)
children 123:c61fadb9d4fa
files clix.lua squishy
diffstat 3 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/clix.lua	Sat Feb 08 16:40:00 2014 +0100
+++ b/clix.lua	Mon Sep 08 12:20:24 2014 +0200
@@ -10,7 +10,8 @@
 
 -- Global to allow commands to add to it
 short_opts = { v = "verbose", q = "quiet", t = "to", f = "from", e = "type",
-	a = "account", p = "password", r = "resource", o = "presence", c = "chatroom", i = "interactive" }
+	a = "account", p = "password", r = "resource", o = "presence", c = "chatroom", i = "interactive",
+    f = "file" }
 
 if #arg < 1 then
 	print("Command Line XMPP, available commands:");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clix/sendfilecontent.lua	Mon Sep 08 12:20:24 2014 +0200
@@ -0,0 +1,30 @@
+return function (opts, arg)
+	if opts.short_help then
+		print("Send file content");
+		return;
+	end
+	
+	local function on_connect(conn)
+		local function send_message(text)
+			conn:send(verse.message({ to = opts.to,
+				type = opts.type or (opts.chatroom and "groupchat") or "chat" })
+				:body(text));
+		end
+		if opts.file then
+			local f, err = io.open(opts.file, "rb")
+			if not f then
+				conn:error("Unable to open file: %s", err);
+			else
+				local content = f:read("*all")
+				f:close()
+				if content:len() < 2000 then
+					send_message(content);
+				else
+					conn:error("File size too large. Cannot send file");
+				end
+			end
+		end
+		conn:close();
+	end
+	clix_connect(opts, on_connect);
+end
--- a/squishy	Sat Feb 08 16:40:00 2014 +0100
+++ b/squishy	Mon Sep 08 12:20:24 2014 +0200
@@ -1,5 +1,6 @@
 local commands = {
 	"send";
+	"sendfilecontent";
 	"receive";
 	"version";
 	"ping";