Thu, 07 Jan 2010 21:22:27 +0000
clix, clix.send: Support for chatrooms (-c/--chatroom with --nick=somenick)
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
1 | short_opts.i = "interactive"; |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
2 | short_opts.e = "echo"; |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
3 | |
0 | 4 | return function (opts, arg) |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
5 | if (#arg == 0 or opts.help) and not opts.interactive then |
0 | 6 | return 0; |
7 | end | |
8 | local function on_connect(conn) | |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
9 | local function send_message(text) |
21
cdeb02d9546d
clix, clix.send: Support for chatrooms (-c/--chatroom with --nick=somenick)
Matthew Wild <mwild1@gmail.com>
parents:
18
diff
changeset
|
10 | conn:send(verse.message({ to = opts.to, |
cdeb02d9546d
clix, clix.send: Support for chatrooms (-c/--chatroom with --nick=somenick)
Matthew Wild <mwild1@gmail.com>
parents:
18
diff
changeset
|
11 | type = opts.type or (opts.chatroom and "groupchat") or "chat" }) |
cdeb02d9546d
clix, clix.send: Support for chatrooms (-c/--chatroom with --nick=somenick)
Matthew Wild <mwild1@gmail.com>
parents:
18
diff
changeset
|
12 | :body(text)); |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
13 | end |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
14 | if opts.interactive or opts.stdin then |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
15 | -- Fake socket object around stdin |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
16 | local stdin = { |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
17 | getfd = function () return 0; end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
18 | dirty = function (self) return false; end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
19 | settimeout = function () end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
20 | send = function (_, d) return #d, 0; end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
21 | close = function () end; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
22 | receive = function (_, patt) |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
23 | local data = io.stdin:read(patt); |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
24 | if opts.echo then |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
25 | io.write(data, patt == "*l" and "\n" or ""); |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
26 | end |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
27 | return data; |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
28 | end |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
29 | }; |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
30 | local function on_incoming(stdin, text) |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
31 | send_message(text); |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
32 | if not opts.interactive then |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
33 | conn:close(); |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
34 | end |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
35 | end |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
36 | stdin = require "net.server".wrapclient(stdin, "stdin", 0, { |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
37 | onincoming = on_incoming, ondisconnect = function () end |
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
38 | }, "*l"); |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
39 | else |
18
6ad3ea055905
clix.send: Add --stdin flag to indicate to read data from stdin (but not interactively)
Matthew Wild <mwild1@gmail.com>
parents:
16
diff
changeset
|
40 | send_message(table.concat(arg, " ")); |
9
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
41 | conn:close(); |
c1d591488695
clix.message: Add -i/--interactive to allow piping stdin over XMPP (like sendxmpp)
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
42 | end |
0 | 43 | end |
44 | clix_connect(opts, on_connect); | |
45 | end |