Update client.py
This commit is contained in:
@@ -176,6 +176,7 @@ class Client(object):
|
||||
|
||||
:param name: name of a person
|
||||
"""
|
||||
|
||||
payload = {
|
||||
'value' : name.lower(),
|
||||
'viewer' : self.uid,
|
||||
@@ -230,6 +231,7 @@ class Client(object):
|
||||
'message_batch[0][thread_fbid]' : thread_id,
|
||||
'message_batch[0][has_attachment]' : False
|
||||
}
|
||||
|
||||
if like:
|
||||
try:
|
||||
sticker = LIKES[like.lower()]
|
||||
@@ -237,9 +239,11 @@ class Client(object):
|
||||
# if user doesn't enter l or m or s, then use the large one
|
||||
sticker = LIKES['l']
|
||||
data["message_batch[0][sticker_id]"] = sticker
|
||||
|
||||
r = self._post(SendURL, data)
|
||||
return r.ok
|
||||
|
||||
|
||||
def getThreadInfo(self, userID, start, end=None):
|
||||
"""Get the info of one Thread
|
||||
|
||||
@@ -247,6 +251,7 @@ class Client(object):
|
||||
:param start: the start index of a thread
|
||||
:param end: (optional) the last index of a thread
|
||||
"""
|
||||
|
||||
if not end: end = start + 20
|
||||
if end <= start: end = start + end
|
||||
|
||||
@@ -262,6 +267,7 @@ class Client(object):
|
||||
j = get_json(r.text)
|
||||
if not j['payload']:
|
||||
return None
|
||||
|
||||
messages = []
|
||||
for message in j['payload']['actions']:
|
||||
messages.append(Message(**message))
|
||||
@@ -274,6 +280,7 @@ class Client(object):
|
||||
:param start: the start index of a thread
|
||||
:param end: (optional) the last index of a thread
|
||||
"""
|
||||
|
||||
if not end: end = start + 20
|
||||
if end <= start: end = start + end
|
||||
|
||||
@@ -320,6 +327,7 @@ class Client(object):
|
||||
'last_action_timestamp': now() - 60*1000
|
||||
#'last_action_timestamp': 0
|
||||
}
|
||||
|
||||
r = self._post(ThreadSyncURL, form)
|
||||
if not r.ok or len(r.text) == 0:
|
||||
return None
|
||||
@@ -327,7 +335,8 @@ class Client(object):
|
||||
j = get_json(r.text)
|
||||
result = {
|
||||
"message_counts": j['payload']['message_counts'],
|
||||
"unseen_threads": j['payload']['unseen_thread_ids']}
|
||||
"unseen_threads": j['payload']['unseen_thread_ids']
|
||||
}
|
||||
return result
|
||||
|
||||
def markAsDelivered(self, userID, threadID):
|
||||
@@ -339,11 +348,13 @@ class Client(object):
|
||||
def markAsRead(self, userID):
|
||||
data = {
|
||||
"watermarkTimestamp": now(),
|
||||
"shouldSendReadReceipt": True}
|
||||
"shouldSendReadReceipt": True
|
||||
}
|
||||
data["ids[%s]"%userID] = True
|
||||
r = self._post(ReadStatusURL, data)
|
||||
return r.ok
|
||||
|
||||
|
||||
def markAsSeen(self):
|
||||
r = self._post(MarkSeenURL, {"seen_timestamp": 0})
|
||||
return r.ok
|
||||
@@ -368,6 +379,7 @@ class Client(object):
|
||||
Call pull api to get sticky and pool parameter,
|
||||
newer api needs these parameter to work.
|
||||
'''
|
||||
|
||||
data = {"msgs_recv": 0}
|
||||
|
||||
r = self._get(StickyURL, data)
|
||||
@@ -385,6 +397,7 @@ class Client(object):
|
||||
'''
|
||||
Call pull api with seq value to get message data.
|
||||
'''
|
||||
|
||||
data = {
|
||||
"msgs_recv": 0,
|
||||
"sticky_token": sticky,
|
||||
@@ -403,8 +416,8 @@ class Client(object):
|
||||
Get message and author name from content.
|
||||
May contains multiple messages in the content.
|
||||
'''
|
||||
if 'ms' not in content:
|
||||
return
|
||||
|
||||
if 'ms' not in content: return
|
||||
for m in content['ms']:
|
||||
try:
|
||||
if m['type'] in ['m_messaging', 'messaging']:
|
||||
@@ -433,6 +446,7 @@ class Client(object):
|
||||
except Exception as e:
|
||||
self.on_message_error(e, m)
|
||||
|
||||
|
||||
def listen(self, markAlive=True):
|
||||
self.listening = True
|
||||
sticky, pool = self._getSticky()
|
||||
@@ -453,23 +467,29 @@ class Client(object):
|
||||
except requests.exceptions.Timeout:
|
||||
pass
|
||||
|
||||
|
||||
def on_message(self, mid, author_id, author_name, message, metadata):
|
||||
self.markAsDelivered(author_id, mid)
|
||||
self.markAsRead(author_id)
|
||||
print("%s said: %s"%(author_name, message))
|
||||
|
||||
|
||||
def on_typing(self, author_id):
|
||||
pass
|
||||
|
||||
|
||||
def on_read(self, author, reader, time):
|
||||
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
|
||||
|
Reference in New Issue
Block a user