clix/sendfilecontent.lua

Mon, 23 Nov 2020 23:52:31 +0100

author
Kim Alvefur <zash@zash.se>
date
Mon, 23 Nov 2020 23:52:31 +0100
changeset 145
6e05b25c2669
parent 103
45843df81db0
child 164
fafdcde2e2eb
permissions
-rw-r--r--

clix.watch_pep: Move invocation syntax out of short help

So it doesn't clutter the command listing

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

mercurial