Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2c0d098852 | ||
|
e4290cd465 | ||
|
46b85dec5c | ||
|
bbc34bd009 | ||
|
c495317e65 | ||
|
a946050228 | ||
|
83789dcefa | ||
|
4f1f9bf1ce | ||
|
32c72c2f35 | ||
|
42ae0035af | ||
|
96e28fdbe6 | ||
|
0f889f50cf |
@@ -27,4 +27,8 @@ Installation:
|
||||
|
||||
$ pip install fbchat
|
||||
|
||||
Copyright 2015 - 2017 by Taehoon Kim / `@carpedm20 <http://carpedm20.github.io/about/>`__
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
- Mads Marquart / `@madsmtm <https://github.com/madsmtm>`__
|
||||
- Taehoon Kim / `@carpedm20 <http://carpedm20.github.io/about/>`__
|
||||
|
@@ -17,7 +17,7 @@ from .client import *
|
||||
|
||||
|
||||
__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
|
||||
__version__ = '1.1.1'
|
||||
__version__ = '1.2.1'
|
||||
__license__ = 'BSD'
|
||||
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
|
||||
__email__ = 'carpedm20@gmail.com'
|
||||
|
@@ -479,7 +479,7 @@ class Client(object):
|
||||
if k['id'] in ['0', 0]:
|
||||
# Skip invalid users
|
||||
pass
|
||||
users.append(User(k['id'], first_name=k.get('firstName'), url=k.get('uri'), photo=k.get('thumbSrc'), name=k.get('name'), is_friend=k.get('is_friend'), gender=GENDERS[k.get('gender')]))
|
||||
users.append(User(k['id'], first_name=k.get('firstName'), url=k.get('uri'), photo=k.get('thumbSrc'), name=k.get('name'), is_friend=k.get('is_friend'), gender=GENDERS.get(k.get('gender'))))
|
||||
|
||||
return users
|
||||
|
||||
@@ -791,7 +791,7 @@ class Client(object):
|
||||
if p['type'] == 'page':
|
||||
participants[p['fbid']] = Page(p['fbid'], url=p['href'], photo=p['image_src'], name=p['name'])
|
||||
elif p['type'] == 'user':
|
||||
participants[p['fbid']] = User(p['fbid'], url=p['href'], first_name=p['short_name'], is_friend=p['is_friend'], gender=GENDERS[p['gender']], photo=p['image_src'], name=p['name'])
|
||||
participants[p['fbid']] = User(p['fbid'], url=p['href'], first_name=p['short_name'], is_friend=p['is_friend'], gender=GENDERS.get(p['gender']), photo=p['image_src'], name=p['name'])
|
||||
else:
|
||||
raise FBchatException('A participant had an unknown type {}: {}'.format(p['type'], p))
|
||||
|
||||
@@ -853,7 +853,7 @@ class Client(object):
|
||||
:raises: FBChatException if request failed
|
||||
"""
|
||||
image_id = str(image_id)
|
||||
j = checkRequest(self._get(ReqUrl.ATTACHMENT_PHOTO, query={'photo_id': str(image_id)}))
|
||||
j = check_request(self._get(ReqUrl.ATTACHMENT_PHOTO, query={'photo_id': str(image_id)}))
|
||||
|
||||
url = get_jsmods_require(j, 3)
|
||||
if url is None:
|
||||
@@ -987,7 +987,7 @@ class Client(object):
|
||||
Deprecated. Use :func:`fbchat.Client.send` instead
|
||||
"""
|
||||
thread_id, thread_type = self._getThread(thread_id, thread_type)
|
||||
data = self._getSendData(message=message, thread_id=thread_id, thread_type=thread_type)
|
||||
data = self._getSendData(message=self._oldMessage(message), thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
data['action_type'] = 'ma-type:user-generated-message'
|
||||
data['has_attachment'] = True
|
||||
@@ -1248,7 +1248,7 @@ class Client(object):
|
||||
:type thread_type: models.ThreadType
|
||||
:raises: FBchatException if request failed
|
||||
"""
|
||||
thread_id, thread_type = self._getThread(thread_id, None)
|
||||
thread_id, thread_type = self._getThread(thread_id, thread_type)
|
||||
|
||||
data = {
|
||||
"typ": status.value,
|
||||
@@ -1482,20 +1482,20 @@ class Client(object):
|
||||
try:
|
||||
for a in delta['attachments']:
|
||||
mercury = a['mercury']
|
||||
if mercury.get('attach_type'):
|
||||
if mercury.get('blob_attachment'):
|
||||
image_metadata = a.get('imageMetadata', {})
|
||||
attach_type = mercury['attach_type']
|
||||
attach_type = mercury['blob_attachment']['__typename']
|
||||
attachment = graphql_to_attachment(mercury.get('blob_attachment', {}))
|
||||
|
||||
if attach_type == ['file', 'video']:
|
||||
if attach_type == ['MessageFile', 'MessageVideo', 'MessageAudio']:
|
||||
# TODO: Add more data here for audio files
|
||||
attachment.size = int(a['fileSize'])
|
||||
elif attach_type == 'share':
|
||||
attachments.append(attachment)
|
||||
elif mercury.get('sticker_attachment'):
|
||||
sticker = graphql_to_sticker(a['mercury']['sticker_attachment'])
|
||||
elif mercury.get('extensible_attachment'):
|
||||
# TODO: Add more data here for shared stuff (URLs, events and so on)
|
||||
pass
|
||||
attachments.append(attachment)
|
||||
if a['mercury'].get('sticker_attachment'):
|
||||
sticker = graphql_to_sticker(a['mercury']['sticker_attachment'])
|
||||
except Exception:
|
||||
log.exception('An exception occured while reading attachments: {}'.format(delta['attachments']))
|
||||
|
||||
@@ -1526,10 +1526,15 @@ class Client(object):
|
||||
self.onInbox(unseen=m["unseen"], unread=m["unread"], recent_unread=m["recent_unread"], msg=m)
|
||||
|
||||
# Typing
|
||||
# elif mtype == "typ":
|
||||
# author_id = str(m.get("from"))
|
||||
# typing_status = TypingStatus(m.get("st"))
|
||||
# self.onTyping(author_id=author_id, typing_status=typing_status)
|
||||
elif mtype == "typ":
|
||||
author_id = str(m.get("from"))
|
||||
thread_id = str(m.get("to"))
|
||||
if thread_id == self.uid:
|
||||
thread_type = ThreadType.USER
|
||||
else:
|
||||
thread_type = ThreadType.GROUP
|
||||
typing_status = TypingStatus(m.get("st"))
|
||||
self.onTyping(author_id=author_id, status=typing_status, thread_id=thread_id, thread_type=thread_type, msg=m)
|
||||
|
||||
# Delivered
|
||||
|
||||
@@ -1849,6 +1854,20 @@ class Client(object):
|
||||
"""
|
||||
log.info('Inbox event: {}, {}, {}'.format(unseen, unread, recent_unread))
|
||||
|
||||
def onTyping(self, author_id=None, status=None, thread_id=None, thread_type=None, msg=None):
|
||||
"""
|
||||
Called when the client is listening, and somebody starts or stops typing into a chat
|
||||
|
||||
:param author_id: The ID of the person who sent the action
|
||||
:param status: The typing status
|
||||
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
|
||||
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
|
||||
:param msg: A full set of the data recieved
|
||||
:type typing_status: models.TypingStatus
|
||||
:type thread_type: models.ThreadType
|
||||
"""
|
||||
pass
|
||||
|
||||
def onQprimer(self, ts=None, msg=None):
|
||||
"""
|
||||
Called when the client just started listening
|
||||
|
@@ -154,7 +154,7 @@ def graphql_to_user(user):
|
||||
first_name=user.get('first_name'),
|
||||
last_name=user.get('last_name'),
|
||||
is_friend=user.get('is_viewer_friend'),
|
||||
gender=GENDERS[user.get('gender')],
|
||||
gender=GENDERS.get(user.get('gender')),
|
||||
affinity=user.get('affinity'),
|
||||
nickname=c_info.get('nickname'),
|
||||
color=c_info.get('color'),
|
||||
|
@@ -74,13 +74,12 @@ GENDERS = {
|
||||
#'': 'female_singular_guess',
|
||||
#'': 'male_singular_guess',
|
||||
#'': 'mixed',
|
||||
#'': 'neuter_singular',
|
||||
'NEUTER': 'neuter_singular',
|
||||
#'': 'unknown_singular',
|
||||
#'': 'female_plural',
|
||||
#'': 'male_plural',
|
||||
#'': 'neuter_plural',
|
||||
#'': 'unknown_plural',
|
||||
None: None
|
||||
}
|
||||
|
||||
class ReqUrl(object):
|
||||
|
Reference in New Issue
Block a user