mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-29 05:02:20 +03:00
ping ability was added and logs reviewed
This commit is contained in:
parent
f167d9c8c3
commit
95abee215d
1 changed files with 21 additions and 5 deletions
|
@ -36,11 +36,23 @@ class Messager(slixmpp.ClientXMPP):
|
||||||
self.hostname = self.configuration_manager.get('CONNECTION', 'host')
|
self.hostname = self.configuration_manager.get('CONNECTION', 'host')
|
||||||
self.receiver = self.configuration_manager.get('CONNECTION', 'receiverjid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/Smack'
|
self.receiver = self.configuration_manager.get('CONNECTION', 'receiverjid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/Smack'
|
||||||
self.receive_file_path = self.configuration_manager.get('CONNECTION', 'receivefileparam')
|
self.receive_file_path = self.configuration_manager.get('CONNECTION', 'receivefileparam')
|
||||||
self.logger.debug('[Messager] XMPP Receiver parameters were set')
|
self.logger.debug('[Messager] XMPP Messager parameters were set')
|
||||||
|
|
||||||
self.register_extensions()
|
self.register_extensions()
|
||||||
self.add_listeners()
|
self.add_listeners()
|
||||||
|
|
||||||
|
def ping_lider(self):
|
||||||
|
try:
|
||||||
|
result = self['xep_0199'].send_ping(jid=self.receiver,timeout=10)
|
||||||
|
if result is False:
|
||||||
|
self.logger.debug('[Messager] Couldn\'t send ping to lider.')
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error('[Messager] A problem occurred while pinging to lider. Error Message:{}'.format(str(e)))
|
||||||
|
return False
|
||||||
|
|
||||||
def add_listeners(self):
|
def add_listeners(self):
|
||||||
self.add_event_handler('session_start', self.session_start)
|
self.add_event_handler('session_start', self.session_start)
|
||||||
self.add_event_handler('session_end', self.session_end)
|
self.add_event_handler('session_end', self.session_end)
|
||||||
|
@ -109,15 +121,19 @@ class Messager(slixmpp.ClientXMPP):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def send_direct_message(self, msg):
|
def send_direct_message(self, msg):
|
||||||
self.logger.debug('[Messager] Sending message: ' + msg)
|
try:
|
||||||
self.send_message(mto=self.receiver, mbody=msg, mtype='normal')
|
self.logger.debug('[Messager] Sending message: ' + msg)
|
||||||
print('<---' + msg)
|
self.send_message(mto=self.receiver, mbody=msg, mtype='normal')
|
||||||
|
print('<---' + msg)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.debug('[Messager] A problem occurred while sending direct message. Error Message: {}'.format(str(e)))
|
||||||
|
|
||||||
def recv_direct_message(self, msg):
|
def recv_direct_message(self, msg):
|
||||||
if msg['type'] in ('chat', 'normal'):
|
if msg['type'] in ('chat', 'normal'):
|
||||||
j = json.loads(str(msg['body']))
|
j = json.loads(str(msg['body']))
|
||||||
|
self.logger.debug('[Messager] Received message: {}'.format(str(msg['body'])))
|
||||||
message_type = j['type']
|
message_type = j['type']
|
||||||
self.logger.debug('[Messager] Fired event is: ' + message_type)
|
self.logger.debug('[Messager] Fired event is: {}' .format(message_type))
|
||||||
print('----->' + str(msg['body']))
|
print('----->' + str(msg['body']))
|
||||||
self.event_manger.fireEvent(message_type, str(msg['body']))
|
self.event_manger.fireEvent(message_type, str(msg['body']))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue