| 1 | local verse = require "verse"; |
| 2 | return function (opts, arg) |
| 3 | if opts.short_help then |
| 4 | print("Send file content"); |
| 5 | return; |
| 6 | end |
| 7 | |
| 8 | local function on_connect(conn) |
| 9 | local function send_message(text) |
| 10 | conn:send(verse.message({ to = opts.to, |
| 11 | type = opts.type or (opts.chatroom and "groupchat") or "chat" }) |
| 12 | :body(text)); |
| 13 | end |
| 14 | if opts.file then |
| 15 | local f, err = io.open(opts.file, "rb") |
| 16 | if not f then |
| 17 | conn:error("Unable to open file: %s", err); |
| 18 | else |
| 19 | local content = f:read("*all") |
| 20 | f:close() |
| 21 | if content:len() < 2000 then |
| 22 | send_message(content); |
| 23 | else |
| 24 | conn:error("File size too large. Cannot send file"); |
| 25 | end |
| 26 | end |
| 27 | end |
| 28 | conn:close(); |
| 29 | end |
| 30 | clix_connect(opts, on_connect); |
| 31 | end |