clix/sendfilecontent.lua

changeset 102
f1166645a56c
child 103
45843df81db0
equal deleted inserted replaced
101:956242b7d5df 102:f1166645a56c
1 return function (opts, arg)
2 if opts.short_help then
3 print("Send file content");
4 return;
5 end
6 local function on_connect(conn)
7 local function send_message(text)
8 conn:send(verse.message({ to = opts.to,
9 type = opts.type or (opts.chatroom and "groupchat") or "chat" })
10 :body(text));
11 end
12 if opts.file then
13 local f = io.open(opts.file, "rb")
14 local content = f:read("*all")
15 f:close()
16 if content:len() < 2000 then
17 send_message(content);
18 else
19 conn:error("File size too large. Cannot send file");
20 end
21 conn:close();
22 end
23 end
24 clix_connect(opts, on_connect);
25 end

mercurial