Merge pull request #23 from PidgeyL/master

More actions on "listening"
This commit is contained in:
Pidgey
2016-01-11 09:06:09 +01:00
2 changed files with 38 additions and 28 deletions

View File

@@ -15,7 +15,7 @@ from .client import *
__copyright__ = 'Copyright 2015 by Taehoon Kim' __copyright__ = 'Copyright 2015 by Taehoon Kim'
__version__ = '0.3.0' __version__ = '0.3.1'
__license__ = 'BSD' __license__ = 'BSD'
__author__ = 'Taehoon Kim; Moreels Pieter-Jan' __author__ = 'Taehoon Kim; Moreels Pieter-Jan'
__email__ = 'carpedm20@gmail.com' __email__ = 'carpedm20@gmail.com'

View File

@@ -237,7 +237,6 @@ class Client(object):
# if user doesn't enter l or m or s, then use the large one # if user doesn't enter l or m or s, then use the large one
sticker = LIKES['l'] sticker = LIKES['l']
data["message_batch[0][sticker_id]"] = sticker data["message_batch[0][sticker_id]"] = sticker
r = self._post(SendURL, data) r = self._post(SendURL, data)
return r.ok return r.ok
@@ -407,31 +406,32 @@ class Client(object):
if 'ms' not in content: if 'ms' not in content:
return return
for m in content['ms']: for m in content['ms']:
if m['type'] in ['m_messaging', 'messaging']: try:
try: if m['type'] in ['m_messaging', 'messaging']:
mid = m['message']['mid'] if m['event'] in ['deliver']:
message=m['message']['body'] mid = m['message']['mid']
fbid = m['message']['sender_fbid'] message=m['message']['body']
name = m['message']['sender_name'] fbid = m['message']['sender_fbid']
self.on_message(mid, fbid, name, message, m) name = m['message']['sender_name']
except: self.on_message(mid, fbid, name, message, m)
pass elif m['type'] in ['typ']:
elif m['type'] in ['typ']: self.on_typing(m["from"])
try: elif m['type'] in ['m_read_receipt']:
fbid = m["from"] self.on_read(m['realtime_viewer_fbid'], m['reader'], m['time'])
self.on_typing(fbid) elif m['type'] in ['inbox']:
except: viewer = m['realtime_viewer_fbid']
pass unseen = m['unseen']
elif m['type'] in ['m_read_receipt']: unread = m['unread']
try: other_unseen = m['other_unseen']
author = m['author'] other_unread = m['other_unread']
reader = m['reader'] timestamp = m['seen_timestamp']
time = m['time'] self.on_inbox(viewer, unseen, unread, other_unseen, other_unread, timestamp)
self.on_read(author, reader, time) elif m['type'] in ['qprimer']:
except: self.on_qprimer(m['made'])
pass else:
else: print(m)
print(m) except Exception as e:
self.on_message_error(e, m)
def listen(self, markAlive=True): def listen(self, markAlive=True):
self.listening = True self.listening = True
@@ -445,7 +445,7 @@ class Client(object):
if markAlive: self.ping(sticky) if markAlive: self.ping(sticky)
try: try:
content = self._pullMessage(sticky, pool) content = self._pullMessage(sticky, pool)
self._parseMessage(content) if content: self._parseMessage(content)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
continue continue
except KeyboardInterrupt: except KeyboardInterrupt:
@@ -463,3 +463,13 @@ class Client(object):
def on_read(self, author, reader, time): def on_read(self, author, reader, time):
pass pass
def on_inbox(self, viewer, unseen, unread, other_unseen, other_unread, timestamp):
pass
def on_message_error(self, exception, message):
print("Exception: ")
print(exception)
def on_qprimer(self, timestamp):
pass