-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmppclient.py
34 lines (24 loc) · 1.04 KB
/
xmppclient.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
30
31
32
33
34
import sleekxmpp
import logging
from threading import Event
class XmppClient(sleekxmpp.ClientXMPP):
def __init__(self, jid, password, muc, nickname):
super(XmppClient, self).__init__(jid, password)
self.MUC = muc
self.NICKNAME = nickname
self.connected = Event()
# logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s')
self.register_plugin('xep_0045')
self.add_event_handler('session_start', self.start)
self.add_event_handler("on_message", self.message)
def start(self, event):
self.send_presence()
self.get_roster()
self.plugin['xep_0045'].joinMUC(self.MUC, self.NICKNAME, wait=True)
self.connected.set()
def on_message(self, msg):
print "RECEIVED %s" %(msg)
def message(self, to, msg):
return self.send_message(mto=to, mbody=msg, mtype="chat")
def muc_message(self, to, msg):
return self.send_message(mto=to, mbody=msg, mtype="groupchat")