clix/sendfilecontent.lua

Wed, 20 Aug 2014 12:05:46 +0200

author
Marc Fauser
date
Wed, 20 Aug 2014 12:05:46 +0200
changeset 102
f1166645a56c
child 103
45843df81db0
permissions
-rw-r--r--

new sendfilecontent plugin
- todo: add full or relative path possibility. not only current path

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

mercurial