diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 453d42c..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -name: Bug report -about: Create a report if you're having trouble with `fbchat` - ---- - -## Description of the problem -Example: Logging in fails when the character `%` is in the password. A specific password that fails is `a_password_with_%` - -## Code to reproduce -```py -# Example code -from fbchat import Client -client = Client("[REDACTED_USERNAME]", "a_password_with_%") -``` - -## Traceback -``` -Traceback (most recent call last): - File "", line 1, in - File "[site-packages]/fbchat/client.py", line 78, in __init__ - self.login(email, password, max_tries) - File "[site-packages]/fbchat/client.py", line 407, in login - raise FBchatException('Login failed. Check email/password. (Failed on URL: {})'.format(login_url)) -fbchat.FBchatException: Login failed. Check email/password. (Failed on URL: https://m.facebook.com/login.php?login_attempt=1) -``` - -## Environment information -- Python version -- `fbchat` version -- If relevant, output from `$ python -m pip list` - -If you have done any research, include that. -Make sure to redact all personal information. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index ac0c918..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -name: Feature request -about: Suggest a feature that you'd like to see implemented - ---- - -## Description -Example: There's no way to send messages to groups - -## Research (if applicable) -Example: I've found the URL `https://facebook.com/send_message.php`, to which you can send a POST requests with the following JSON: -```json -{ - "text": message_content, - "fbid": group_id, - "some_variable": ? -} -``` -But I don't know how what `some_variable` does, and it doesn't work without it. I've found some examples of `some_variable` to be: `MTIzNDU2Nzg5MA`, `MTIzNDU2Nzg5MQ` and `MTIzNDU2Nzg5Mg` diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 9070b78..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,20 +0,0 @@ -# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details -version: 2 - -formats: - - pdf - - htmlzip - -python: - version: 3.6 - install: - - path: . - extra_requirements: - - docs - -# Build documentation in the docs/ directory with Sphinx -sphinx: - configuration: docs/conf.py - # Disabled, until we can find a way to get sphinx-autodoc-typehints play nice with our - # module renaming! - fail_on_warning: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f63d7ae..0000000 --- a/.travis.yml +++ /dev/null @@ -1,53 +0,0 @@ -sudo: false -language: python -python: 3.6 - -cache: pip - -before_install: pip install flit -# Use `--deps production` so that we don't install unnecessary dependencies -install: flit install --deps production --extras test -script: pytest - -jobs: - include: - - python: 3.5 - - python: 3.6 - - python: 3.7 - - python: pypy3.5 - - - name: Lint - before_install: skip - install: pip install black - script: black --check --verbose . - - - stage: deploy - name: GitHub Releases - if: tag IS present - install: skip - script: flit build - deploy: - provider: releases - api_key: $GITHUB_OAUTH_TOKEN - file_glob: true - file: dist/* - skip_cleanup: true - draft: false - on: - tags: true - - - stage: deploy - name: PyPI - if: tag IS present - install: skip - script: skip - deploy: - provider: script - script: flit publish - on: - tags: true - -notifications: - email: - on_success: never - on_failure: change diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3bc9f31 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "esbonio.sphinx.confDir": "" +} diff --git a/README.rst b/README.rst index 9725752..d6ab750 100644 --- a/README.rst +++ b/README.rst @@ -1,48 +1,6 @@ -This project is unmaintained -============================ - -This project is officially marked as unmaintained, since my life is somewhere where I just do not have the time and energy to lead this project. - -If there is someone out there willing to take the lead, please get in contact, but even if there is, I can't get in contact with the original author `@carpedm20 `__ and get the ability to add others as maintainers, see `issue 390 `__. So a fork might be preferable. - -I have opened for further discussion `in issue 613 `__. - -Thanks for serving you all these years. - -\- Mads Marquart / `@madsmtm `__. - - -Original project description below ----------------------------------- - - ``fbchat`` - Facebook Messenger for Python ========================================== -.. image:: https://badgen.net/pypi/v/fbchat - :target: https://pypi.python.org/pypi/fbchat - :alt: Project version - -.. image:: https://badgen.net/badge/python/3.5,3.6,3.7,3.8,pypy?list=| - :target: https://pypi.python.org/pypi/fbchat - :alt: Supported python versions: 3.5, 3.6, 3.7, 3.8 and pypy - -.. image:: https://badgen.net/pypi/license/fbchat - :target: https://github.com/carpedm20/fbchat/tree/master/LICENSE - :alt: License: BSD 3-Clause - -.. image:: https://readthedocs.org/projects/fbchat/badge/?version=stable - :target: https://fbchat.readthedocs.io - :alt: Documentation - -.. image:: https://badgen.net/travis/carpedm20/fbchat - :target: https://travis-ci.org/carpedm20/fbchat - :alt: Travis CI - -.. image:: https://badgen.net/badge/code%20style/black/black - :target: https://github.com/ambv/black - :alt: Code style - A powerful and efficient library to interact with `Facebook's Messenger `__, using just your email and password. @@ -56,16 +14,13 @@ This is *not* an official API, Facebook has that `over here `__. - -Additionally, you can view the project's progress `here `__. +``v2`` is currently being developed at the ``master`` branch and it's highly unstable. Caveats @@ -76,14 +31,6 @@ Caveats However, there's a catch! **Using this library may not comply with Facebook's Terms Of Service!**, so be responsible Facebook citizens! We are not responsible if your account gets banned! Additionally, **the APIs the library is calling is undocumented!** In theory, this means that your code could break tomorrow, without the slightest warning! -If this happens to you, please report it, so that we can fix it as soon as possible! - -.. inclusion-marker-intro-end -.. This message doesn't make sense in the docs at Read The Docs, so we exclude it - -With that out of the way, you may go to `Read The Docs `__ to see the full documentation! - -.. inclusion-marker-installation-start Installation @@ -91,17 +38,7 @@ Installation .. code-block:: - $ pip install fbchat - -If you don't have `pip `_, `this guide `_ can guide you through the process. - -You can also install directly from source, provided you have ``pip>=19.0``: - -.. code-block:: - - $ pip install git+https://github.com/carpedm20/fbchat.git - -.. inclusion-marker-installation-end + $ pip install git+https://git.karaolidis.com/Nikas36/fbchat.git Example Usage @@ -112,18 +49,11 @@ Example Usage import getpass import fbchat session = fbchat.Session.login("", getpass.getpass()) - user = fbchat.User(session=session, id=session.user_id) + user = fbchat.User(session=session, id=session._user_id) user.send_text("Test message!") -More examples are available `here `__. - - -Maintainer ----------- - -No one, see notice at the top. Acknowledgements ---------------- -This project was originally inspired by `facebook-chat-api `__. +This project is a fork of `fbchat `__ and was originally inspired by `facebook-chat-api `__. diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index 5128596..0000000 --- a/docs/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -SOURCEDIR = . -BUILDDIR = _build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/_static/find-group-id.png b/docs/_static/find-group-id.png deleted file mode 100644 index b60f143..0000000 Binary files a/docs/_static/find-group-id.png and /dev/null differ diff --git a/docs/_templates/layout.html b/docs/_templates/layout.html deleted file mode 100644 index 5ad7d43..0000000 --- a/docs/_templates/layout.html +++ /dev/null @@ -1,26 +0,0 @@ -{% extends '!layout.html' %} - -{% block extrahead %} - - - -{% endblock %} diff --git a/docs/_templates/sidebar.html b/docs/_templates/sidebar.html deleted file mode 100644 index 143754a..0000000 --- a/docs/_templates/sidebar.html +++ /dev/null @@ -1,13 +0,0 @@ -

- {{ _(project) }} -

- -

- Star -

- -

- {{ _(shorttitle) }} -

- -{{ toctree() }} \ No newline at end of file diff --git a/docs/api/attachments.rst b/docs/api/attachments.rst deleted file mode 100644 index 01841a4..0000000 --- a/docs/api/attachments.rst +++ /dev/null @@ -1,13 +0,0 @@ -Attachments -=========== - -.. autoclass:: Attachment() -.. autoclass:: ShareAttachment() -.. autoclass:: Sticker() -.. autoclass:: LocationAttachment() -.. autoclass:: LiveLocationAttachment() -.. autoclass:: FileAttachment() -.. autoclass:: AudioAttachment() -.. autoclass:: ImageAttachment() -.. autoclass:: VideoAttachment() -.. autoclass:: ImageAttachment() diff --git a/docs/api/client.rst b/docs/api/client.rst deleted file mode 100644 index b392eb0..0000000 --- a/docs/api/client.rst +++ /dev/null @@ -1,4 +0,0 @@ -Client -====== - -.. autoclass:: Client diff --git a/docs/api/events.rst b/docs/api/events.rst deleted file mode 100644 index 233e9bd..0000000 --- a/docs/api/events.rst +++ /dev/null @@ -1,4 +0,0 @@ -Events -====== - -.. autoclass:: Listener diff --git a/docs/api/exceptions.rst b/docs/api/exceptions.rst deleted file mode 100644 index 09958ca..0000000 --- a/docs/api/exceptions.rst +++ /dev/null @@ -1,11 +0,0 @@ -Exceptions -========== - -.. autoexception:: FacebookError() -.. autoexception:: HTTPError() -.. autoexception:: ParseError() -.. autoexception:: NotLoggedIn() -.. autoexception:: ExternalError() -.. autoexception:: GraphQLError() -.. autoexception:: InvalidParameters() -.. autoexception:: PleaseRefresh() diff --git a/docs/api/index.rst b/docs/api/index.rst deleted file mode 100644 index 0cc6ccf..0000000 --- a/docs/api/index.rst +++ /dev/null @@ -1,21 +0,0 @@ -.. module:: fbchat - -.. Note: we're using () to hide the __init__ method where relevant - -Full API -======== - -If you are looking for information on a specific function, class, or method, this part of the documentation is for you. - -.. toctree:: - :maxdepth: 1 - - session - client - threads - thread_data - messages - exceptions - attachments - events - misc diff --git a/docs/api/messages.rst b/docs/api/messages.rst deleted file mode 100644 index 1f1cf53..0000000 --- a/docs/api/messages.rst +++ /dev/null @@ -1,8 +0,0 @@ -Messages -======== - -.. autoclass:: Message -.. autoclass:: Mention -.. autoclass:: EmojiSize(Enum) - :undoc-members: -.. autoclass:: MessageData() diff --git a/docs/api/misc.rst b/docs/api/misc.rst deleted file mode 100644 index 89430b3..0000000 --- a/docs/api/misc.rst +++ /dev/null @@ -1,20 +0,0 @@ -Miscellaneous -============= - -.. autoclass:: ThreadLocation(Enum) - :undoc-members: -.. autoclass:: ActiveStatus() - -.. autoclass:: QuickReply -.. autoclass:: QuickReplyText -.. autoclass:: QuickReplyLocation -.. autoclass:: QuickReplyPhoneNumber -.. autoclass:: QuickReplyEmail - -.. autoclass:: Poll -.. autoclass:: PollOption - -.. autoclass:: Plan -.. autoclass:: PlanData() -.. autoclass:: GuestStatus(Enum) - :undoc-members: diff --git a/docs/api/session.rst b/docs/api/session.rst deleted file mode 100644 index 09ab89a..0000000 --- a/docs/api/session.rst +++ /dev/null @@ -1,4 +0,0 @@ -Session -======= - -.. autoclass:: Session() diff --git a/docs/api/thread_data.rst b/docs/api/thread_data.rst deleted file mode 100644 index 7ed8306..0000000 --- a/docs/api/thread_data.rst +++ /dev/null @@ -1,6 +0,0 @@ -Thread Data -=========== - -.. autoclass:: PageData() -.. autoclass:: UserData() -.. autoclass:: GroupData() diff --git a/docs/api/threads.rst b/docs/api/threads.rst deleted file mode 100644 index 79de8f2..0000000 --- a/docs/api/threads.rst +++ /dev/null @@ -1,8 +0,0 @@ -Threads -======= - -.. autoclass:: ThreadABC() -.. autoclass:: Thread -.. autoclass:: Page -.. autoclass:: User -.. autoclass:: Group diff --git a/docs/conf.py b/docs/conf.py deleted file mode 100644 index f942d18..0000000 --- a/docs/conf.py +++ /dev/null @@ -1,194 +0,0 @@ -# Configuration file for the Sphinx documentation builder. -# -# This file does only contain a selection of the most common options. For a -# full list see the documentation: -# http://www.sphinx-doc.org/en/master/config - -# -- Path setup -------------------------------------------------------------- - -import os -import sys - -sys.path.insert(0, os.path.abspath("..")) - -os.environ["_FBCHAT_DISABLE_FIX_MODULE_METADATA"] = "1" - -import fbchat - -del os.environ["_FBCHAT_DISABLE_FIX_MODULE_METADATA"] - -# -- Project information ----------------------------------------------------- - -project = fbchat.__name__ -copyright = "Copyright 2015 - 2018 by Taehoon Kim and 2018 - 2020 by Mads Marquart" -author = "Taehoon Kim; Moreels Pieter-Jan; Mads Marquart" -description = fbchat.__doc__.split("\n")[0] - -# The short X.Y version -version = fbchat.__version__ -# The full version, including alpha/beta/rc tags -release = fbchat.__version__ - - -# -- General configuration --------------------------------------------------- - -# If your documentation needs a minimal Sphinx version, state it here. -# -needs_sphinx = "2.0" - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.intersphinx", - "sphinx.ext.viewcode", - "sphinx.ext.napoleon", - "sphinxcontrib.spelling", - "sphinx_autodoc_typehints", -] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# The master toctree document. -master_doc = "index" - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] - -rst_prolog = ".. currentmodule:: " + project - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# -default_role = "any" - -# Make the reference parsing more strict -# -nitpicky = True - -# Prefer strict Python highlighting -# -highlight_language = "python3" - -# If true, '()' will be appended to :func: etc. cross-reference text. -# -add_function_parentheses = False - - -# -- Options for HTML output ------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -# -html_theme_options = { - "show_powered_by": False, - "github_user": "carpedm20", - "github_repo": project, - "github_banner": True, - "show_related": False, -} - -# Custom sidebar templates, must be a dictionary that maps document names -# to template names. -# -# The default sidebars (for documents that don't match any pattern) are -# defined by theme itself. Builtin themes are using these templates by -# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', -# 'searchbox.html']``. -# -html_sidebars = {"**": ["sidebar.html", "searchbox.html"]} - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# -html_show_sphinx = False - -# If true, links to the reST sources are added to the pages. -# -html_show_sourcelink = False - -# A shorter title for the navigation bar. Default is the same as html_title. -# -html_short_title = description - - -# -- Options for HTMLHelp output --------------------------------------------- - -# Output file base name for HTML help builder. -htmlhelp_basename = project + "doc" - - -# -- Options for LaTeX output ------------------------------------------------ - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [(master_doc, project + ".tex", project, author, "manual")] - - -# -- Options for manual page output ------------------------------------------ - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [(master_doc, project, project, [x.strip() for x in author.split(";")], 1)] - - -# -- Options for Texinfo output ---------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - (master_doc, project, project, author, project, description, "Miscellaneous",) -] - - -# -- Options for Epub output ------------------------------------------------- - -# A list of files that should not be packed into the epub file. -epub_exclude_files = ["search.html"] - - -# -- Extension configuration ------------------------------------------------- - -# -- Options for autodoc extension --------------------------------------- - -autoclass_content = "class" -autodoc_member_order = "bysource" -autodoc_default_options = {"members": True} - -# -- Options for intersphinx extension --------------------------------------- - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {"https://docs.python.org/": None} - -# -- Options for napoleon extension ---------------------------------------------- - -# Use Google style docstrings -napoleon_google_docstring = True -napoleon_numpy_docstring = False - -# napoleon_use_admonition_for_examples = False -# napoleon_use_admonition_for_notes = False -# napoleon_use_admonition_for_references = False - -# -- Options for spelling extension ---------------------------------------------- - -spelling_word_list_filename = [ - "spelling/names.txt", - "spelling/technical.txt", - "spelling/fixes.txt", -] -spelling_ignore_wiki_words = False -# spelling_ignore_acronyms = False -spelling_ignore_python_builtins = False -spelling_ignore_importable_modules = False diff --git a/docs/examples.rst b/docs/examples.rst deleted file mode 100644 index aac1fce..0000000 --- a/docs/examples.rst +++ /dev/null @@ -1,55 +0,0 @@ -.. _examples: - -Examples -======== - -These are a few examples on how to use ``fbchat``. Remember to swap out ```` and ```` for your email and password - - -Basic example -------------- - -This will show basic usage of ``fbchat`` - -.. literalinclude:: ../examples/basic_usage.py - - -Interacting with Threads ------------------------- - -This will interact with the thread in every way ``fbchat`` supports - -.. literalinclude:: ../examples/interract.py - - -Fetching Information --------------------- - -This will show the different ways of fetching information about users and threads - -.. literalinclude:: ../examples/fetch.py - - -``Echobot`` ------------ - -This will reply to any message with the same message - -.. literalinclude:: ../examples/echobot.py - - -Remove Bot ----------- - -This will remove a user from a group if they write the message ``Remove me!`` - -.. literalinclude:: ../examples/removebot.py - - -"Prevent changes"-Bot ---------------------- - -This will prevent chat color, emoji, nicknames and chat name from being changed. -It will also prevent people from being added and removed - -.. literalinclude:: ../examples/keepbot.py diff --git a/docs/faq.rst b/docs/faq.rst deleted file mode 100644 index 28183b8..0000000 --- a/docs/faq.rst +++ /dev/null @@ -1,23 +0,0 @@ -Frequently Asked Questions -========================== - -The new version broke my application ------------------------------------- - -``fbchat`` follows `Scemantic Versioning `__ quite rigorously! - -That means that breaking changes can *only* occur in major versions (e.g. ``v1.9.6`` -> ``v2.0.0``). - -If you find that something breaks, and you didn't update to a new major version, then it is a bug, and we would be grateful if you reported it! - -In case you're stuck with an old codebase, you can downgrade to a previous version of ``fbchat``, e.g. version ``1.9.6``: - -.. code-block:: sh - - $ pip install fbchat==1.9.6 - - -Will you be supporting creating posts/events/pages and so on? -------------------------------------------------------------- - -We won't be focusing on anything else than chat-related things. This library is called ``fbCHAT``, after all! diff --git a/docs/index.rst b/docs/index.rst deleted file mode 100644 index 99af34b..0000000 --- a/docs/index.rst +++ /dev/null @@ -1,23 +0,0 @@ -.. highlight:: sh -.. See README.rst for explanation of these markers - -.. include:: ../README.rst - :end-before: inclusion-marker-intro-end - -With that said, let's get started! - -.. include:: ../README.rst - :start-after: inclusion-marker-installation-start - :end-before: inclusion-marker-installation-end - - -Documentation Overview ----------------------- - -.. toctree:: - :maxdepth: 2 - - intro - examples - faq - api/index diff --git a/docs/intro.rst b/docs/intro.rst deleted file mode 100644 index 108c8bb..0000000 --- a/docs/intro.rst +++ /dev/null @@ -1,152 +0,0 @@ -Introduction -============ - -Welcome, this page will guide you through the basic concepts of using ``fbchat``. - -The hardest, and most error prone part is logging in, and managing your login session, so that is what we will look at first. - - -Logging In ----------- - -Everything in ``fbchat`` starts with getting an instance of `Session`. Currently there are two ways of doing that, `Session.login` and `Session.from_cookies`. - -The follow example will prompt you for you password, and use it to login:: - - import getpass - import fbchat - session = fbchat.Session.login("", getpass.getpass()) - # If your account requires a two factor authentication code: - session = fbchat.Session.login( - "", - getpass.getpass(), - lambda: getpass.getpass("2FA code"), - ) - -However, **this is not something you should do often!** Logging in/out all the time *will* get your Facebook account locked! - -Instead, you should start by using `Session.login`, and then store the cookies with `Session.get_cookies`, so that they can be used instead the next time your application starts. - -Usability-wise, this is also better, since you won't have to re-type your password every time you want to login. - -The following, quite lengthy, yet very import example, illustrates a way to do this: - -.. literalinclude:: ../examples/session_handling.py - -Assuming you have successfully completed the above, congratulations! Using ``fbchat`` should be mostly trouble free from now on! - - -Understanding Thread Ids ------------------------- - -At the core of any thread is its unique identifier, its ID. - -A thread basically just means "something I can chat with", but more precisely, it can refer to a few things: -- A Messenger group thread (`Group`) -- The conversation between you and a single Facebook user (`User`) -- The conversation between you and a Facebook Page (`Page`) - -You can get your own user ID from `Session.user` with ``session.user.id``. - -Getting the ID of a specific group thread is fairly trivial, you only need to login to ``_, click on the group you want to find the ID of, and then read the id from the address bar. -The URL will look something like this: ``https://www.messenger.com/t/1234567890``, where ``1234567890`` would be the ID of the group. - -The same method can be applied to some user accounts, though if they have set a custom URL, then you will have to use a different method. - -An image to illustrate the process is shown below: - -.. image:: /_static/find-group-id.png - :alt: An image illustrating how to find the ID of a group - -Once you have an ID, you can use it to create a `Group` or a `User` instance, which will allow you to do all sorts of things. To do this, you need a valid, logged in session:: - - group = fbchat.Group(session=session, id="") - # Or for user threads - user = fbchat.User(session=session, id="") - -Just like threads, every message, poll, plan, attachment, action etc. you send or do on Facebook has a unique ID. - -Below is an example of using such a message ID to get a `Message` instance:: - - # Provide the thread the message was created in, and it's ID - message = fbchat.Message(thread=user, id="") - - -Fetching Information --------------------- - -Managing these ids yourself quickly becomes very cumbersome! Luckily, there are other, easier ways of getting `Group`/`User` instances. - -You would start by creating a `Client` instance, which is basically just a helper on top of `Session`, that will allow you to do various things:: - - client = fbchat.Client(session=session) - -Now, you could search for threads using `Client.search_for_threads`, or fetch a list of them using `Client.fetch_threads`:: - - # Fetch the 5 most likely search results - # Uses Facebook's search functions, you don't have to specify the whole name, first names will usually be enough - threads = list(client.search_for_threads("", limit=5)) - # Fetch the 5 most recent threads in your account - threads = list(client.fetch_threads(limit=5)) - -Note the `list` statements; this is because the methods actually return `generators `__. If you don't know what that means, don't worry, it is just something you can use to make your code faster later. - -The examples above will actually fetch `UserData`/`GroupData`, which are subclasses of `User`/`Group`. These model have extra properties, so you could for example print the names and ids of the fetched threads like this:: - - for thread in threads: - print(f"{thread.id}: {thread.name}") - -Once you have a thread, you can use that to fetch the messages therein:: - - for message in thread.fetch_messages(limit=20): - print(message.text) - - -Interacting with Threads ------------------------- - -Once you have a `User`/`Group` instance, you can do things on them as described in `ThreadABC`, since they are subclasses of that. - -Some functionality, like adding users to a `Group`, or blocking a `User`, logically only works the relevant threads, so see the full API documentation for that. - -With that out of the way, let's see some examples! - -The simplest way of interacting with a thread is by sending a message:: - - # Send a message to the user - message = user.send_text("test message") - -There are many types of messages you can send, see the full API documentation for more. - -Notice how we held on to the sent message? The return type i a `Message` instance, so you can interact with it afterwards:: - - # React to the message with the 😍 emoji - message.react("😍") - -Besides sending messages, you can also interact with threads in other ways. An example is to change the thread color:: - - # Will change the thread color to the default blue - thread.set_color("#0084ff") - - -Listening & Events ------------------- - -Now, we are finally at the point we have all been waiting for: Creating an automatic Facebook bot! - -To get started, you create the functions you want to call on certain events:: - - def my_function(event: fbchat.MessageEvent): - print(f"Message from {event.author.id}: {event.message.text}") - -Then you create a `fbchat.Listener` object:: - - listener = fbchat.Listener(session=session, chat_on=False, foreground=False) - -Which you can then use to receive events, and send them to your functions:: - - for event in listener.listen(): - if isinstance(event, fbchat.MessageEvent): - my_function(event) - -View the :ref:`examples` to see some more examples illustrating the event system. diff --git a/docs/make.bat b/docs/make.bat deleted file mode 100644 index 27f573b..0000000 --- a/docs/make.bat +++ /dev/null @@ -1,35 +0,0 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=. -set BUILDDIR=_build - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% - -:end -popd diff --git a/docs/spelling/fixes.txt b/docs/spelling/fixes.txt deleted file mode 100644 index 2c0351f..0000000 --- a/docs/spelling/fixes.txt +++ /dev/null @@ -1,3 +0,0 @@ -premade -todo -emoji diff --git a/docs/spelling/names.txt b/docs/spelling/names.txt deleted file mode 100644 index 6ec43dc..0000000 --- a/docs/spelling/names.txt +++ /dev/null @@ -1,3 +0,0 @@ -Facebook -GraphQL -GitHub diff --git a/docs/spelling/technical.txt b/docs/spelling/technical.txt deleted file mode 100644 index 9453d88..0000000 --- a/docs/spelling/technical.txt +++ /dev/null @@ -1,17 +0,0 @@ -iterables -iterable -mimetype -timestamp -metadata -spam -spammy -admin -admins -unsend -unsends -unmute -spritemap -online -inbox -subclassing -codebase diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index ed3d55b..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,64 +0,0 @@ -[tool.black] -line-length = 88 -target-version = ['py36', 'py37', 'py38'] - -[build-system] -requires = ["flit"] -build-backend = "flit.buildapi" - -[tool.flit.metadata] -module = "fbchat" -author = "Taehoon Kim" -author-email = "carpedm20@gmail.com" -maintainer = "Mads Marquart" -maintainer-email = "madsmtm@gmail.com" -home-page = "https://github.com/carpedm20/fbchat/" -requires = [ - "attrs>=19.1", - "requests~=2.19", - "beautifulsoup4~=4.0", - "paho-mqtt~=1.5", -] -description-file = "README.rst" -classifiers = [ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Intended Audience :: Information Technology", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - "Natural Language :: English", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Topic :: Communications :: Chat", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Internet :: WWW/HTTP :: Dynamic Content", - "Topic :: Software Development :: Libraries", - "Topic :: Software Development :: Libraries :: Python Modules", -] -requires-python = ">=3.5, <4.0" -keywords = "Facebook FB Messenger Library Chat Api Bot" -license = "BSD 3-Clause" - -[tool.flit.metadata.urls] -Documentation = "https://fbchat.readthedocs.io/" -Repository = "https://github.com/carpedm20/fbchat/" - -[tool.flit.metadata.requires-extra] -test = [ - "pytest>=4.3,<6.0", -] -docs = [ - "sphinx~=2.0", - "sphinxcontrib-spelling~=4.0", - "sphinx-autodoc-typehints~=1.10", -] -lint = [ - "black", -] diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 176f965..0000000 --- a/pytest.ini +++ /dev/null @@ -1,10 +0,0 @@ -[pytest] -xfail_strict = true -markers = - online: Online tests, that require a user account set up. Meant to be used \ - manually, to check whether Facebook has broken something. -addopts = - --strict - -m "not online" -testpaths = tests -filterwarnings = error