Compare commits

..

12 Commits

Author SHA1 Message Date
Mads Marquart
2c0d098852 Fixes #240, small backwards-compatablitity issue when sending images 2018-01-08 21:55:11 +01:00
Mads Marquart
e4290cd465 Version up, thanks to @lobstr 2018-01-02 13:40:50 +01:00
Mads Marquart
46b85dec5c Merge remote-tracking branch 'lobstr/master' 2018-01-02 13:40:25 +01:00
Mads Marquart
bbc34bd009 Added onTyping method 2018-01-02 13:33:13 +01:00
cirrux
c495317e65 Fix setTypingStatus to send correctly 2018-01-01 23:11:35 -05:00
cirrux
a946050228 Re-enable typing notification 2017-12-31 12:27:55 -05:00
cirrux
83789dcefa Fix attachment parsing for newer structure 2017-12-26 19:12:10 -05:00
Mads Marquart
4f1f9bf1ce Fixed errors on unknown genders 2017-12-15 23:46:47 +01:00
Mads Marquart
32c72c2f35 Version up, thanks to @Dante383 2017-12-10 20:08:13 +01:00
Dante
42ae0035af typo in function name
checkRequest --> check_request
2017-12-10 14:16:17 +01:00
Mads Marquart
96e28fdbe6 Fixed error when recieving share attachments 2017-11-16 15:14:46 +01:00
Taehoon Kim
0f889f50cf Update README.rst 2017-11-14 17:25:01 +09:00
5 changed files with 43 additions and 21 deletions

View File

@@ -27,4 +27,8 @@ Installation:
$ pip install fbchat $ 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/>`__

View File

@@ -17,7 +17,7 @@ from .client import *
__copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year) __copyright__ = 'Copyright 2015 - {} by Taehoon Kim'.format(datetime.now().year)
__version__ = '1.1.1' __version__ = '1.2.1'
__license__ = 'BSD' __license__ = 'BSD'
__author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart' __author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart'
__email__ = 'carpedm20@gmail.com' __email__ = 'carpedm20@gmail.com'

View File

@@ -479,7 +479,7 @@ class Client(object):
if k['id'] in ['0', 0]: if k['id'] in ['0', 0]:
# Skip invalid users # Skip invalid users
pass 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 return users
@@ -791,7 +791,7 @@ class Client(object):
if p['type'] == 'page': if p['type'] == 'page':
participants[p['fbid']] = Page(p['fbid'], url=p['href'], photo=p['image_src'], name=p['name']) participants[p['fbid']] = Page(p['fbid'], url=p['href'], photo=p['image_src'], name=p['name'])
elif p['type'] == 'user': 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: else:
raise FBchatException('A participant had an unknown type {}: {}'.format(p['type'], p)) raise FBchatException('A participant had an unknown type {}: {}'.format(p['type'], p))
@@ -853,7 +853,7 @@ class Client(object):
:raises: FBChatException if request failed :raises: FBChatException if request failed
""" """
image_id = str(image_id) 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) url = get_jsmods_require(j, 3)
if url is None: if url is None:
@@ -987,7 +987,7 @@ class Client(object):
Deprecated. Use :func:`fbchat.Client.send` instead Deprecated. Use :func:`fbchat.Client.send` instead
""" """
thread_id, thread_type = self._getThread(thread_id, thread_type) 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['action_type'] = 'ma-type:user-generated-message'
data['has_attachment'] = True data['has_attachment'] = True
@@ -1248,7 +1248,7 @@ class Client(object):
:type thread_type: models.ThreadType :type thread_type: models.ThreadType
:raises: FBchatException if request failed :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 = { data = {
"typ": status.value, "typ": status.value,
@@ -1482,20 +1482,20 @@ class Client(object):
try: try:
for a in delta['attachments']: for a in delta['attachments']:
mercury = a['mercury'] mercury = a['mercury']
if mercury.get('attach_type'): if mercury.get('blob_attachment'):
image_metadata = a.get('imageMetadata', {}) image_metadata = a.get('imageMetadata', {})
attach_type = mercury['attach_type'] attach_type = mercury['blob_attachment']['__typename']
attachment = graphql_to_attachment(mercury.get('blob_attachment', {})) 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 # TODO: Add more data here for audio files
attachment.size = int(a['fileSize']) attachment.size = int(a['fileSize'])
elif attach_type == 'share':
# TODO: Add more data here for shared stuff (URLs, events and so on)
pass
attachments.append(attachment) attachments.append(attachment)
if a['mercury'].get('sticker_attachment'): elif mercury.get('sticker_attachment'):
sticker = graphql_to_sticker(a['mercury']['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
except Exception: except Exception:
log.exception('An exception occured while reading attachments: {}'.format(delta['attachments'])) 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) self.onInbox(unseen=m["unseen"], unread=m["unread"], recent_unread=m["recent_unread"], msg=m)
# Typing # Typing
# elif mtype == "typ": elif mtype == "typ":
# author_id = str(m.get("from")) author_id = str(m.get("from"))
# typing_status = TypingStatus(m.get("st")) thread_id = str(m.get("to"))
# self.onTyping(author_id=author_id, typing_status=typing_status) 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 # Delivered
@@ -1849,6 +1854,20 @@ class Client(object):
""" """
log.info('Inbox event: {}, {}, {}'.format(unseen, unread, recent_unread)) 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): def onQprimer(self, ts=None, msg=None):
""" """
Called when the client just started listening Called when the client just started listening

View File

@@ -154,7 +154,7 @@ def graphql_to_user(user):
first_name=user.get('first_name'), first_name=user.get('first_name'),
last_name=user.get('last_name'), last_name=user.get('last_name'),
is_friend=user.get('is_viewer_friend'), is_friend=user.get('is_viewer_friend'),
gender=GENDERS[user.get('gender')], gender=GENDERS.get(user.get('gender')),
affinity=user.get('affinity'), affinity=user.get('affinity'),
nickname=c_info.get('nickname'), nickname=c_info.get('nickname'),
color=c_info.get('color'), color=c_info.get('color'),

View File

@@ -74,13 +74,12 @@ GENDERS = {
#'': 'female_singular_guess', #'': 'female_singular_guess',
#'': 'male_singular_guess', #'': 'male_singular_guess',
#'': 'mixed', #'': 'mixed',
#'': 'neuter_singular', 'NEUTER': 'neuter_singular',
#'': 'unknown_singular', #'': 'unknown_singular',
#'': 'female_plural', #'': 'female_plural',
#'': 'male_plural', #'': 'male_plural',
#'': 'neuter_plural', #'': 'neuter_plural',
#'': 'unknown_plural', #'': 'unknown_plural',
None: None
} }
class ReqUrl(object): class ReqUrl(object):