-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxmpp.py
29 lines (23 loc) · 871 Bytes
/
xmpp.py
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
from twisted.words.xish import domish
from wokkel.xmppim import MessageProtocol, AvailablePresence
class XMPPBot(MessageProtocol):
def __init__(self, config):
self.config = config
def connectionMade(self):
# send initial presence
self.send(AvailablePresence())
def connectionLost(self, reason):
print "Disconnected!"
def sendMsg(self, dest, message):
reply = domish.Element((None, "message"))
reply["to"] = dest
reply["type"] = 'chat'
reply.addElement("body", content=message)
self.send(reply)
def msg(self, message):
split = message.split()
if split[0].lower() in self.config['users']:
self.sendMsg(split[0], message[message.find(' ')+1:])
else:
for dest in self.config['users']:
self.sendMsg(dest, message)