From 060f64b4d209fccd98166b4082ee3ce4c1e52aee Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 21 Jun 2018 15:29:52 +0200 Subject: [PATCH 01/10] Rename LICENSE.txt to LICENSE --- LICENSE.txt => LICENSE | 0 MANIFEST.in | 2 +- README.rst | 2 +- setup.cfg | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename LICENSE.txt => LICENSE (100%) diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE diff --git a/MANIFEST.in b/MANIFEST.in index 97e2ad3..9d5d250 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -include LICENSE.txt +include LICENSE include README.rst diff --git a/README.rst b/README.rst index 441e203..bb56c4a 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ fbchat: Facebook Chat (Messenger) for Python ============================================ .. image:: https://img.shields.io/badge/license-BSD-blue.svg - :target: LICENSE.txt + :target: https://github.com/carpedm20/fbchat/tree/master/LICENSE :alt: License: BSD .. image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6%20pypy-blue.svg diff --git a/setup.cfg b/setup.cfg index dbd7670..748ca86 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ name = fbchat version = attr: fbchat.__version__ license = BSD -license_file = LICENSE.txt +license_file = LICENSE author = Taehoon Kim author_email = carpedm20@gmail.com From c352a0d6986327ff35f122454dc4e8044e09e99e Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 21 Jun 2018 15:36:54 +0200 Subject: [PATCH 02/10] Modified license, so it's correctly recognised by `licensee` It _should_ be okay, since the modified version is less permissive The only real addition is `Neither the name of the copyright holder nor` --- LICENSE | 7 ++++--- README.rst | 2 +- fbchat/__init__.py | 4 ++-- setup.cfg | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index 73f2dde..321c518 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -New BSD License +BSD 3-Clause License Copyright (c) 2015, Taehoon Kim All rights reserved. @@ -13,8 +13,9 @@ modification, are permitted provided that the following conditions are met: this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -* The names of its contributors may not be used to endorse or promote products - derived from this software without specific prior written permission. +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE diff --git a/README.rst b/README.rst index bb56c4a..718a7f3 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ fbchat: Facebook Chat (Messenger) for Python .. image:: https://img.shields.io/badge/license-BSD-blue.svg :target: https://github.com/carpedm20/fbchat/tree/master/LICENSE - :alt: License: BSD + :alt: License: BSD 3-Clause .. image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6%20pypy-blue.svg :target: https://pypi.python.org/pypi/fbchat diff --git a/fbchat/__init__.py b/fbchat/__init__.py index 2b92a3f..8b048df 100644 --- a/fbchat/__init__.py +++ b/fbchat/__init__.py @@ -7,7 +7,7 @@ Facebook Chat (Messenger) for Python :copyright: (c) 2015 - 2018 by Taehoon Kim - :license: BSD, see LICENSE for more details. + :license: BSD 3-Clause, see LICENSE for more details. """ from __future__ import unicode_literals @@ -19,7 +19,7 @@ __version__ = '1.3.9' __description__ = 'Facebook Chat (Messenger) for Python' __copyright__ = 'Copyright 2015 - 2018 by Taehoon Kim' -__license__ = 'BSD' +__license__ = 'BSD 3-Clause' __author__ = 'Taehoon Kim; Moreels Pieter-Jan; Mads Marquart' __email__ = 'carpedm20@gmail.com' diff --git a/setup.cfg b/setup.cfg index 748ca86..b554b7b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] name = fbchat version = attr: fbchat.__version__ -license = BSD +license = BSD 3-Clause license_file = LICENSE author = Taehoon Kim From af3d385ff52775e1ed65c683ee728959dece3fea Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 21 Jun 2018 16:41:27 +0200 Subject: [PATCH 03/10] Add issue templates via. Github's `Create Issue Template` feature --- .github/ISSUE_TEMPLATE/bug-report.md | 34 ++++++++++++++++++ .github/ISSUE_TEMPLATE/bug_report.md | 35 +++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 19 ++++++++++ .../question---anything-else.md | 8 +++++ .github/ISSUE_TEMPLATE/question.md | 8 +++++ 5 files changed, 104 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/question---anything-else.md create mode 100644 .github/ISSUE_TEMPLATE/question.md diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000..9903544 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,34 @@ +--- +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 FBchatUserError('Login failed. Check email/password. (Failed on url: {})'.format(login_url)) +fbchat.models.FBchatUserError: 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/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..b735373 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,35 @@ +--- +name: Bug report +about: Create a report to help us improve + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..ac0c918 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,19 @@ +--- +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/.github/ISSUE_TEMPLATE/question---anything-else.md b/.github/ISSUE_TEMPLATE/question---anything-else.md new file mode 100644 index 0000000..89ccdc1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question---anything-else.md @@ -0,0 +1,8 @@ +--- +name: Question / Anything else +about: If you have a question about Facebook or fbchat, a meta-issue, or anything, + feel free to ask ;) + +--- + + diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 0000000..d5e735a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,8 @@ +--- +name: Question +about: If you have a question about Facebook or fbchat, a meta-issue, or anything, + feel free to ask ;) + +--- + + From 070a8cad159615b8eae604ad207fed3ff6ff8a1c Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 21 Jun 2018 16:52:21 +0200 Subject: [PATCH 04/10] Removed wrong templates --- .github/ISSUE_TEMPLATE/bug-report.md | 34 ------------- .github/ISSUE_TEMPLATE/bug_report.md | 51 +++++++++---------- .../question---anything-else.md | 8 --- .github/ISSUE_TEMPLATE/question.md | 8 --- 4 files changed, 25 insertions(+), 76 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug-report.md delete mode 100644 .github/ISSUE_TEMPLATE/question---anything-else.md delete mode 100644 .github/ISSUE_TEMPLATE/question.md diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md deleted file mode 100644 index 9903544..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 FBchatUserError('Login failed. Check email/password. (Failed on url: {})'.format(login_url)) -fbchat.models.FBchatUserError: 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/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b735373..9903544 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,35 +1,34 @@ --- name: Bug report -about: Create a report to help us improve +about: Create a report if you're having trouble with `fbchat` --- -**Describe the bug** -A clear and concise description of what the bug is. +## Description of the problem +Example: Logging in fails when the character `%` is in the password. A specific password that fails is `a_password_with_%` -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error +## Code to reproduce +```py +# Example code +from fbchat import Client +client = Client("[REDACTED_USERNAME]", "a_password_with_%") +``` -**Expected behavior** -A clear and concise description of what you expected to happen. +## 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 FBchatUserError('Login failed. Check email/password. (Failed on url: {})'.format(login_url)) +fbchat.models.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/login.php?login_attempt=1) +``` -**Screenshots** -If applicable, add screenshots to help explain your problem. +## Environment information +- Python version +- `fbchat` version +- If relevant, output from `$ python -m pip list` -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - -**Additional context** -Add any other context about the problem here. +If you have done any research, include that. +Make sure to redact all personal information. diff --git a/.github/ISSUE_TEMPLATE/question---anything-else.md b/.github/ISSUE_TEMPLATE/question---anything-else.md deleted file mode 100644 index 89ccdc1..0000000 --- a/.github/ISSUE_TEMPLATE/question---anything-else.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: Question / Anything else -about: If you have a question about Facebook or fbchat, a meta-issue, or anything, - feel free to ask ;) - ---- - - diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md deleted file mode 100644 index d5e735a..0000000 --- a/.github/ISSUE_TEMPLATE/question.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: Question -about: If you have a question about Facebook or fbchat, a meta-issue, or anything, - feel free to ask ;) - ---- - - From 540e530420e1a96468499820f9a13399a63622be Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 21 Jun 2018 17:11:46 +0200 Subject: [PATCH 05/10] Added `Contributor Covenant Code of Conduct` --- CODE_OF_CONDUCT | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 CODE_OF_CONDUCT diff --git a/CODE_OF_CONDUCT b/CODE_OF_CONDUCT new file mode 100644 index 0000000..1e2a33b --- /dev/null +++ b/CODE_OF_CONDUCT @@ -0,0 +1,75 @@ +Contributor Covenant Code of Conduct + +Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +education, socio-economic status, nationality, personal appearance, race, +religion, or sexual identity and orientation. + +Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + + +Examples of unacceptable behavior by participants include: + + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others’ private information, such as a physical or electronic +address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a +professional setting + + +Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at carpedm20@gmail.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project’s leadership. + +Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html From 71bf5e0e4f0627521d0ce32d5d3f852048a59cfb Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 21 Jun 2018 17:12:01 +0200 Subject: [PATCH 06/10] Added `CONTRIBUTING.rst` --- CONTRIBUTING.rst | 22 ++++++++++++++++++++++ MANIFEST.in | 1 + 2 files changed, 23 insertions(+) create mode 100644 CONTRIBUTING.rst diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 0000000..c6e0767 --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,22 @@ +Contributing to fbchat +====================== + +Thanks for reading this, all contributions are very much welcome! + +Please be aware that ``fbchat`` uses `Scemantic Versioning `__ +That means that if you're submitting a breaking change, it will probably take a while before it gets considered. + +In that case, you can point your PR to the ``2.0.0-dev`` branch, where the API is being properly developed. +Otherwise, just point it to ``master``. + +Testing Environment +------------------- + +The tests use `pytest `__, and to work they need two Facebook accounts, and a group thread between these. +To set these up, you should export the following environment variables: + +``client1_email``, ``client1_password``, ``client2_email``, ``client2_password`` and ``group_id`` + +If you're not able to do this, consider simply running ``pytest -m offline``. + +And if you're adding new functionality, if possible, make sure to create a new test for it. diff --git a/MANIFEST.in b/MANIFEST.in index 9d5d250..57c2977 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include LICENSE +include CONTRIBUTING.rst include README.rst From c2fb602bee34d59a7c6c8d863d836c88fd83f7ba Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 12 Jul 2018 17:42:34 +0200 Subject: [PATCH 07/10] Disabled travis pytest caching, now the tests should be pretty stable --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e2c1df..18166dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,10 @@ install: cache: pip: true - directories: - - .pytest_cache + # Pytest caching is disabled, since TravisCI instances have different public IPs. Facebook doesn't like that, + # and redirects you to the url `/checkpoint/block`, where you have to change the account's password + # directories: + # - .pytest_cache jobs: include: From 86a163e3370d16c5fc0c6d22d1995a6ad01354dc Mon Sep 17 00:00:00 2001 From: ThatAlexanderA <38069912+ThatAlexanderA@users.noreply.github.com> Date: Sat, 14 Jul 2018 12:40:42 +0200 Subject: [PATCH 08/10] Added create group def --- fbchat/client.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 5b5dbe1..221cbec 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1033,7 +1033,25 @@ class Client(object): is_gif = (mimetype == 'image/gif') image_id = self._uploadImage(image_path, open(image_path, 'rb'), mimetype) return self.sendImage(image_id=image_id, message=message, thread_id=thread_id, thread_type=thread_type, is_gif=is_gif) - + + def createGroup(self, message, person_ids=None): + """Creates a group with the given ids + :param person_ids: A list of people to create the group with. + :return: Returns error if couldn't create group, returns True when the group created. + """ + payload = { + "send" : "send", + "body": message, + "ids" : person_ids + } + r = self._post(self.req_url.CREATE_GROUP, payload) + if "send_success" in r.url: + log.debug("The group was created successfully!") + return True + else: + log.warning("Error while creating group") + return False + def addUsersToGroup(self, user_ids, thread_id=None): """ Adds users to a group. From 4993da727ab6f6bf836f38fa744bdaf5a1857b2a Mon Sep 17 00:00:00 2001 From: ThatAlexanderA <38069912+ThatAlexanderA@users.noreply.github.com> Date: Sat, 14 Jul 2018 12:42:18 +0200 Subject: [PATCH 09/10] Added create group url --- fbchat/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fbchat/utils.py b/fbchat/utils.py index d33a70f..2517459 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -125,6 +125,7 @@ class ReqUrl(object): EVENT_REMINDER = "https://www.facebook.com/ajax/eventreminder/create" MODERN_SETTINGS_MENU = "https://www.facebook.com/bluebar/modern_settings_menu/" REMOVE_FRIEND = "https://m.facebook.com/a/removefriend.php" + CREATE_GROUP = "https://m.facebook.com/messages/send/?icm=1" pull_channel = 0 From 4419c816f5b8c674e1a8fa43fe30e87bb783a098 Mon Sep 17 00:00:00 2001 From: Marco Gavelli Date: Sun, 15 Jul 2018 12:37:20 +0200 Subject: [PATCH 10/10] Fix 2FA for non english FB --- fbchat/client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 5b5dbe1..0ecb4a7 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -265,8 +265,7 @@ class Client(object): # Usually, 'Checkpoint' will refer to 2FA if ('checkpoint' in r.url - and ('enter security code to continue' in r.text.lower() - or 'enter login code to continue' in r.text.lower())): + and ('id="approvals_code"' in r.text.lower())): r = self._2FA(r) # Sometimes Facebook tries to show the user a "Save Device" dialog