import sys import os import xmpp def msg_cb conn msg user cmd msg getF

 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
import sys
import os
import xmpp
def msg_cb(conn, msg):
user, cmd = msg.getFrom(), msg.getBody()
if cmd:
reply = os.popen(cmd).read()
if reply:
conn.send(xmpp.Message(user,reply))
def step_on(conn):
try:
conn.Process(1)
except KeyboardInterrupt:
return False
return True
def go_on(conn):
while step_on(conn):
pass
def main():
if len(sys.argv) < 3:
print 'Usage: python main.py <username> <server> <password>'
sys.exit(1)
user, server, pwd = sys.argv[1:]
conn = xmpp.Client(server)
conn_res = conn.connect()
auth_res = conn.auth(user, pwd)
conn.RegisterHandler('message', msg_cb)
conn.sendInitPresence()
print 'Bot started'
go_on(conn)
if __name__ == '__main__':
main()