clix/sendfilecontent.lua

changeset 102
f1166645a56c
child 103
45843df81db0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clix/sendfilecontent.lua	Wed Aug 20 12:05:46 2014 +0200
@@ -0,0 +1,25 @@
+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 = io.open(opts.file, "rb")
+            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
+            conn:close();
+		end
+	end
+	clix_connect(opts, on_connect);
+end

mercurial