Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1460b2f421 | ||
|
27f76ba659 | ||
|
589117b9e7 | ||
|
80300cd160 | ||
|
76171408cc | ||
|
c1800a174f | ||
|
8ae8435940 | ||
|
f916cb3b53 | ||
|
929c2137bf | ||
|
98056e91c5 | ||
|
944a7248c3 | ||
|
caa2ecd0b7 | ||
|
dfc2d0652f | ||
|
8d25540445 | ||
|
6ea174bfd4 | ||
|
56e43aec0e | ||
|
491d120c25 |
@@ -5,6 +5,7 @@ python: 3.6
|
|||||||
cache: pip
|
cache: pip
|
||||||
|
|
||||||
before_install: pip install flit
|
before_install: pip install flit
|
||||||
|
# Use `--deps production` so that we don't install unnecessary dependencies
|
||||||
install: flit install --deps production --extras test
|
install: flit install --deps production --extras test
|
||||||
script: pytest -m offline
|
script: pytest -m offline
|
||||||
|
|
||||||
@@ -53,3 +54,8 @@ jobs:
|
|||||||
script: flit publish
|
script: flit publish
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email:
|
||||||
|
on_success: never
|
||||||
|
on_failure: change
|
||||||
|
@@ -174,5 +174,5 @@ html_sidebars = {"**": ["sidebar.html", "searchbox.html"]}
|
|||||||
|
|
||||||
html_show_sphinx = False
|
html_show_sphinx = False
|
||||||
html_show_sourcelink = False
|
html_show_sourcelink = False
|
||||||
autoclass_content = "init"
|
autoclass_content = "both"
|
||||||
html_short_title = description
|
html_short_title = description
|
||||||
|
@@ -7,10 +7,11 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from .models import *
|
||||||
from .client import *
|
from .client import *
|
||||||
|
|
||||||
__title__ = "fbchat"
|
__title__ = "fbchat"
|
||||||
__version__ = "1.6.2"
|
__version__ = "1.6.4"
|
||||||
__description__ = "Facebook Chat (Messenger) for Python"
|
__description__ = "Facebook Chat (Messenger) for Python"
|
||||||
|
|
||||||
__copyright__ = "Copyright 2015 - 2019 by Taehoon Kim"
|
__copyright__ = "Copyright 2015 - 2019 by Taehoon Kim"
|
||||||
|
48
fbchat/_attachment.py
Normal file
48
fbchat/_attachment.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class Attachment(object):
|
||||||
|
"""Represents a Facebook attachment"""
|
||||||
|
|
||||||
|
#: The attachment ID
|
||||||
|
uid = attr.ib(None)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class UnsentMessage(Attachment):
|
||||||
|
"""Represents an unsent message attachment"""
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class ShareAttachment(Attachment):
|
||||||
|
"""Represents a shared item (eg. URL) that has been sent as a Facebook attachment"""
|
||||||
|
|
||||||
|
#: ID of the author of the shared post
|
||||||
|
author = attr.ib(None)
|
||||||
|
#: Target URL
|
||||||
|
url = attr.ib(None)
|
||||||
|
#: Original URL if Facebook redirects the URL
|
||||||
|
original_url = attr.ib(None)
|
||||||
|
#: Title of the attachment
|
||||||
|
title = attr.ib(None)
|
||||||
|
#: Description of the attachment
|
||||||
|
description = attr.ib(None)
|
||||||
|
#: Name of the source
|
||||||
|
source = attr.ib(None)
|
||||||
|
#: URL of the attachment image
|
||||||
|
image_url = attr.ib(None)
|
||||||
|
#: URL of the original image if Facebook uses `safe_image`
|
||||||
|
original_image_url = attr.ib(None)
|
||||||
|
#: Width of the image
|
||||||
|
image_width = attr.ib(None)
|
||||||
|
#: Height of the image
|
||||||
|
image_height = attr.ib(None)
|
||||||
|
#: List of additional attachments
|
||||||
|
attachments = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
|
||||||
|
|
||||||
|
# Put here for backwards compatibility, so that the init argument order is preserved
|
||||||
|
uid = attr.ib(None)
|
12
fbchat/_core.py
Normal file
12
fbchat/_core.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import aenum
|
||||||
|
|
||||||
|
|
||||||
|
class Enum(aenum.Enum):
|
||||||
|
"""Used internally by fbchat to support enumerations"""
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
# For documentation:
|
||||||
|
return "{}.{}".format(type(self).__name__, self.name)
|
32
fbchat/_exception.py
Normal file
32
fbchat/_exception.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|
||||||
|
class FBchatException(Exception):
|
||||||
|
"""Custom exception thrown by fbchat. All exceptions in the fbchat module inherits this"""
|
||||||
|
|
||||||
|
|
||||||
|
class FBchatFacebookError(FBchatException):
|
||||||
|
#: The error code that Facebook returned
|
||||||
|
fb_error_code = None
|
||||||
|
#: The error message that Facebook returned (In the user's own language)
|
||||||
|
fb_error_message = None
|
||||||
|
#: The status code that was sent in the http response (eg. 404) (Usually only set if not successful, aka. not 200)
|
||||||
|
request_status_code = None
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
message,
|
||||||
|
fb_error_code=None,
|
||||||
|
fb_error_message=None,
|
||||||
|
request_status_code=None,
|
||||||
|
):
|
||||||
|
super(FBchatFacebookError, self).__init__(message)
|
||||||
|
"""Thrown by fbchat when Facebook returns an error"""
|
||||||
|
self.fb_error_code = str(fb_error_code)
|
||||||
|
self.fb_error_message = fb_error_message
|
||||||
|
self.request_status_code = request_status_code
|
||||||
|
|
||||||
|
|
||||||
|
class FBchatUserError(FBchatException):
|
||||||
|
"""Thrown by fbchat when wrong values are entered"""
|
197
fbchat/_file.py
Normal file
197
fbchat/_file.py
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
from ._attachment import Attachment
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class FileAttachment(Attachment):
|
||||||
|
"""Represents a file that has been sent as a Facebook attachment"""
|
||||||
|
|
||||||
|
#: Url where you can download the file
|
||||||
|
url = attr.ib(None)
|
||||||
|
#: Size of the file in bytes
|
||||||
|
size = attr.ib(None)
|
||||||
|
#: Name of the file
|
||||||
|
name = attr.ib(None)
|
||||||
|
#: Whether Facebook determines that this file may be harmful
|
||||||
|
is_malicious = attr.ib(None)
|
||||||
|
|
||||||
|
# Put here for backwards compatibility, so that the init argument order is preserved
|
||||||
|
uid = attr.ib(None)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class AudioAttachment(Attachment):
|
||||||
|
"""Represents an audio file that has been sent as a Facebook attachment"""
|
||||||
|
|
||||||
|
#: Name of the file
|
||||||
|
filename = attr.ib(None)
|
||||||
|
#: Url of the audio file
|
||||||
|
url = attr.ib(None)
|
||||||
|
#: Duration of the audioclip in milliseconds
|
||||||
|
duration = attr.ib(None)
|
||||||
|
#: Audio type
|
||||||
|
audio_type = attr.ib(None)
|
||||||
|
|
||||||
|
# Put here for backwards compatibility, so that the init argument order is preserved
|
||||||
|
uid = attr.ib(None)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class ImageAttachment(Attachment):
|
||||||
|
"""Represents an image that has been sent as a Facebook attachment
|
||||||
|
|
||||||
|
To retrieve the full image url, use: :func:`fbchat.Client.fetchImageUrl`, and pass
|
||||||
|
it the uid of the image attachment
|
||||||
|
"""
|
||||||
|
|
||||||
|
#: The extension of the original image (eg. 'png')
|
||||||
|
original_extension = attr.ib(None)
|
||||||
|
#: Width of original image
|
||||||
|
width = attr.ib(None, converter=lambda x: None if x is None else int(x))
|
||||||
|
#: Height of original image
|
||||||
|
height = attr.ib(None, converter=lambda x: None if x is None else int(x))
|
||||||
|
|
||||||
|
#: Whether the image is animated
|
||||||
|
is_animated = attr.ib(None)
|
||||||
|
|
||||||
|
#: URL to a thumbnail of the image
|
||||||
|
thumbnail_url = attr.ib(None)
|
||||||
|
|
||||||
|
#: URL to a medium preview of the image
|
||||||
|
preview_url = attr.ib(None)
|
||||||
|
#: Width of the medium preview image
|
||||||
|
preview_width = attr.ib(None)
|
||||||
|
#: Height of the medium preview image
|
||||||
|
preview_height = attr.ib(None)
|
||||||
|
|
||||||
|
#: URL to a large preview of the image
|
||||||
|
large_preview_url = attr.ib(None)
|
||||||
|
#: Width of the large preview image
|
||||||
|
large_preview_width = attr.ib(None)
|
||||||
|
#: Height of the large preview image
|
||||||
|
large_preview_height = attr.ib(None)
|
||||||
|
|
||||||
|
#: URL to an animated preview of the image (eg. for gifs)
|
||||||
|
animated_preview_url = attr.ib(None)
|
||||||
|
#: Width of the animated preview image
|
||||||
|
animated_preview_width = attr.ib(None)
|
||||||
|
#: Height of the animated preview image
|
||||||
|
animated_preview_height = attr.ib(None)
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
original_extension=None,
|
||||||
|
width=None,
|
||||||
|
height=None,
|
||||||
|
is_animated=None,
|
||||||
|
thumbnail_url=None,
|
||||||
|
preview=None,
|
||||||
|
large_preview=None,
|
||||||
|
animated_preview=None,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
super(ImageAttachment, self).__init__(**kwargs)
|
||||||
|
self.original_extension = original_extension
|
||||||
|
if width is not None:
|
||||||
|
width = int(width)
|
||||||
|
self.width = width
|
||||||
|
if height is not None:
|
||||||
|
height = int(height)
|
||||||
|
self.height = height
|
||||||
|
self.is_animated = is_animated
|
||||||
|
self.thumbnail_url = thumbnail_url
|
||||||
|
|
||||||
|
if preview is None:
|
||||||
|
preview = {}
|
||||||
|
self.preview_url = preview.get("uri")
|
||||||
|
self.preview_width = preview.get("width")
|
||||||
|
self.preview_height = preview.get("height")
|
||||||
|
|
||||||
|
if large_preview is None:
|
||||||
|
large_preview = {}
|
||||||
|
self.large_preview_url = large_preview.get("uri")
|
||||||
|
self.large_preview_width = large_preview.get("width")
|
||||||
|
self.large_preview_height = large_preview.get("height")
|
||||||
|
|
||||||
|
if animated_preview is None:
|
||||||
|
animated_preview = {}
|
||||||
|
self.animated_preview_url = animated_preview.get("uri")
|
||||||
|
self.animated_preview_width = animated_preview.get("width")
|
||||||
|
self.animated_preview_height = animated_preview.get("height")
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class VideoAttachment(Attachment):
|
||||||
|
"""Represents a video that has been sent as a Facebook attachment"""
|
||||||
|
|
||||||
|
#: Size of the original video in bytes
|
||||||
|
size = attr.ib(None)
|
||||||
|
#: Width of original video
|
||||||
|
width = attr.ib(None)
|
||||||
|
#: Height of original video
|
||||||
|
height = attr.ib(None)
|
||||||
|
#: Length of video in milliseconds
|
||||||
|
duration = attr.ib(None)
|
||||||
|
#: URL to very compressed preview video
|
||||||
|
preview_url = attr.ib(None)
|
||||||
|
|
||||||
|
#: URL to a small preview image of the video
|
||||||
|
small_image_url = attr.ib(None)
|
||||||
|
#: Width of the small preview image
|
||||||
|
small_image_width = attr.ib(None)
|
||||||
|
#: Height of the small preview image
|
||||||
|
small_image_height = attr.ib(None)
|
||||||
|
|
||||||
|
#: URL to a medium preview image of the video
|
||||||
|
medium_image_url = attr.ib(None)
|
||||||
|
#: Width of the medium preview image
|
||||||
|
medium_image_width = attr.ib(None)
|
||||||
|
#: Height of the medium preview image
|
||||||
|
medium_image_height = attr.ib(None)
|
||||||
|
|
||||||
|
#: URL to a large preview image of the video
|
||||||
|
large_image_url = attr.ib(None)
|
||||||
|
#: Width of the large preview image
|
||||||
|
large_image_width = attr.ib(None)
|
||||||
|
#: Height of the large preview image
|
||||||
|
large_image_height = attr.ib(None)
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
size=None,
|
||||||
|
width=None,
|
||||||
|
height=None,
|
||||||
|
duration=None,
|
||||||
|
preview_url=None,
|
||||||
|
small_image=None,
|
||||||
|
medium_image=None,
|
||||||
|
large_image=None,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
super(VideoAttachment, self).__init__(**kwargs)
|
||||||
|
self.size = size
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.duration = duration
|
||||||
|
self.preview_url = preview_url
|
||||||
|
|
||||||
|
if small_image is None:
|
||||||
|
small_image = {}
|
||||||
|
self.small_image_url = small_image.get("uri")
|
||||||
|
self.small_image_width = small_image.get("width")
|
||||||
|
self.small_image_height = small_image.get("height")
|
||||||
|
|
||||||
|
if medium_image is None:
|
||||||
|
medium_image = {}
|
||||||
|
self.medium_image_url = medium_image.get("uri")
|
||||||
|
self.medium_image_width = medium_image.get("width")
|
||||||
|
self.medium_image_height = medium_image.get("height")
|
||||||
|
|
||||||
|
if large_image is None:
|
||||||
|
large_image = {}
|
||||||
|
self.large_image_url = large_image.get("uri")
|
||||||
|
self.large_image_width = large_image.get("width")
|
||||||
|
self.large_image_height = large_image.get("height")
|
74
fbchat/_group.py
Normal file
74
fbchat/_group.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
from ._thread import ThreadType, Thread
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class Group(Thread):
|
||||||
|
"""Represents a Facebook group. Inherits `Thread`"""
|
||||||
|
|
||||||
|
#: Unique list (set) of the group thread's participant user IDs
|
||||||
|
participants = attr.ib(factory=set, converter=lambda x: set() if x is None else x)
|
||||||
|
#: A dict, containing user nicknames mapped to their IDs
|
||||||
|
nicknames = attr.ib(factory=dict, converter=lambda x: {} if x is None else x)
|
||||||
|
#: A :class:`ThreadColor`. The groups's message color
|
||||||
|
color = attr.ib(None)
|
||||||
|
#: The groups's default emoji
|
||||||
|
emoji = attr.ib(None)
|
||||||
|
# Set containing user IDs of thread admins
|
||||||
|
admins = attr.ib(factory=set, converter=lambda x: set() if x is None else x)
|
||||||
|
# True if users need approval to join
|
||||||
|
approval_mode = attr.ib(None)
|
||||||
|
# Set containing user IDs requesting to join
|
||||||
|
approval_requests = attr.ib(
|
||||||
|
factory=set, converter=lambda x: set() if x is None else x
|
||||||
|
)
|
||||||
|
# Link for joining group
|
||||||
|
join_link = attr.ib(None)
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
uid,
|
||||||
|
participants=None,
|
||||||
|
nicknames=None,
|
||||||
|
color=None,
|
||||||
|
emoji=None,
|
||||||
|
admins=None,
|
||||||
|
approval_mode=None,
|
||||||
|
approval_requests=None,
|
||||||
|
join_link=None,
|
||||||
|
privacy_mode=None,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
super(Group, self).__init__(ThreadType.GROUP, uid, **kwargs)
|
||||||
|
if participants is None:
|
||||||
|
participants = set()
|
||||||
|
self.participants = participants
|
||||||
|
if nicknames is None:
|
||||||
|
nicknames = []
|
||||||
|
self.nicknames = nicknames
|
||||||
|
self.color = color
|
||||||
|
self.emoji = emoji
|
||||||
|
if admins is None:
|
||||||
|
admins = set()
|
||||||
|
self.admins = admins
|
||||||
|
self.approval_mode = approval_mode
|
||||||
|
if approval_requests is None:
|
||||||
|
approval_requests = set()
|
||||||
|
self.approval_requests = approval_requests
|
||||||
|
self.join_link = join_link
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class Room(Group):
|
||||||
|
"""Deprecated. Use :class:`Group` instead"""
|
||||||
|
|
||||||
|
# True is room is not discoverable
|
||||||
|
privacy_mode = attr.ib(None)
|
||||||
|
|
||||||
|
def __init__(self, uid, privacy_mode=None, **kwargs):
|
||||||
|
super(Room, self).__init__(uid, **kwargs)
|
||||||
|
self.type = ThreadType.ROOM
|
||||||
|
self.privacy_mode = privacy_mode
|
48
fbchat/_location.py
Normal file
48
fbchat/_location.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
from ._attachment import Attachment
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class LocationAttachment(Attachment):
|
||||||
|
"""Represents a user location
|
||||||
|
|
||||||
|
Latitude and longitude OR address is provided by Facebook
|
||||||
|
"""
|
||||||
|
|
||||||
|
#: Latitude of the location
|
||||||
|
latitude = attr.ib(None)
|
||||||
|
#: Longitude of the location
|
||||||
|
longitude = attr.ib(None)
|
||||||
|
#: URL of image showing the map of the location
|
||||||
|
image_url = attr.ib(None, init=False)
|
||||||
|
#: Width of the image
|
||||||
|
image_width = attr.ib(None, init=False)
|
||||||
|
#: Height of the image
|
||||||
|
image_height = attr.ib(None, init=False)
|
||||||
|
#: URL to Bing maps with the location
|
||||||
|
url = attr.ib(None, init=False)
|
||||||
|
# Address of the location
|
||||||
|
address = attr.ib(None)
|
||||||
|
|
||||||
|
# Put here for backwards compatibility, so that the init argument order is preserved
|
||||||
|
uid = attr.ib(None)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class LiveLocationAttachment(LocationAttachment):
|
||||||
|
"""Represents a live user location"""
|
||||||
|
|
||||||
|
#: Name of the location
|
||||||
|
name = attr.ib(None)
|
||||||
|
#: Timestamp when live location expires
|
||||||
|
expiration_time = attr.ib(None)
|
||||||
|
#: True if live location is expired
|
||||||
|
is_expired = attr.ib(None)
|
||||||
|
|
||||||
|
def __init__(self, name=None, expiration_time=None, is_expired=None, **kwargs):
|
||||||
|
super(LiveLocationAttachment, self).__init__(**kwargs)
|
||||||
|
self.expiration_time = expiration_time
|
||||||
|
self.is_expired = is_expired
|
123
fbchat/_message.py
Normal file
123
fbchat/_message.py
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
from string import Formatter
|
||||||
|
from ._core import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class EmojiSize(Enum):
|
||||||
|
"""Used to specify the size of a sent emoji"""
|
||||||
|
|
||||||
|
LARGE = "369239383222810"
|
||||||
|
MEDIUM = "369239343222814"
|
||||||
|
SMALL = "369239263222822"
|
||||||
|
|
||||||
|
|
||||||
|
class MessageReaction(Enum):
|
||||||
|
"""Used to specify a message reaction"""
|
||||||
|
|
||||||
|
LOVE = "😍"
|
||||||
|
SMILE = "😆"
|
||||||
|
WOW = "😮"
|
||||||
|
SAD = "😢"
|
||||||
|
ANGRY = "😠"
|
||||||
|
YES = "👍"
|
||||||
|
NO = "👎"
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class Mention(object):
|
||||||
|
"""Represents a @mention"""
|
||||||
|
|
||||||
|
#: The thread ID the mention is pointing at
|
||||||
|
thread_id = attr.ib()
|
||||||
|
#: The character where the mention starts
|
||||||
|
offset = attr.ib(0)
|
||||||
|
#: The length of the mention
|
||||||
|
length = attr.ib(10)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class Message(object):
|
||||||
|
"""Represents a Facebook message"""
|
||||||
|
|
||||||
|
#: The actual message
|
||||||
|
text = attr.ib(None)
|
||||||
|
#: A list of :class:`Mention` objects
|
||||||
|
mentions = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
|
||||||
|
#: A :class:`EmojiSize`. Size of a sent emoji
|
||||||
|
emoji_size = attr.ib(None)
|
||||||
|
#: The message ID
|
||||||
|
uid = attr.ib(None, init=False)
|
||||||
|
#: ID of the sender
|
||||||
|
author = attr.ib(None, init=False)
|
||||||
|
#: Timestamp of when the message was sent
|
||||||
|
timestamp = attr.ib(None, init=False)
|
||||||
|
#: Whether the message is read
|
||||||
|
is_read = attr.ib(None, init=False)
|
||||||
|
#: A list of pepole IDs who read the message, works only with :func:`fbchat.Client.fetchThreadMessages`
|
||||||
|
read_by = attr.ib(factory=list, init=False)
|
||||||
|
#: A dict with user's IDs as keys, and their :class:`MessageReaction` as values
|
||||||
|
reactions = attr.ib(factory=dict, init=False)
|
||||||
|
#: A :class:`Sticker`
|
||||||
|
sticker = attr.ib(None)
|
||||||
|
#: A list of attachments
|
||||||
|
attachments = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
|
||||||
|
#: A list of :class:`QuickReply`
|
||||||
|
quick_replies = attr.ib(factory=list, converter=lambda x: [] if x is None else x)
|
||||||
|
#: Whether the message is unsent (deleted for everyone)
|
||||||
|
unsent = attr.ib(False, init=False)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def formatMentions(cls, text, *args, **kwargs):
|
||||||
|
"""Like `str.format`, but takes tuples with a thread id and text instead.
|
||||||
|
|
||||||
|
Returns a `Message` object, with the formatted string and relevant mentions.
|
||||||
|
|
||||||
|
```
|
||||||
|
>>> Message.formatMentions("Hey {!r}! My name is {}", ("1234", "Peter"), ("4321", "Michael"))
|
||||||
|
<Message (None): "Hey 'Peter'! My name is Michael", mentions=[<Mention 1234: offset=4 length=7>, <Mention 4321: offset=24 length=7>] emoji_size=None attachments=[]>
|
||||||
|
|
||||||
|
>>> Message.formatMentions("Hey {p}! My name is {}", ("1234", "Michael"), p=("4321", "Peter"))
|
||||||
|
<Message (None): 'Hey Peter! My name is Michael', mentions=[<Mention 4321: offset=4 length=5>, <Mention 1234: offset=22 length=7>] emoji_size=None attachments=[]>
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
result = ""
|
||||||
|
mentions = list()
|
||||||
|
offset = 0
|
||||||
|
f = Formatter()
|
||||||
|
field_names = [field_name[1] for field_name in f.parse(text)]
|
||||||
|
automatic = "" in field_names
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
for (literal_text, field_name, format_spec, conversion) in f.parse(text):
|
||||||
|
offset += len(literal_text)
|
||||||
|
result += literal_text
|
||||||
|
|
||||||
|
if field_name is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if field_name == "":
|
||||||
|
field_name = str(i)
|
||||||
|
i += 1
|
||||||
|
elif automatic and field_name.isdigit():
|
||||||
|
raise ValueError(
|
||||||
|
"cannot switch from automatic field numbering to manual field specification"
|
||||||
|
)
|
||||||
|
|
||||||
|
thread_id, name = f.get_field(field_name, args, kwargs)[0]
|
||||||
|
|
||||||
|
if format_spec:
|
||||||
|
name = f.format_field(name, format_spec)
|
||||||
|
if conversion:
|
||||||
|
name = f.convert_field(name, conversion)
|
||||||
|
|
||||||
|
result += name
|
||||||
|
mentions.append(
|
||||||
|
Mention(thread_id=thread_id, offset=offset, length=len(name))
|
||||||
|
)
|
||||||
|
offset += len(name)
|
||||||
|
|
||||||
|
message = cls(text=result, mentions=mentions)
|
||||||
|
return message
|
38
fbchat/_page.py
Normal file
38
fbchat/_page.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
from ._thread import ThreadType, Thread
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class Page(Thread):
|
||||||
|
"""Represents a Facebook page. Inherits `Thread`"""
|
||||||
|
|
||||||
|
#: The page's custom url
|
||||||
|
url = attr.ib(None)
|
||||||
|
#: The name of the page's location city
|
||||||
|
city = attr.ib(None)
|
||||||
|
#: Amount of likes the page has
|
||||||
|
likes = attr.ib(None)
|
||||||
|
#: Some extra information about the page
|
||||||
|
sub_title = attr.ib(None)
|
||||||
|
#: The page's category
|
||||||
|
category = attr.ib(None)
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
uid,
|
||||||
|
url=None,
|
||||||
|
city=None,
|
||||||
|
likes=None,
|
||||||
|
sub_title=None,
|
||||||
|
category=None,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
super(Page, self).__init__(ThreadType.PAGE, uid, **kwargs)
|
||||||
|
self.url = url
|
||||||
|
self.city = city
|
||||||
|
self.likes = likes
|
||||||
|
self.sub_title = sub_title
|
||||||
|
self.category = category
|
28
fbchat/_plan.py
Normal file
28
fbchat/_plan.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class Plan(object):
|
||||||
|
"""Represents a plan"""
|
||||||
|
|
||||||
|
#: ID of the plan
|
||||||
|
uid = attr.ib(None, init=False)
|
||||||
|
#: Plan time (unix time stamp), only precise down to the minute
|
||||||
|
time = attr.ib(converter=int)
|
||||||
|
#: Plan title
|
||||||
|
title = attr.ib()
|
||||||
|
#: Plan location name
|
||||||
|
location = attr.ib(None, converter=lambda x: x or "")
|
||||||
|
#: Plan location ID
|
||||||
|
location_id = attr.ib(None, converter=lambda x: x or "")
|
||||||
|
#: ID of the plan creator
|
||||||
|
author_id = attr.ib(None, init=False)
|
||||||
|
#: List of the people IDs who will take part in the plan
|
||||||
|
going = attr.ib(factory=list, init=False)
|
||||||
|
#: List of the people IDs who won't take part in the plan
|
||||||
|
declined = attr.ib(factory=list, init=False)
|
||||||
|
#: List of the people IDs who are invited to the plan
|
||||||
|
invited = attr.ib(factory=list, init=False)
|
34
fbchat/_poll.py
Normal file
34
fbchat/_poll.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class Poll(object):
|
||||||
|
"""Represents a poll"""
|
||||||
|
|
||||||
|
#: ID of the poll
|
||||||
|
uid = attr.ib(None, init=False)
|
||||||
|
#: Title of the poll
|
||||||
|
title = attr.ib()
|
||||||
|
#: List of :class:`PollOption`, can be fetched with :func:`fbchat.Client.fetchPollOptions`
|
||||||
|
options = attr.ib()
|
||||||
|
#: Options count
|
||||||
|
options_count = attr.ib(None, init=False)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class PollOption(object):
|
||||||
|
"""Represents a poll option"""
|
||||||
|
|
||||||
|
#: ID of the poll option
|
||||||
|
uid = attr.ib(None, init=False)
|
||||||
|
#: Text of the poll option
|
||||||
|
text = attr.ib()
|
||||||
|
#: Whether vote when creating or client voted
|
||||||
|
vote = attr.ib(False)
|
||||||
|
#: ID of the users who voted for this poll option
|
||||||
|
voters = attr.ib(None, init=False)
|
||||||
|
#: Votes count
|
||||||
|
votes_count = attr.ib(None, init=False)
|
76
fbchat/_quick_reply.py
Normal file
76
fbchat/_quick_reply.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
from ._attachment import Attachment
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class QuickReply(object):
|
||||||
|
"""Represents a quick reply"""
|
||||||
|
|
||||||
|
#: Payload of the quick reply
|
||||||
|
payload = attr.ib(None)
|
||||||
|
#: External payload for responses
|
||||||
|
external_payload = attr.ib(None, init=False)
|
||||||
|
#: Additional data
|
||||||
|
data = attr.ib(None)
|
||||||
|
#: Whether it's a response for a quick reply
|
||||||
|
is_response = attr.ib(False)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class QuickReplyText(QuickReply):
|
||||||
|
"""Represents a text quick reply"""
|
||||||
|
|
||||||
|
#: Title of the quick reply
|
||||||
|
title = attr.ib(None)
|
||||||
|
#: URL of the quick reply image (optional)
|
||||||
|
image_url = attr.ib(None)
|
||||||
|
#: Type of the quick reply
|
||||||
|
_type = "text"
|
||||||
|
|
||||||
|
def __init__(self, title=None, image_url=None, **kwargs):
|
||||||
|
super(QuickReplyText, self).__init__(**kwargs)
|
||||||
|
self.title = title
|
||||||
|
self.image_url = image_url
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class QuickReplyLocation(QuickReply):
|
||||||
|
"""Represents a location quick reply (Doesn't work on mobile)"""
|
||||||
|
|
||||||
|
#: Type of the quick reply
|
||||||
|
_type = "location"
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(QuickReplyLocation, self).__init__(**kwargs)
|
||||||
|
self.is_response = False
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class QuickReplyPhoneNumber(QuickReply):
|
||||||
|
"""Represents a phone number quick reply (Doesn't work on mobile)"""
|
||||||
|
|
||||||
|
#: URL of the quick reply image (optional)
|
||||||
|
image_url = attr.ib(None)
|
||||||
|
#: Type of the quick reply
|
||||||
|
_type = "user_phone_number"
|
||||||
|
|
||||||
|
def __init__(self, image_url=None, **kwargs):
|
||||||
|
super(QuickReplyPhoneNumber, self).__init__(**kwargs)
|
||||||
|
self.image_url = image_url
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class QuickReplyEmail(QuickReply):
|
||||||
|
"""Represents an email quick reply (Doesn't work on mobile)"""
|
||||||
|
|
||||||
|
#: URL of the quick reply image (optional)
|
||||||
|
image_url = attr.ib(None)
|
||||||
|
#: Type of the quick reply
|
||||||
|
_type = "user_email"
|
||||||
|
|
||||||
|
def __init__(self, image_url=None, **kwargs):
|
||||||
|
super(QuickReplyEmail, self).__init__(**kwargs)
|
||||||
|
self.image_url = image_url
|
39
fbchat/_sticker.py
Normal file
39
fbchat/_sticker.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
from ._attachment import Attachment
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class Sticker(Attachment):
|
||||||
|
"""Represents a Facebook sticker that has been sent to a thread as an attachment"""
|
||||||
|
|
||||||
|
#: The sticker-pack's ID
|
||||||
|
pack = attr.ib(None)
|
||||||
|
#: Whether the sticker is animated
|
||||||
|
is_animated = attr.ib(False)
|
||||||
|
|
||||||
|
# If the sticker is animated, the following should be present
|
||||||
|
#: URL to a medium spritemap
|
||||||
|
medium_sprite_image = attr.ib(None)
|
||||||
|
#: URL to a large spritemap
|
||||||
|
large_sprite_image = attr.ib(None)
|
||||||
|
#: The amount of frames present in the spritemap pr. row
|
||||||
|
frames_per_row = attr.ib(None)
|
||||||
|
#: The amount of frames present in the spritemap pr. coloumn
|
||||||
|
frames_per_col = attr.ib(None)
|
||||||
|
#: The frame rate the spritemap is intended to be played in
|
||||||
|
frame_rate = attr.ib(None)
|
||||||
|
|
||||||
|
#: URL to the sticker's image
|
||||||
|
url = attr.ib(None)
|
||||||
|
#: Width of the sticker
|
||||||
|
width = attr.ib(None)
|
||||||
|
#: Height of the sticker
|
||||||
|
height = attr.ib(None)
|
||||||
|
#: The sticker's label/name
|
||||||
|
label = attr.ib(None)
|
||||||
|
|
||||||
|
def __init__(self, uid=None):
|
||||||
|
super(Sticker, self).__init__(uid=uid)
|
81
fbchat/_thread.py
Normal file
81
fbchat/_thread.py
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
from ._core import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class ThreadType(Enum):
|
||||||
|
"""Used to specify what type of Facebook thread is being used. See :ref:`intro_threads` for more info"""
|
||||||
|
|
||||||
|
USER = 1
|
||||||
|
GROUP = 2
|
||||||
|
ROOM = 2
|
||||||
|
PAGE = 3
|
||||||
|
|
||||||
|
|
||||||
|
class ThreadLocation(Enum):
|
||||||
|
"""Used to specify where a thread is located (inbox, pending, archived, other)."""
|
||||||
|
|
||||||
|
INBOX = "INBOX"
|
||||||
|
PENDING = "PENDING"
|
||||||
|
ARCHIVED = "ARCHIVED"
|
||||||
|
OTHER = "OTHER"
|
||||||
|
|
||||||
|
|
||||||
|
class ThreadColor(Enum):
|
||||||
|
"""Used to specify a thread colors"""
|
||||||
|
|
||||||
|
MESSENGER_BLUE = "#0084ff"
|
||||||
|
VIKING = "#44bec7"
|
||||||
|
GOLDEN_POPPY = "#ffc300"
|
||||||
|
RADICAL_RED = "#fa3c4c"
|
||||||
|
SHOCKING = "#d696bb"
|
||||||
|
PICTON_BLUE = "#6699cc"
|
||||||
|
FREE_SPEECH_GREEN = "#13cf13"
|
||||||
|
PUMPKIN = "#ff7e29"
|
||||||
|
LIGHT_CORAL = "#e68585"
|
||||||
|
MEDIUM_SLATE_BLUE = "#7646ff"
|
||||||
|
DEEP_SKY_BLUE = "#20cef5"
|
||||||
|
FERN = "#67b868"
|
||||||
|
CAMEO = "#d4a88c"
|
||||||
|
BRILLIANT_ROSE = "#ff5ca1"
|
||||||
|
BILOBA_FLOWER = "#a695c7"
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class Thread(object):
|
||||||
|
"""Represents a Facebook thread"""
|
||||||
|
|
||||||
|
#: The unique identifier of the thread. Can be used a `thread_id`. See :ref:`intro_threads` for more info
|
||||||
|
uid = attr.ib(converter=str)
|
||||||
|
#: Specifies the type of thread. Can be used a `thread_type`. See :ref:`intro_threads` for more info
|
||||||
|
type = attr.ib()
|
||||||
|
#: A url to the thread's picture
|
||||||
|
photo = attr.ib(None)
|
||||||
|
#: The name of the thread
|
||||||
|
name = attr.ib(None)
|
||||||
|
#: Timestamp of last message
|
||||||
|
last_message_timestamp = attr.ib(None)
|
||||||
|
#: Number of messages in the thread
|
||||||
|
message_count = attr.ib(None)
|
||||||
|
#: Set :class:`Plan`
|
||||||
|
plan = attr.ib(None)
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
_type,
|
||||||
|
uid,
|
||||||
|
photo=None,
|
||||||
|
name=None,
|
||||||
|
last_message_timestamp=None,
|
||||||
|
message_count=None,
|
||||||
|
plan=None,
|
||||||
|
):
|
||||||
|
self.uid = str(uid)
|
||||||
|
self.type = _type
|
||||||
|
self.photo = photo
|
||||||
|
self.name = name
|
||||||
|
self.last_message_timestamp = last_message_timestamp
|
||||||
|
self.message_count = message_count
|
||||||
|
self.plan = plan
|
76
fbchat/_user.py
Normal file
76
fbchat/_user.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import attr
|
||||||
|
from ._core import Enum
|
||||||
|
from ._thread import ThreadType, Thread
|
||||||
|
|
||||||
|
|
||||||
|
class TypingStatus(Enum):
|
||||||
|
"""Used to specify whether the user is typing or has stopped typing"""
|
||||||
|
|
||||||
|
STOPPED = 0
|
||||||
|
TYPING = 1
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False, init=False)
|
||||||
|
class User(Thread):
|
||||||
|
"""Represents a Facebook user. Inherits `Thread`"""
|
||||||
|
|
||||||
|
#: The profile url
|
||||||
|
url = attr.ib(None)
|
||||||
|
#: The users first name
|
||||||
|
first_name = attr.ib(None)
|
||||||
|
#: The users last name
|
||||||
|
last_name = attr.ib(None)
|
||||||
|
#: Whether the user and the client are friends
|
||||||
|
is_friend = attr.ib(None)
|
||||||
|
#: The user's gender
|
||||||
|
gender = attr.ib(None)
|
||||||
|
#: From 0 to 1. How close the client is to the user
|
||||||
|
affinity = attr.ib(None)
|
||||||
|
#: The user's nickname
|
||||||
|
nickname = attr.ib(None)
|
||||||
|
#: The clients nickname, as seen by the user
|
||||||
|
own_nickname = attr.ib(None)
|
||||||
|
#: A :class:`ThreadColor`. The message color
|
||||||
|
color = attr.ib(None)
|
||||||
|
#: The default emoji
|
||||||
|
emoji = attr.ib(None)
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
uid,
|
||||||
|
url=None,
|
||||||
|
first_name=None,
|
||||||
|
last_name=None,
|
||||||
|
is_friend=None,
|
||||||
|
gender=None,
|
||||||
|
affinity=None,
|
||||||
|
nickname=None,
|
||||||
|
own_nickname=None,
|
||||||
|
color=None,
|
||||||
|
emoji=None,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
super(User, self).__init__(ThreadType.USER, uid, **kwargs)
|
||||||
|
self.url = url
|
||||||
|
self.first_name = first_name
|
||||||
|
self.last_name = last_name
|
||||||
|
self.is_friend = is_friend
|
||||||
|
self.gender = gender
|
||||||
|
self.affinity = affinity
|
||||||
|
self.nickname = nickname
|
||||||
|
self.own_nickname = own_nickname
|
||||||
|
self.color = color
|
||||||
|
self.emoji = emoji
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s(cmp=False)
|
||||||
|
class ActiveStatus(object):
|
||||||
|
#: Whether the user is active now
|
||||||
|
active = attr.ib(None)
|
||||||
|
#: Timestamp when the user was last active
|
||||||
|
last_active = attr.ib(None)
|
||||||
|
#: Whether the user is playing Messenger game now
|
||||||
|
in_game = attr.ib(None)
|
105
fbchat/client.py
105
fbchat/client.py
@@ -1180,7 +1180,9 @@ class Client(object):
|
|||||||
self.req_url.UNREAD_THREADS, form, fix_request=True, as_json=True
|
self.req_url.UNREAD_THREADS, form, fix_request=True, as_json=True
|
||||||
)
|
)
|
||||||
|
|
||||||
return j["payload"]["unread_thread_fbids"][0]["other_user_fbids"]
|
payload = j["payload"]["unread_thread_fbids"][0]
|
||||||
|
|
||||||
|
return payload["thread_fbids"] + payload["other_user_fbids"]
|
||||||
|
|
||||||
def fetchUnseen(self):
|
def fetchUnseen(self):
|
||||||
"""
|
"""
|
||||||
@@ -1194,7 +1196,9 @@ class Client(object):
|
|||||||
self.req_url.UNSEEN_THREADS, None, fix_request=True, as_json=True
|
self.req_url.UNSEEN_THREADS, None, fix_request=True, as_json=True
|
||||||
)
|
)
|
||||||
|
|
||||||
return j["payload"]["unseen_thread_fbids"][0]["other_user_fbids"]
|
payload = j["payload"]["unseen_thread_fbids"][0]
|
||||||
|
|
||||||
|
return payload["thread_fbids"] + payload["other_user_fbids"]
|
||||||
|
|
||||||
def fetchImageUrl(self, image_id):
|
def fetchImageUrl(self, image_id):
|
||||||
"""Fetches the url to the original image from an image attachment ID
|
"""Fetches the url to the original image from an image attachment ID
|
||||||
@@ -2522,26 +2526,7 @@ class Client(object):
|
|||||||
self.seq = j.get("seq", "0")
|
self.seq = j.get("seq", "0")
|
||||||
return j
|
return j
|
||||||
|
|
||||||
def _parseMessage(self, content):
|
def _parseDelta(self, m):
|
||||||
"""Get message and author name from content. May contain multiple messages in the content."""
|
|
||||||
|
|
||||||
if "lb_info" in content:
|
|
||||||
self.sticky = content["lb_info"]["sticky"]
|
|
||||||
self.pool = content["lb_info"]["pool"]
|
|
||||||
|
|
||||||
if "batches" in content:
|
|
||||||
for batch in content["batches"]:
|
|
||||||
self._parseMessage(batch)
|
|
||||||
|
|
||||||
if "ms" not in content:
|
|
||||||
return
|
|
||||||
|
|
||||||
for m in content["ms"]:
|
|
||||||
mtype = m.get("type")
|
|
||||||
try:
|
|
||||||
# Things that directly change chat
|
|
||||||
if mtype == "delta":
|
|
||||||
|
|
||||||
def getThreadIdAndThreadType(msg_metadata):
|
def getThreadIdAndThreadType(msg_metadata):
|
||||||
"""Returns a tuple consisting of thread ID and thread type"""
|
"""Returns a tuple consisting of thread ID and thread type"""
|
||||||
id_thread = None
|
id_thread = None
|
||||||
@@ -2566,9 +2551,7 @@ class Client(object):
|
|||||||
|
|
||||||
# Added participants
|
# Added participants
|
||||||
if "addedParticipants" in delta:
|
if "addedParticipants" in delta:
|
||||||
added_ids = [
|
added_ids = [str(x["userFbId"]) for x in delta["addedParticipants"]]
|
||||||
str(x["userFbId"]) for x in delta["addedParticipants"]
|
|
||||||
]
|
|
||||||
thread_id = str(metadata["threadKey"]["threadFbId"])
|
thread_id = str(metadata["threadKey"]["threadFbId"])
|
||||||
self.onPeopleAdded(
|
self.onPeopleAdded(
|
||||||
mid=mid,
|
mid=mid,
|
||||||
@@ -2594,9 +2577,7 @@ class Client(object):
|
|||||||
|
|
||||||
# Color change
|
# Color change
|
||||||
elif delta_type == "change_thread_theme":
|
elif delta_type == "change_thread_theme":
|
||||||
new_color = graphql_color_to_enum(
|
new_color = graphql_color_to_enum(delta["untypedData"]["theme_color"])
|
||||||
delta["untypedData"]["theme_color"]
|
|
||||||
)
|
|
||||||
thread_id, thread_type = getThreadIdAndThreadType(metadata)
|
thread_id, thread_type = getThreadIdAndThreadType(metadata)
|
||||||
self.onColorChange(
|
self.onColorChange(
|
||||||
mid=mid,
|
mid=mid,
|
||||||
@@ -2729,8 +2710,7 @@ class Client(object):
|
|||||||
elif delta_class == "DeliveryReceipt":
|
elif delta_class == "DeliveryReceipt":
|
||||||
message_ids = delta["messageIds"]
|
message_ids = delta["messageIds"]
|
||||||
delivered_for = str(
|
delivered_for = str(
|
||||||
delta.get("actorFbId")
|
delta.get("actorFbId") or delta["threadKey"]["otherUserFbId"]
|
||||||
or delta["threadKey"]["otherUserFbId"]
|
|
||||||
)
|
)
|
||||||
ts = int(delta["deliveredWatermarkTimestampMs"])
|
ts = int(delta["deliveredWatermarkTimestampMs"])
|
||||||
thread_id, thread_type = getThreadIdAndThreadType(delta)
|
thread_id, thread_type = getThreadIdAndThreadType(delta)
|
||||||
@@ -2746,10 +2726,7 @@ class Client(object):
|
|||||||
|
|
||||||
# Message seen
|
# Message seen
|
||||||
elif delta_class == "ReadReceipt":
|
elif delta_class == "ReadReceipt":
|
||||||
seen_by = str(
|
seen_by = str(delta.get("actorFbId") or delta["threadKey"]["otherUserFbId"])
|
||||||
delta.get("actorFbId")
|
|
||||||
or delta["threadKey"]["otherUserFbId"]
|
|
||||||
)
|
|
||||||
seen_ts = int(delta["actionTimestampMs"])
|
seen_ts = int(delta["actionTimestampMs"])
|
||||||
delivered_ts = int(delta["watermarkTimestampMs"])
|
delivered_ts = int(delta["watermarkTimestampMs"])
|
||||||
thread_id, thread_type = getThreadIdAndThreadType(delta)
|
thread_id, thread_type = getThreadIdAndThreadType(delta)
|
||||||
@@ -2766,12 +2743,10 @@ class Client(object):
|
|||||||
# Messages marked as seen
|
# Messages marked as seen
|
||||||
elif delta_class == "MarkRead":
|
elif delta_class == "MarkRead":
|
||||||
seen_ts = int(
|
seen_ts = int(
|
||||||
delta.get("actionTimestampMs")
|
delta.get("actionTimestampMs") or delta.get("actionTimestamp")
|
||||||
or delta.get("actionTimestamp")
|
|
||||||
)
|
)
|
||||||
delivered_ts = int(
|
delivered_ts = int(
|
||||||
delta.get("watermarkTimestampMs")
|
delta.get("watermarkTimestampMs") or delta.get("watermarkTimestamp")
|
||||||
or delta.get("watermarkTimestamp")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
threads = []
|
threads = []
|
||||||
@@ -2783,11 +2758,7 @@ class Client(object):
|
|||||||
|
|
||||||
# thread_id, thread_type = getThreadIdAndThreadType(delta)
|
# thread_id, thread_type = getThreadIdAndThreadType(delta)
|
||||||
self.onMarkedSeen(
|
self.onMarkedSeen(
|
||||||
threads=threads,
|
threads=threads, seen_ts=seen_ts, ts=delivered_ts, metadata=delta, msg=m
|
||||||
seen_ts=seen_ts,
|
|
||||||
ts=delivered_ts,
|
|
||||||
metadata=delta,
|
|
||||||
msg=m,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Game played
|
# Game played
|
||||||
@@ -2848,9 +2819,7 @@ class Client(object):
|
|||||||
# User joined to group call
|
# User joined to group call
|
||||||
elif delta_type == "participant_joined_group_call":
|
elif delta_type == "participant_joined_group_call":
|
||||||
thread_id, thread_type = getThreadIdAndThreadType(metadata)
|
thread_id, thread_type = getThreadIdAndThreadType(metadata)
|
||||||
is_video_call = bool(
|
is_video_call = bool(int(delta["untypedData"]["group_call_type"]))
|
||||||
int(delta["untypedData"]["group_call_type"])
|
|
||||||
)
|
|
||||||
self.onUserJoinedCall(
|
self.onUserJoinedCall(
|
||||||
mid=mid,
|
mid=mid,
|
||||||
joined_id=author_id,
|
joined_id=author_id,
|
||||||
@@ -2882,12 +2851,8 @@ class Client(object):
|
|||||||
)
|
)
|
||||||
elif event_type == "update_vote":
|
elif event_type == "update_vote":
|
||||||
# User voted on group poll
|
# User voted on group poll
|
||||||
added_options = json.loads(
|
added_options = json.loads(delta["untypedData"]["added_option_ids"])
|
||||||
delta["untypedData"]["added_option_ids"]
|
removed_options = json.loads(delta["untypedData"]["removed_option_ids"])
|
||||||
)
|
|
||||||
removed_options = json.loads(
|
|
||||||
delta["untypedData"]["removed_option_ids"]
|
|
||||||
)
|
|
||||||
self.onPollVoted(
|
self.onPollVoted(
|
||||||
mid=mid,
|
mid=mid,
|
||||||
poll=poll,
|
poll=poll,
|
||||||
@@ -2990,9 +2955,7 @@ class Client(object):
|
|||||||
mid = i["messageId"]
|
mid = i["messageId"]
|
||||||
author_id = str(i["userId"])
|
author_id = str(i["userId"])
|
||||||
reaction = (
|
reaction = (
|
||||||
MessageReaction(i["reaction"])
|
MessageReaction(i["reaction"]) if i.get("reaction") else None
|
||||||
if i.get("reaction")
|
|
||||||
else None
|
|
||||||
)
|
)
|
||||||
add_reaction = not bool(i["action"])
|
add_reaction = not bool(i["action"])
|
||||||
if add_reaction:
|
if add_reaction:
|
||||||
@@ -3088,9 +3051,7 @@ class Client(object):
|
|||||||
for mention in parse_json(delta["data"]["prng"])
|
for mention in parse_json(delta["data"]["prng"])
|
||||||
]
|
]
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception(
|
log.exception("An exception occured while reading attachments")
|
||||||
"An exception occured while reading attachments"
|
|
||||||
)
|
|
||||||
|
|
||||||
sticker = None
|
sticker = None
|
||||||
attachments = []
|
attachments = []
|
||||||
@@ -3101,9 +3062,7 @@ class Client(object):
|
|||||||
mercury = a["mercury"]
|
mercury = a["mercury"]
|
||||||
if mercury.get("blob_attachment"):
|
if mercury.get("blob_attachment"):
|
||||||
image_metadata = a.get("imageMetadata", {})
|
image_metadata = a.get("imageMetadata", {})
|
||||||
attach_type = mercury["blob_attachment"][
|
attach_type = mercury["blob_attachment"]["__typename"]
|
||||||
"__typename"
|
|
||||||
]
|
|
||||||
attachment = graphql_to_attachment(
|
attachment = graphql_to_attachment(
|
||||||
mercury["blob_attachment"]
|
mercury["blob_attachment"]
|
||||||
)
|
)
|
||||||
@@ -3118,9 +3077,7 @@ class Client(object):
|
|||||||
attachments.append(attachment)
|
attachments.append(attachment)
|
||||||
|
|
||||||
elif mercury.get("sticker_attachment"):
|
elif mercury.get("sticker_attachment"):
|
||||||
sticker = graphql_to_sticker(
|
sticker = graphql_to_sticker(mercury["sticker_attachment"])
|
||||||
mercury["sticker_attachment"]
|
|
||||||
)
|
|
||||||
|
|
||||||
elif mercury.get("extensible_attachment"):
|
elif mercury.get("extensible_attachment"):
|
||||||
attachment = graphql_to_extensible_attachment(
|
attachment = graphql_to_extensible_attachment(
|
||||||
@@ -3170,6 +3127,26 @@ class Client(object):
|
|||||||
else:
|
else:
|
||||||
self.onUnknownMesssageType(msg=m)
|
self.onUnknownMesssageType(msg=m)
|
||||||
|
|
||||||
|
def _parseMessage(self, content):
|
||||||
|
"""Get message and author name from content. May contain multiple messages in the content."""
|
||||||
|
|
||||||
|
if "lb_info" in content:
|
||||||
|
self.sticky = content["lb_info"]["sticky"]
|
||||||
|
self.pool = content["lb_info"]["pool"]
|
||||||
|
|
||||||
|
if "batches" in content:
|
||||||
|
for batch in content["batches"]:
|
||||||
|
self._parseMessage(batch)
|
||||||
|
|
||||||
|
if "ms" not in content:
|
||||||
|
return
|
||||||
|
|
||||||
|
for m in content["ms"]:
|
||||||
|
mtype = m.get("type")
|
||||||
|
try:
|
||||||
|
# Things that directly change chat
|
||||||
|
if mtype == "delta":
|
||||||
|
self._parseDelta(m)
|
||||||
# Inbox
|
# Inbox
|
||||||
elif mtype == "inbox":
|
elif mtype == "inbox":
|
||||||
self.onInbox(
|
self.onInbox(
|
||||||
|
@@ -142,19 +142,26 @@ def graphql_to_extensible_attachment(a):
|
|||||||
if target:
|
if target:
|
||||||
_type = target["__typename"]
|
_type = target["__typename"]
|
||||||
if _type == "MessageLocation":
|
if _type == "MessageLocation":
|
||||||
latitude, longitude = get_url_parameter(
|
url = story.get("url")
|
||||||
get_url_parameter(story["url"], "u"), "where1"
|
address = get_url_parameter(get_url_parameter(url, "u"), "where1")
|
||||||
).split(", ")
|
try:
|
||||||
|
latitude, longitude = [float(x) for x in address.split(", ")]
|
||||||
|
address = None
|
||||||
|
except ValueError:
|
||||||
|
latitude, longitude = None, None
|
||||||
rtn = LocationAttachment(
|
rtn = LocationAttachment(
|
||||||
uid=int(story["deduplication_key"]),
|
uid=int(story["deduplication_key"]),
|
||||||
latitude=float(latitude),
|
latitude=latitude,
|
||||||
longitude=float(longitude),
|
longitude=longitude,
|
||||||
|
address=address,
|
||||||
)
|
)
|
||||||
if story["media"]:
|
media = story.get("media")
|
||||||
rtn.image_url = story["media"]["image"]["uri"]
|
if media and media.get("image"):
|
||||||
rtn.image_width = story["media"]["image"]["width"]
|
image = media["image"]
|
||||||
rtn.image_height = story["media"]["image"]["height"]
|
rtn.image_url = image.get("uri")
|
||||||
rtn.url = story["url"]
|
rtn.image_width = image.get("width")
|
||||||
|
rtn.image_height = image.get("height")
|
||||||
|
rtn.url = url
|
||||||
return rtn
|
return rtn
|
||||||
elif _type == "MessageLiveLocation":
|
elif _type == "MessageLiveLocation":
|
||||||
rtn = LiveLocationAttachment(
|
rtn = LiveLocationAttachment(
|
||||||
@@ -166,53 +173,50 @@ def graphql_to_extensible_attachment(a):
|
|||||||
if story["target"].get("coordinate")
|
if story["target"].get("coordinate")
|
||||||
else None,
|
else None,
|
||||||
name=story["title_with_entities"]["text"],
|
name=story["title_with_entities"]["text"],
|
||||||
expiration_time=story["target"]["expiration_time"]
|
expiration_time=story["target"].get("expiration_time"),
|
||||||
if story["target"].get("expiration_time")
|
is_expired=story["target"].get("is_expired"),
|
||||||
else None,
|
|
||||||
is_expired=story["target"]["is_expired"],
|
|
||||||
)
|
)
|
||||||
if story["media"]:
|
media = story.get("media")
|
||||||
rtn.image_url = story["media"]["image"]["uri"]
|
if media and media.get("image"):
|
||||||
rtn.image_width = story["media"]["image"]["width"]
|
image = media["image"]
|
||||||
rtn.image_height = story["media"]["image"]["height"]
|
rtn.image_url = image.get("uri")
|
||||||
rtn.url = story["url"]
|
rtn.image_width = image.get("width")
|
||||||
|
rtn.image_height = image.get("height")
|
||||||
|
rtn.url = story.get("url")
|
||||||
return rtn
|
return rtn
|
||||||
elif _type in ["ExternalUrl", "Story"]:
|
elif _type in ["ExternalUrl", "Story"]:
|
||||||
return ShareAttachment(
|
url = story.get("url")
|
||||||
|
rtn = ShareAttachment(
|
||||||
uid=a.get("legacy_attachment_id"),
|
uid=a.get("legacy_attachment_id"),
|
||||||
author=story["target"]["actors"][0]["id"]
|
author=story["target"]["actors"][0]["id"]
|
||||||
if story["target"].get("actors")
|
if story["target"].get("actors")
|
||||||
else None,
|
else None,
|
||||||
url=story["url"],
|
url=url,
|
||||||
original_url=get_url_parameter(story["url"], "u")
|
original_url=get_url_parameter(url, "u")
|
||||||
if "/l.php?u=" in story["url"]
|
if "/l.php?u=" in url
|
||||||
else story["url"],
|
else url,
|
||||||
title=story["title_with_entities"].get("text"),
|
title=story["title_with_entities"].get("text"),
|
||||||
description=story["description"].get("text")
|
description=story["description"].get("text")
|
||||||
if story.get("description")
|
if story.get("description")
|
||||||
else None,
|
else None,
|
||||||
source=story["source"]["text"],
|
source=story["source"].get("text"),
|
||||||
image_url=story["media"]["image"]["uri"]
|
|
||||||
if story.get("media")
|
|
||||||
else None,
|
|
||||||
original_image_url=(
|
|
||||||
get_url_parameter(story["media"]["image"]["uri"], "url")
|
|
||||||
if "/safe_image.php" in story["media"]["image"]["uri"]
|
|
||||||
else story["media"]["image"]["uri"]
|
|
||||||
)
|
|
||||||
if story.get("media")
|
|
||||||
else None,
|
|
||||||
image_width=story["media"]["image"]["width"]
|
|
||||||
if story.get("media")
|
|
||||||
else None,
|
|
||||||
image_height=story["media"]["image"]["height"]
|
|
||||||
if story.get("media")
|
|
||||||
else None,
|
|
||||||
attachments=[
|
attachments=[
|
||||||
graphql_to_subattachment(attachment)
|
graphql_to_subattachment(attachment)
|
||||||
for attachment in story.get("subattachments")
|
for attachment in story.get("subattachments")
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
media = story.get("media")
|
||||||
|
if media and media.get("image"):
|
||||||
|
image = media["image"]
|
||||||
|
rtn.image_url = image.get("uri")
|
||||||
|
rtn.original_image_url = (
|
||||||
|
get_url_parameter(rtn.image_url, "url")
|
||||||
|
if "/safe_image.php" in rtn.image_url
|
||||||
|
else rtn.image_url
|
||||||
|
)
|
||||||
|
rtn.image_width = image.get("width")
|
||||||
|
rtn.image_height = image.get("height")
|
||||||
|
return rtn
|
||||||
else:
|
else:
|
||||||
return UnsentMessage(uid=a.get("legacy_attachment_id"))
|
return UnsentMessage(uid=a.get("legacy_attachment_id"))
|
||||||
|
|
||||||
@@ -220,10 +224,11 @@ def graphql_to_extensible_attachment(a):
|
|||||||
def graphql_to_subattachment(a):
|
def graphql_to_subattachment(a):
|
||||||
_type = a["target"]["__typename"]
|
_type = a["target"]["__typename"]
|
||||||
if _type == "Video":
|
if _type == "Video":
|
||||||
|
media = a["media"]
|
||||||
return VideoAttachment(
|
return VideoAttachment(
|
||||||
duration=a["media"].get("playable_duration_in_ms"),
|
duration=media.get("playable_duration_in_ms"),
|
||||||
preview_url=a["media"].get("playable_url"),
|
preview_url=media.get("playable_url"),
|
||||||
medium_image=a["media"].get("image"),
|
medium_image=media.get("image"),
|
||||||
uid=a["target"].get("video_id"),
|
uid=a["target"].get("video_id"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
978
fbchat/models.py
978
fbchat/models.py
@@ -1,957 +1,29 @@
|
|||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
"""This file is here to maintain backwards compatability, and to re-export our models
|
||||||
|
into the global module (see `__init__.py`).
|
||||||
|
|
||||||
|
A common pattern was to use `from fbchat.models import *`, hence we need this while
|
||||||
|
transitioning to a better code structure.
|
||||||
|
"""
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import aenum
|
|
||||||
from string import Formatter
|
|
||||||
|
|
||||||
|
from ._core import Enum
|
||||||
class FBchatException(Exception):
|
from ._exception import FBchatException, FBchatFacebookError, FBchatUserError
|
||||||
"""Custom exception thrown by fbchat. All exceptions in the fbchat module inherits this"""
|
from ._thread import ThreadType, ThreadLocation, ThreadColor, Thread
|
||||||
|
from ._user import TypingStatus, User, ActiveStatus
|
||||||
|
from ._group import Group, Room
|
||||||
class FBchatFacebookError(FBchatException):
|
from ._page import Page
|
||||||
#: The error code that Facebook returned
|
from ._message import EmojiSize, MessageReaction, Mention, Message
|
||||||
fb_error_code = None
|
from ._attachment import Attachment, UnsentMessage, ShareAttachment
|
||||||
#: The error message that Facebook returned (In the user's own language)
|
from ._sticker import Sticker
|
||||||
fb_error_message = None
|
from ._location import LocationAttachment, LiveLocationAttachment
|
||||||
#: The status code that was sent in the http response (eg. 404) (Usually only set if not successful, aka. not 200)
|
from ._file import FileAttachment, AudioAttachment, ImageAttachment, VideoAttachment
|
||||||
request_status_code = None
|
from ._quick_reply import (
|
||||||
|
QuickReply,
|
||||||
def __init__(
|
QuickReplyText,
|
||||||
self,
|
QuickReplyLocation,
|
||||||
message,
|
QuickReplyPhoneNumber,
|
||||||
fb_error_code=None,
|
QuickReplyEmail,
|
||||||
fb_error_message=None,
|
)
|
||||||
request_status_code=None,
|
from ._poll import Poll, PollOption
|
||||||
):
|
from ._plan import Plan
|
||||||
super(FBchatFacebookError, self).__init__(message)
|
|
||||||
"""Thrown by fbchat when Facebook returns an error"""
|
|
||||||
self.fb_error_code = str(fb_error_code)
|
|
||||||
self.fb_error_message = fb_error_message
|
|
||||||
self.request_status_code = request_status_code
|
|
||||||
|
|
||||||
|
|
||||||
class FBchatUserError(FBchatException):
|
|
||||||
"""Thrown by fbchat when wrong values are entered"""
|
|
||||||
|
|
||||||
|
|
||||||
class Thread(object):
|
|
||||||
#: The unique identifier of the thread. Can be used a `thread_id`. See :ref:`intro_threads` for more info
|
|
||||||
uid = None
|
|
||||||
#: Specifies the type of thread. Can be used a `thread_type`. See :ref:`intro_threads` for more info
|
|
||||||
type = None
|
|
||||||
#: A url to the thread's picture
|
|
||||||
photo = None
|
|
||||||
#: The name of the thread
|
|
||||||
name = None
|
|
||||||
#: Timestamp of last message
|
|
||||||
last_message_timestamp = None
|
|
||||||
#: Number of messages in the thread
|
|
||||||
message_count = None
|
|
||||||
#: Set :class:`Plan`
|
|
||||||
plan = None
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
_type,
|
|
||||||
uid,
|
|
||||||
photo=None,
|
|
||||||
name=None,
|
|
||||||
last_message_timestamp=None,
|
|
||||||
message_count=None,
|
|
||||||
plan=None,
|
|
||||||
):
|
|
||||||
"""Represents a Facebook thread"""
|
|
||||||
self.uid = str(uid)
|
|
||||||
self.type = _type
|
|
||||||
self.photo = photo
|
|
||||||
self.name = name
|
|
||||||
self.last_message_timestamp = last_message_timestamp
|
|
||||||
self.message_count = message_count
|
|
||||||
self.plan = plan
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__unicode__()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "<{} {} ({})>".format(self.type.name, self.name, self.uid)
|
|
||||||
|
|
||||||
|
|
||||||
class User(Thread):
|
|
||||||
#: The profile url
|
|
||||||
url = None
|
|
||||||
#: The users first name
|
|
||||||
first_name = None
|
|
||||||
#: The users last name
|
|
||||||
last_name = None
|
|
||||||
#: Whether the user and the client are friends
|
|
||||||
is_friend = None
|
|
||||||
#: The user's gender
|
|
||||||
gender = None
|
|
||||||
#: From 0 to 1. How close the client is to the user
|
|
||||||
affinity = None
|
|
||||||
#: The user's nickname
|
|
||||||
nickname = None
|
|
||||||
#: The clients nickname, as seen by the user
|
|
||||||
own_nickname = None
|
|
||||||
#: A :class:`ThreadColor`. The message color
|
|
||||||
color = None
|
|
||||||
#: The default emoji
|
|
||||||
emoji = None
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
uid,
|
|
||||||
url=None,
|
|
||||||
first_name=None,
|
|
||||||
last_name=None,
|
|
||||||
is_friend=None,
|
|
||||||
gender=None,
|
|
||||||
affinity=None,
|
|
||||||
nickname=None,
|
|
||||||
own_nickname=None,
|
|
||||||
color=None,
|
|
||||||
emoji=None,
|
|
||||||
**kwargs
|
|
||||||
):
|
|
||||||
"""Represents a Facebook user. Inherits `Thread`"""
|
|
||||||
super(User, self).__init__(ThreadType.USER, uid, **kwargs)
|
|
||||||
self.url = url
|
|
||||||
self.first_name = first_name
|
|
||||||
self.last_name = last_name
|
|
||||||
self.is_friend = is_friend
|
|
||||||
self.gender = gender
|
|
||||||
self.affinity = affinity
|
|
||||||
self.nickname = nickname
|
|
||||||
self.own_nickname = own_nickname
|
|
||||||
self.color = color
|
|
||||||
self.emoji = emoji
|
|
||||||
|
|
||||||
|
|
||||||
class Group(Thread):
|
|
||||||
#: Unique list (set) of the group thread's participant user IDs
|
|
||||||
participants = None
|
|
||||||
#: A dict, containing user nicknames mapped to their IDs
|
|
||||||
nicknames = None
|
|
||||||
#: A :class:`ThreadColor`. The groups's message color
|
|
||||||
color = None
|
|
||||||
#: The groups's default emoji
|
|
||||||
emoji = None
|
|
||||||
# Set containing user IDs of thread admins
|
|
||||||
admins = None
|
|
||||||
# True if users need approval to join
|
|
||||||
approval_mode = None
|
|
||||||
# Set containing user IDs requesting to join
|
|
||||||
approval_requests = None
|
|
||||||
# Link for joining group
|
|
||||||
join_link = None
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
uid,
|
|
||||||
participants=None,
|
|
||||||
nicknames=None,
|
|
||||||
color=None,
|
|
||||||
emoji=None,
|
|
||||||
admins=None,
|
|
||||||
approval_mode=None,
|
|
||||||
approval_requests=None,
|
|
||||||
join_link=None,
|
|
||||||
privacy_mode=None,
|
|
||||||
**kwargs
|
|
||||||
):
|
|
||||||
"""Represents a Facebook group. Inherits `Thread`"""
|
|
||||||
super(Group, self).__init__(ThreadType.GROUP, uid, **kwargs)
|
|
||||||
if participants is None:
|
|
||||||
participants = set()
|
|
||||||
self.participants = participants
|
|
||||||
if nicknames is None:
|
|
||||||
nicknames = []
|
|
||||||
self.nicknames = nicknames
|
|
||||||
self.color = color
|
|
||||||
self.emoji = emoji
|
|
||||||
if admins is None:
|
|
||||||
admins = set()
|
|
||||||
self.admins = admins
|
|
||||||
self.approval_mode = approval_mode
|
|
||||||
if approval_requests is None:
|
|
||||||
approval_requests = set()
|
|
||||||
self.approval_requests = approval_requests
|
|
||||||
self.join_link = join_link
|
|
||||||
|
|
||||||
|
|
||||||
class Room(Group):
|
|
||||||
# True is room is not discoverable
|
|
||||||
privacy_mode = None
|
|
||||||
|
|
||||||
def __init__(self, uid, privacy_mode=None, **kwargs):
|
|
||||||
"""Deprecated. Use :class:`Group` instead"""
|
|
||||||
super(Room, self).__init__(uid, **kwargs)
|
|
||||||
self.type = ThreadType.ROOM
|
|
||||||
self.privacy_mode = privacy_mode
|
|
||||||
|
|
||||||
|
|
||||||
class Page(Thread):
|
|
||||||
#: The page's custom url
|
|
||||||
url = None
|
|
||||||
#: The name of the page's location city
|
|
||||||
city = None
|
|
||||||
#: Amount of likes the page has
|
|
||||||
likes = None
|
|
||||||
#: Some extra information about the page
|
|
||||||
sub_title = None
|
|
||||||
#: The page's category
|
|
||||||
category = None
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
uid,
|
|
||||||
url=None,
|
|
||||||
city=None,
|
|
||||||
likes=None,
|
|
||||||
sub_title=None,
|
|
||||||
category=None,
|
|
||||||
**kwargs
|
|
||||||
):
|
|
||||||
"""Represents a Facebook page. Inherits `Thread`"""
|
|
||||||
super(Page, self).__init__(ThreadType.PAGE, uid, **kwargs)
|
|
||||||
self.url = url
|
|
||||||
self.city = city
|
|
||||||
self.likes = likes
|
|
||||||
self.sub_title = sub_title
|
|
||||||
self.category = category
|
|
||||||
|
|
||||||
|
|
||||||
class Message(object):
|
|
||||||
#: The actual message
|
|
||||||
text = None
|
|
||||||
#: A list of :class:`Mention` objects
|
|
||||||
mentions = None
|
|
||||||
#: A :class:`EmojiSize`. Size of a sent emoji
|
|
||||||
emoji_size = None
|
|
||||||
#: The message ID
|
|
||||||
uid = None
|
|
||||||
#: ID of the sender
|
|
||||||
author = None
|
|
||||||
#: Timestamp of when the message was sent
|
|
||||||
timestamp = None
|
|
||||||
#: Whether the message is read
|
|
||||||
is_read = None
|
|
||||||
#: A list of pepole IDs who read the message, works only with :func:`fbchat.Client.fetchThreadMessages`
|
|
||||||
read_by = None
|
|
||||||
#: A dict with user's IDs as keys, and their :class:`MessageReaction` as values
|
|
||||||
reactions = None
|
|
||||||
#: The actual message
|
|
||||||
text = None
|
|
||||||
#: A :class:`Sticker`
|
|
||||||
sticker = None
|
|
||||||
#: A list of attachments
|
|
||||||
attachments = None
|
|
||||||
#: A list of :class:`QuickReply`
|
|
||||||
quick_replies = None
|
|
||||||
#: Whether the message is unsent (deleted for everyone)
|
|
||||||
unsent = None
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
text=None,
|
|
||||||
mentions=None,
|
|
||||||
emoji_size=None,
|
|
||||||
sticker=None,
|
|
||||||
attachments=None,
|
|
||||||
quick_replies=None,
|
|
||||||
):
|
|
||||||
"""Represents a Facebook message"""
|
|
||||||
self.text = text
|
|
||||||
if mentions is None:
|
|
||||||
mentions = []
|
|
||||||
self.mentions = mentions
|
|
||||||
self.emoji_size = emoji_size
|
|
||||||
self.sticker = sticker
|
|
||||||
if attachments is None:
|
|
||||||
attachments = []
|
|
||||||
self.attachments = attachments
|
|
||||||
if quick_replies is None:
|
|
||||||
quick_replies = []
|
|
||||||
self.quick_replies = quick_replies
|
|
||||||
self.reactions = {}
|
|
||||||
self.read_by = []
|
|
||||||
self.deleted = False
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__unicode__()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "<Message ({}): {}, mentions={} emoji_size={} attachments={}>".format(
|
|
||||||
self.uid, repr(self.text), self.mentions, self.emoji_size, self.attachments
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def formatMentions(cls, text, *args, **kwargs):
|
|
||||||
"""Like `str.format`, but takes tuples with a thread id and text instead.
|
|
||||||
|
|
||||||
Returns a `Message` object, with the formatted string and relevant mentions.
|
|
||||||
|
|
||||||
```
|
|
||||||
>>> Message.formatMentions("Hey {!r}! My name is {}", ("1234", "Peter"), ("4321", "Michael"))
|
|
||||||
<Message (None): "Hey 'Peter'! My name is Michael", mentions=[<Mention 1234: offset=4 length=7>, <Mention 4321: offset=24 length=7>] emoji_size=None attachments=[]>
|
|
||||||
|
|
||||||
>>> Message.formatMentions("Hey {p}! My name is {}", ("1234", "Michael"), p=("4321", "Peter"))
|
|
||||||
<Message (None): 'Hey Peter! My name is Michael', mentions=[<Mention 4321: offset=4 length=5>, <Mention 1234: offset=22 length=7>] emoji_size=None attachments=[]>
|
|
||||||
```
|
|
||||||
"""
|
|
||||||
result = ""
|
|
||||||
mentions = list()
|
|
||||||
offset = 0
|
|
||||||
f = Formatter()
|
|
||||||
field_names = [field_name[1] for field_name in f.parse(text)]
|
|
||||||
automatic = "" in field_names
|
|
||||||
i = 0
|
|
||||||
|
|
||||||
for (literal_text, field_name, format_spec, conversion) in f.parse(text):
|
|
||||||
offset += len(literal_text)
|
|
||||||
result += literal_text
|
|
||||||
|
|
||||||
if field_name is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if field_name == "":
|
|
||||||
field_name = str(i)
|
|
||||||
i += 1
|
|
||||||
elif automatic and field_name.isdigit():
|
|
||||||
raise ValueError(
|
|
||||||
"cannot switch from automatic field numbering to manual field specification"
|
|
||||||
)
|
|
||||||
|
|
||||||
thread_id, name = f.get_field(field_name, args, kwargs)[0]
|
|
||||||
|
|
||||||
if format_spec:
|
|
||||||
name = f.format_field(name, format_spec)
|
|
||||||
if conversion:
|
|
||||||
name = f.convert_field(name, conversion)
|
|
||||||
|
|
||||||
result += name
|
|
||||||
mentions.append(
|
|
||||||
Mention(thread_id=thread_id, offset=offset, length=len(name))
|
|
||||||
)
|
|
||||||
offset += len(name)
|
|
||||||
|
|
||||||
message = cls(text=result, mentions=mentions)
|
|
||||||
return message
|
|
||||||
|
|
||||||
|
|
||||||
class Attachment(object):
|
|
||||||
#: The attachment ID
|
|
||||||
uid = None
|
|
||||||
|
|
||||||
def __init__(self, uid=None):
|
|
||||||
"""Represents a Facebook attachment"""
|
|
||||||
self.uid = uid
|
|
||||||
|
|
||||||
|
|
||||||
class UnsentMessage(Attachment):
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
"""Represents an unsent message attachment"""
|
|
||||||
super(UnsentMessage, self).__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class Sticker(Attachment):
|
|
||||||
#: The sticker-pack's ID
|
|
||||||
pack = None
|
|
||||||
#: Whether the sticker is animated
|
|
||||||
is_animated = False
|
|
||||||
|
|
||||||
# If the sticker is animated, the following should be present
|
|
||||||
#: URL to a medium spritemap
|
|
||||||
medium_sprite_image = None
|
|
||||||
#: URL to a large spritemap
|
|
||||||
large_sprite_image = None
|
|
||||||
#: The amount of frames present in the spritemap pr. row
|
|
||||||
frames_per_row = None
|
|
||||||
#: The amount of frames present in the spritemap pr. coloumn
|
|
||||||
frames_per_col = None
|
|
||||||
#: The frame rate the spritemap is intended to be played in
|
|
||||||
frame_rate = None
|
|
||||||
|
|
||||||
#: URL to the sticker's image
|
|
||||||
url = None
|
|
||||||
#: Width of the sticker
|
|
||||||
width = None
|
|
||||||
#: Height of the sticker
|
|
||||||
height = None
|
|
||||||
#: The sticker's label/name
|
|
||||||
label = None
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
"""Represents a Facebook sticker that has been sent to a Facebook thread as an attachment"""
|
|
||||||
super(Sticker, self).__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class ShareAttachment(Attachment):
|
|
||||||
#: ID of the author of the shared post
|
|
||||||
author = None
|
|
||||||
#: Target URL
|
|
||||||
url = None
|
|
||||||
#: Original URL if Facebook redirects the URL
|
|
||||||
original_url = None
|
|
||||||
#: Title of the attachment
|
|
||||||
title = None
|
|
||||||
#: Description of the attachment
|
|
||||||
description = None
|
|
||||||
#: Name of the source
|
|
||||||
source = None
|
|
||||||
#: URL of the attachment image
|
|
||||||
image_url = None
|
|
||||||
#: URL of the original image if Facebook uses `safe_image`
|
|
||||||
original_image_url = None
|
|
||||||
#: Width of the image
|
|
||||||
image_width = None
|
|
||||||
#: Height of the image
|
|
||||||
image_height = None
|
|
||||||
#: List of additional attachments
|
|
||||||
attachments = None
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
author=None,
|
|
||||||
url=None,
|
|
||||||
original_url=None,
|
|
||||||
title=None,
|
|
||||||
description=None,
|
|
||||||
source=None,
|
|
||||||
image_url=None,
|
|
||||||
original_image_url=None,
|
|
||||||
image_width=None,
|
|
||||||
image_height=None,
|
|
||||||
attachments=None,
|
|
||||||
**kwargs
|
|
||||||
):
|
|
||||||
"""Represents a shared item (eg. URL) that has been sent as a Facebook attachment"""
|
|
||||||
super(ShareAttachment, self).__init__(**kwargs)
|
|
||||||
self.author = author
|
|
||||||
self.url = url
|
|
||||||
self.original_url = original_url
|
|
||||||
self.title = title
|
|
||||||
self.description = description
|
|
||||||
self.source = source
|
|
||||||
self.image_url = image_url
|
|
||||||
self.original_image_url = original_image_url
|
|
||||||
self.image_width = image_width
|
|
||||||
self.image_height = image_height
|
|
||||||
if attachments is None:
|
|
||||||
attachments = []
|
|
||||||
self.attachments = attachments
|
|
||||||
|
|
||||||
|
|
||||||
class LocationAttachment(Attachment):
|
|
||||||
#: Latidute of the location
|
|
||||||
latitude = None
|
|
||||||
#: Longitude of the location
|
|
||||||
longitude = None
|
|
||||||
#: URL of image showing the map of the location
|
|
||||||
image_url = None
|
|
||||||
#: Width of the image
|
|
||||||
image_width = None
|
|
||||||
#: Height of the image
|
|
||||||
image_height = None
|
|
||||||
#: URL to Bing maps with the location
|
|
||||||
url = None
|
|
||||||
|
|
||||||
def __init__(self, latitude=None, longitude=None, **kwargs):
|
|
||||||
"""Represents a user location"""
|
|
||||||
super(LocationAttachment, self).__init__(**kwargs)
|
|
||||||
self.latitude = latitude
|
|
||||||
self.longitude = longitude
|
|
||||||
|
|
||||||
|
|
||||||
class LiveLocationAttachment(LocationAttachment):
|
|
||||||
#: Name of the location
|
|
||||||
name = None
|
|
||||||
#: Timestamp when live location expires
|
|
||||||
expiration_time = None
|
|
||||||
#: True if live location is expired
|
|
||||||
is_expired = None
|
|
||||||
|
|
||||||
def __init__(self, name=None, expiration_time=None, is_expired=None, **kwargs):
|
|
||||||
"""Represents a live user location"""
|
|
||||||
super(LiveLocationAttachment, self).__init__(**kwargs)
|
|
||||||
self.expiration_time = expiration_time
|
|
||||||
self.is_expired = is_expired
|
|
||||||
|
|
||||||
|
|
||||||
class FileAttachment(Attachment):
|
|
||||||
#: Url where you can download the file
|
|
||||||
url = None
|
|
||||||
#: Size of the file in bytes
|
|
||||||
size = None
|
|
||||||
#: Name of the file
|
|
||||||
name = None
|
|
||||||
#: Whether Facebook determines that this file may be harmful
|
|
||||||
is_malicious = None
|
|
||||||
|
|
||||||
def __init__(self, url=None, size=None, name=None, is_malicious=None, **kwargs):
|
|
||||||
"""Represents a file that has been sent as a Facebook attachment"""
|
|
||||||
super(FileAttachment, self).__init__(**kwargs)
|
|
||||||
self.url = url
|
|
||||||
self.size = size
|
|
||||||
self.name = name
|
|
||||||
self.is_malicious = is_malicious
|
|
||||||
|
|
||||||
|
|
||||||
class AudioAttachment(Attachment):
|
|
||||||
#: Name of the file
|
|
||||||
filename = None
|
|
||||||
#: Url of the audio file
|
|
||||||
url = None
|
|
||||||
#: Duration of the audioclip in milliseconds
|
|
||||||
duration = None
|
|
||||||
#: Audio type
|
|
||||||
audio_type = None
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self, filename=None, url=None, duration=None, audio_type=None, **kwargs
|
|
||||||
):
|
|
||||||
"""Represents an audio file that has been sent as a Facebook attachment"""
|
|
||||||
super(AudioAttachment, self).__init__(**kwargs)
|
|
||||||
self.filename = filename
|
|
||||||
self.url = url
|
|
||||||
self.duration = duration
|
|
||||||
self.audio_type = audio_type
|
|
||||||
|
|
||||||
|
|
||||||
class ImageAttachment(Attachment):
|
|
||||||
#: The extension of the original image (eg. 'png')
|
|
||||||
original_extension = None
|
|
||||||
#: Width of original image
|
|
||||||
width = None
|
|
||||||
#: Height of original image
|
|
||||||
height = None
|
|
||||||
|
|
||||||
#: Whether the image is animated
|
|
||||||
is_animated = None
|
|
||||||
|
|
||||||
#: URL to a thumbnail of the image
|
|
||||||
thumbnail_url = None
|
|
||||||
|
|
||||||
#: URL to a medium preview of the image
|
|
||||||
preview_url = None
|
|
||||||
#: Width of the medium preview image
|
|
||||||
preview_width = None
|
|
||||||
#: Height of the medium preview image
|
|
||||||
preview_height = None
|
|
||||||
|
|
||||||
#: URL to a large preview of the image
|
|
||||||
large_preview_url = None
|
|
||||||
#: Width of the large preview image
|
|
||||||
large_preview_width = None
|
|
||||||
#: Height of the large preview image
|
|
||||||
large_preview_height = None
|
|
||||||
|
|
||||||
#: URL to an animated preview of the image (eg. for gifs)
|
|
||||||
animated_preview_url = None
|
|
||||||
#: Width of the animated preview image
|
|
||||||
animated_preview_width = None
|
|
||||||
#: Height of the animated preview image
|
|
||||||
animated_preview_height = None
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
original_extension=None,
|
|
||||||
width=None,
|
|
||||||
height=None,
|
|
||||||
is_animated=None,
|
|
||||||
thumbnail_url=None,
|
|
||||||
preview=None,
|
|
||||||
large_preview=None,
|
|
||||||
animated_preview=None,
|
|
||||||
**kwargs
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Represents an image that has been sent as a Facebook attachment
|
|
||||||
To retrieve the full image url, use: :func:`fbchat.Client.fetchImageUrl`,
|
|
||||||
and pass it the uid of the image attachment
|
|
||||||
"""
|
|
||||||
super(ImageAttachment, self).__init__(**kwargs)
|
|
||||||
self.original_extension = original_extension
|
|
||||||
if width is not None:
|
|
||||||
width = int(width)
|
|
||||||
self.width = width
|
|
||||||
if height is not None:
|
|
||||||
height = int(height)
|
|
||||||
self.height = height
|
|
||||||
self.is_animated = is_animated
|
|
||||||
self.thumbnail_url = thumbnail_url
|
|
||||||
|
|
||||||
if preview is None:
|
|
||||||
preview = {}
|
|
||||||
self.preview_url = preview.get("uri")
|
|
||||||
self.preview_width = preview.get("width")
|
|
||||||
self.preview_height = preview.get("height")
|
|
||||||
|
|
||||||
if large_preview is None:
|
|
||||||
large_preview = {}
|
|
||||||
self.large_preview_url = large_preview.get("uri")
|
|
||||||
self.large_preview_width = large_preview.get("width")
|
|
||||||
self.large_preview_height = large_preview.get("height")
|
|
||||||
|
|
||||||
if animated_preview is None:
|
|
||||||
animated_preview = {}
|
|
||||||
self.animated_preview_url = animated_preview.get("uri")
|
|
||||||
self.animated_preview_width = animated_preview.get("width")
|
|
||||||
self.animated_preview_height = animated_preview.get("height")
|
|
||||||
|
|
||||||
|
|
||||||
class VideoAttachment(Attachment):
|
|
||||||
#: Size of the original video in bytes
|
|
||||||
size = None
|
|
||||||
#: Width of original video
|
|
||||||
width = None
|
|
||||||
#: Height of original video
|
|
||||||
height = None
|
|
||||||
#: Length of video in milliseconds
|
|
||||||
duration = None
|
|
||||||
#: URL to very compressed preview video
|
|
||||||
preview_url = None
|
|
||||||
|
|
||||||
#: URL to a small preview image of the video
|
|
||||||
small_image_url = None
|
|
||||||
#: Width of the small preview image
|
|
||||||
small_image_width = None
|
|
||||||
#: Height of the small preview image
|
|
||||||
small_image_height = None
|
|
||||||
|
|
||||||
#: URL to a medium preview image of the video
|
|
||||||
medium_image_url = None
|
|
||||||
#: Width of the medium preview image
|
|
||||||
medium_image_width = None
|
|
||||||
#: Height of the medium preview image
|
|
||||||
medium_image_height = None
|
|
||||||
|
|
||||||
#: URL to a large preview image of the video
|
|
||||||
large_image_url = None
|
|
||||||
#: Width of the large preview image
|
|
||||||
large_image_width = None
|
|
||||||
#: Height of the large preview image
|
|
||||||
large_image_height = None
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
size=None,
|
|
||||||
width=None,
|
|
||||||
height=None,
|
|
||||||
duration=None,
|
|
||||||
preview_url=None,
|
|
||||||
small_image=None,
|
|
||||||
medium_image=None,
|
|
||||||
large_image=None,
|
|
||||||
**kwargs
|
|
||||||
):
|
|
||||||
"""Represents a video that has been sent as a Facebook attachment"""
|
|
||||||
super(VideoAttachment, self).__init__(**kwargs)
|
|
||||||
self.size = size
|
|
||||||
self.width = width
|
|
||||||
self.height = height
|
|
||||||
self.duration = duration
|
|
||||||
self.preview_url = preview_url
|
|
||||||
|
|
||||||
if small_image is None:
|
|
||||||
small_image = {}
|
|
||||||
self.small_image_url = small_image.get("uri")
|
|
||||||
self.small_image_width = small_image.get("width")
|
|
||||||
self.small_image_height = small_image.get("height")
|
|
||||||
|
|
||||||
if medium_image is None:
|
|
||||||
medium_image = {}
|
|
||||||
self.medium_image_url = medium_image.get("uri")
|
|
||||||
self.medium_image_width = medium_image.get("width")
|
|
||||||
self.medium_image_height = medium_image.get("height")
|
|
||||||
|
|
||||||
if large_image is None:
|
|
||||||
large_image = {}
|
|
||||||
self.large_image_url = large_image.get("uri")
|
|
||||||
self.large_image_width = large_image.get("width")
|
|
||||||
self.large_image_height = large_image.get("height")
|
|
||||||
|
|
||||||
|
|
||||||
class Mention(object):
|
|
||||||
#: The thread ID the mention is pointing at
|
|
||||||
thread_id = None
|
|
||||||
#: The character where the mention starts
|
|
||||||
offset = None
|
|
||||||
#: The length of the mention
|
|
||||||
length = None
|
|
||||||
|
|
||||||
def __init__(self, thread_id, offset=0, length=10):
|
|
||||||
"""Represents a @mention"""
|
|
||||||
self.thread_id = thread_id
|
|
||||||
self.offset = offset
|
|
||||||
self.length = length
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__unicode__()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "<Mention {}: offset={} length={}>".format(
|
|
||||||
self.thread_id, self.offset, self.length
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class QuickReply(object):
|
|
||||||
#: Payload of the quick reply
|
|
||||||
payload = None
|
|
||||||
#: External payload for responses
|
|
||||||
external_payload = None
|
|
||||||
#: Additional data
|
|
||||||
data = None
|
|
||||||
#: Whether it's a response for a quick reply
|
|
||||||
is_response = None
|
|
||||||
|
|
||||||
def __init__(self, payload=None, data=None, is_response=False):
|
|
||||||
"""Represents a quick reply"""
|
|
||||||
self.payload = payload
|
|
||||||
self.data = data
|
|
||||||
self.is_response = is_response
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__unicode__()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "<{}: payload={!r}>".format(self.__class__.__name__, self.payload)
|
|
||||||
|
|
||||||
|
|
||||||
class QuickReplyText(QuickReply):
|
|
||||||
#: Title of the quick reply
|
|
||||||
title = None
|
|
||||||
#: URL of the quick reply image (optional)
|
|
||||||
image_url = None
|
|
||||||
#: Type of the quick reply
|
|
||||||
_type = "text"
|
|
||||||
|
|
||||||
def __init__(self, title=None, image_url=None, **kwargs):
|
|
||||||
"""Represents a text quick reply"""
|
|
||||||
super(QuickReplyText, self).__init__(**kwargs)
|
|
||||||
self.title = title
|
|
||||||
self.image_url = image_url
|
|
||||||
|
|
||||||
|
|
||||||
class QuickReplyLocation(QuickReply):
|
|
||||||
#: Type of the quick reply
|
|
||||||
_type = "location"
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
"""Represents a location quick reply (Doesn't work on mobile)"""
|
|
||||||
super(QuickReplyLocation, self).__init__(**kwargs)
|
|
||||||
self.is_response = False
|
|
||||||
|
|
||||||
|
|
||||||
class QuickReplyPhoneNumber(QuickReply):
|
|
||||||
#: URL of the quick reply image (optional)
|
|
||||||
image_url = None
|
|
||||||
#: Type of the quick reply
|
|
||||||
_type = "user_phone_number"
|
|
||||||
|
|
||||||
def __init__(self, image_url=None, **kwargs):
|
|
||||||
"""Represents a phone number quick reply (Doesn't work on mobile)"""
|
|
||||||
super(QuickReplyPhoneNumber, self).__init__(**kwargs)
|
|
||||||
self.image_url = image_url
|
|
||||||
|
|
||||||
|
|
||||||
class QuickReplyEmail(QuickReply):
|
|
||||||
#: URL of the quick reply image (optional)
|
|
||||||
image_url = None
|
|
||||||
#: Type of the quick reply
|
|
||||||
_type = "user_email"
|
|
||||||
|
|
||||||
def __init__(self, image_url=None, **kwargs):
|
|
||||||
"""Represents an email quick reply (Doesn't work on mobile)"""
|
|
||||||
super(QuickReplyEmail, self).__init__(**kwargs)
|
|
||||||
self.image_url = image_url
|
|
||||||
|
|
||||||
|
|
||||||
class Poll(object):
|
|
||||||
#: ID of the poll
|
|
||||||
uid = None
|
|
||||||
#: Title of the poll
|
|
||||||
title = None
|
|
||||||
#: List of :class:`PollOption`, can be fetched with :func:`fbchat.Client.fetchPollOptions`
|
|
||||||
options = None
|
|
||||||
#: Options count
|
|
||||||
options_count = None
|
|
||||||
|
|
||||||
def __init__(self, title, options):
|
|
||||||
"""Represents a poll"""
|
|
||||||
self.title = title
|
|
||||||
self.options = options
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__unicode__()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "<Poll ({}): {} options={}>".format(
|
|
||||||
self.uid, repr(self.title), self.options
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PollOption(object):
|
|
||||||
#: ID of the poll option
|
|
||||||
uid = None
|
|
||||||
#: Text of the poll option
|
|
||||||
text = None
|
|
||||||
#: Whether vote when creating or client voted
|
|
||||||
vote = None
|
|
||||||
#: ID of the users who voted for this poll option
|
|
||||||
voters = None
|
|
||||||
#: Votes count
|
|
||||||
votes_count = None
|
|
||||||
|
|
||||||
def __init__(self, text, vote=False):
|
|
||||||
"""Represents a poll option"""
|
|
||||||
self.text = text
|
|
||||||
self.vote = vote
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__unicode__()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "<PollOption ({}): {} voters={}>".format(
|
|
||||||
self.uid, repr(self.text), self.voters
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Plan(object):
|
|
||||||
#: ID of the plan
|
|
||||||
uid = None
|
|
||||||
#: Plan time (unix time stamp), only precise down to the minute
|
|
||||||
time = None
|
|
||||||
#: Plan title
|
|
||||||
title = None
|
|
||||||
#: Plan location name
|
|
||||||
location = None
|
|
||||||
#: Plan location ID
|
|
||||||
location_id = None
|
|
||||||
#: ID of the plan creator
|
|
||||||
author_id = None
|
|
||||||
#: List of the people IDs who will take part in the plan
|
|
||||||
going = None
|
|
||||||
#: List of the people IDs who won't take part in the plan
|
|
||||||
declined = None
|
|
||||||
#: List of the people IDs who are invited to the plan
|
|
||||||
invited = None
|
|
||||||
|
|
||||||
def __init__(self, time, title, location=None, location_id=None):
|
|
||||||
"""Represents a plan"""
|
|
||||||
self.time = int(time)
|
|
||||||
self.title = title
|
|
||||||
self.location = location or ""
|
|
||||||
self.location_id = location_id or ""
|
|
||||||
self.author_id = None
|
|
||||||
self.going = []
|
|
||||||
self.declined = []
|
|
||||||
self.invited = []
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__unicode__()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "<Plan ({}): {} time={}, location={}, location_id={}>".format(
|
|
||||||
self.uid,
|
|
||||||
repr(self.title),
|
|
||||||
self.time,
|
|
||||||
repr(self.location),
|
|
||||||
repr(self.location_id),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ActiveStatus(object):
|
|
||||||
#: Whether the user is active now
|
|
||||||
active = None
|
|
||||||
#: Timestamp when the user was last active
|
|
||||||
last_active = None
|
|
||||||
#: Whether the user is playing Messenger game now
|
|
||||||
in_game = None
|
|
||||||
|
|
||||||
def __init__(self, active=None, last_active=None, in_game=None):
|
|
||||||
self.active = active
|
|
||||||
self.last_active = last_active
|
|
||||||
self.in_game = in_game
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.__unicode__()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "<ActiveStatus: active={} last_active={} in_game={}>".format(
|
|
||||||
self.active, self.last_active, self.in_game
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Enum(aenum.Enum):
|
|
||||||
"""Used internally by fbchat to support enumerations"""
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
# For documentation:
|
|
||||||
return "{}.{}".format(type(self).__name__, self.name)
|
|
||||||
|
|
||||||
|
|
||||||
class ThreadType(Enum):
|
|
||||||
"""Used to specify what type of Facebook thread is being used. See :ref:`intro_threads` for more info"""
|
|
||||||
|
|
||||||
USER = 1
|
|
||||||
GROUP = 2
|
|
||||||
ROOM = 2
|
|
||||||
PAGE = 3
|
|
||||||
|
|
||||||
|
|
||||||
class ThreadLocation(Enum):
|
|
||||||
"""Used to specify where a thread is located (inbox, pending, archived, other)."""
|
|
||||||
|
|
||||||
INBOX = "INBOX"
|
|
||||||
PENDING = "PENDING"
|
|
||||||
ARCHIVED = "ARCHIVED"
|
|
||||||
OTHER = "OTHER"
|
|
||||||
|
|
||||||
|
|
||||||
class TypingStatus(Enum):
|
|
||||||
"""Used to specify whether the user is typing or has stopped typing"""
|
|
||||||
|
|
||||||
STOPPED = 0
|
|
||||||
TYPING = 1
|
|
||||||
|
|
||||||
|
|
||||||
class EmojiSize(Enum):
|
|
||||||
"""Used to specify the size of a sent emoji"""
|
|
||||||
|
|
||||||
LARGE = "369239383222810"
|
|
||||||
MEDIUM = "369239343222814"
|
|
||||||
SMALL = "369239263222822"
|
|
||||||
|
|
||||||
|
|
||||||
class ThreadColor(Enum):
|
|
||||||
"""Used to specify a thread colors"""
|
|
||||||
|
|
||||||
MESSENGER_BLUE = "#0084ff"
|
|
||||||
VIKING = "#44bec7"
|
|
||||||
GOLDEN_POPPY = "#ffc300"
|
|
||||||
RADICAL_RED = "#fa3c4c"
|
|
||||||
SHOCKING = "#d696bb"
|
|
||||||
PICTON_BLUE = "#6699cc"
|
|
||||||
FREE_SPEECH_GREEN = "#13cf13"
|
|
||||||
PUMPKIN = "#ff7e29"
|
|
||||||
LIGHT_CORAL = "#e68585"
|
|
||||||
MEDIUM_SLATE_BLUE = "#7646ff"
|
|
||||||
DEEP_SKY_BLUE = "#20cef5"
|
|
||||||
FERN = "#67b868"
|
|
||||||
CAMEO = "#d4a88c"
|
|
||||||
BRILLIANT_ROSE = "#ff5ca1"
|
|
||||||
BILOBA_FLOWER = "#a695c7"
|
|
||||||
|
|
||||||
|
|
||||||
class MessageReaction(Enum):
|
|
||||||
"""Used to specify a message reaction"""
|
|
||||||
|
|
||||||
LOVE = "😍"
|
|
||||||
SMILE = "😆"
|
|
||||||
WOW = "😮"
|
|
||||||
SAD = "😢"
|
|
||||||
ANGRY = "😠"
|
|
||||||
YES = "👍"
|
|
||||||
NO = "👎"
|
|
||||||
|
@@ -23,6 +23,7 @@ maintainer-email = "madsmtm@gmail.com"
|
|||||||
home-page = "https://github.com/carpedm20/fbchat/"
|
home-page = "https://github.com/carpedm20/fbchat/"
|
||||||
requires = [
|
requires = [
|
||||||
"aenum",
|
"aenum",
|
||||||
|
"attrs~=18.2.0",
|
||||||
"requests",
|
"requests",
|
||||||
"beautifulsoup4",
|
"beautifulsoup4",
|
||||||
]
|
]
|
||||||
|
Reference in New Issue
Block a user