-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo_jabber_server.groovy
executable file
·54 lines (41 loc) · 1.43 KB
/
todo_jabber_server.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env groovy -cp lib/smack.jar:lib/smackx.jar
import java.io.*
import org.jivesoftware.smack.*
import org.jivesoftware.smack.packet.*
import org.jivesoftware.smack.filter.*
def connection = new XMPPConnection("jabber.org")
connection.connect()
connection.login("todobot123", "passwd")
presence = new Presence(Presence.Type.available)
presence.setStatus("Getting Things Done!")
connection.sendPacket(presence)
filter = new AndFilter();
filter.addFilter(new FromMatchesFilter("[email protected]"));
filter.addFilter(new PacketTypeFilter(Message.class));
class TodoPacketListener implements PacketListener {
private XMPPConnection connection
TodoPacketListener(XMPPConnection connection) {
this.connection = connection
}
void processPacket(Packet packet) {
try {
def message = (Message) packet
def program = ["/Users/i_gouss/bin/todo.py", "-p"]
def args = message.getBody().split().toList();
program.addAll(args)
def proc = program.execute()
proc.waitFor()
def reply = new Message(message.getFrom(), Message.Type.chat)
reply.setFrom(message.getTo())
reply.setThread(message.getThread())
reply.setBody(proc.in.text)
connection.sendPacket(reply)
} catch(Exception ex) {
println ex
}
}
}
connection.addPacketListener(new TodoPacketListener(connection), filter)
InputStreamReader converter = new InputStreamReader(System.in)
BufferedReader input = new BufferedReader(converter)
input.readLine()