Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0 dev #666

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
44 changes: 0 additions & 44 deletions docs/api.rst

This file was deleted.

4 changes: 4 additions & 0 deletions docs/api/base.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Base class
==========

.. autoclass:: Base()
4 changes: 4 additions & 0 deletions docs/api/get.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Retrieving information
======================

.. autoclass:: Get(Base)
16 changes: 16 additions & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
API
===

.. toctree::

base
get
listener
message_management
search
send
thread_control
thread_interraction
thread_options

models
4 changes: 4 additions & 0 deletions docs/api/listener.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Event Listening
===============

.. autoclass:: Listener(Base)
4 changes: 4 additions & 0 deletions docs/api/message_management.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Management of Messages
======================

.. autoclass:: MessageManagement(Listener)
5 changes: 5 additions & 0 deletions docs/api/models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Various Data Models
===================

.. automodule:: fbchat.models
:undoc-members:
4 changes: 4 additions & 0 deletions docs/api/search.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Searching for information
=========================

.. autoclass:: Search(Base)
4 changes: 4 additions & 0 deletions docs/api/send.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Sending messages
================

.. autoclass:: Send(Listener)
4 changes: 4 additions & 0 deletions docs/api/thread_control.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Controlling Threads
===================

.. autoclass:: ThreadControl(Listener)
4 changes: 4 additions & 0 deletions docs/api/thread_interraction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Interraction with Threads
=========================

.. autoclass:: ThreadInterraction(Listener)
4 changes: 4 additions & 0 deletions docs/api/thread_options.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Configuring Thread Options
==========================

.. autoclass:: ThreadOptions(Base)
18 changes: 13 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import sys
sys.path.insert(0, os.path.abspath('..'))

import fbchat
import tests
from fbchat import __copyright__, __author__, __version__, __description__
from fbchat import __copyright__, __author__, __version__, __description__ # noqa


# -- General configuration ------------------------------------------------
Expand All @@ -39,7 +37,8 @@
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.viewcode'
'sphinx.ext.viewcode',
'sphinx.ext.napoleon'
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -187,5 +186,14 @@

html_show_sphinx = False
html_show_sourcelink = False
autoclass_content = 'init'
autoclass_content = 'class'
autodoc_member_order = 'bysource'
autodoc_default_flags = ['members']
html_short_title = description
napoleon_numpy_docstring = False
napoleon_include_init_with_doc = True
napoleon_use_rtype = False
rst_prolog = '''
.. module:: fbchat
'''
default_role = 'class'
9 changes: 4 additions & 5 deletions docs/examples.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.. highlight:: python
.. _examples:

Examples
Expand Down Expand Up @@ -28,23 +27,23 @@ Fetching Information

This will show the different ways of fetching information about users and threads

.. literalinclude:: ../examples/fetch.py
.. literalinclude:: ../examples/retrieve.py


Echobot
-------

This will reply to any message with the same message

.. literalinclude:: ../examples/echobot.py
.. literalinclude:: ../examples/echo_bot.py


Remove Bot
----------

This will remove a user from a group if they write the message `Remove me!`

.. literalinclude:: ../examples/removebot.py
.. literalinclude:: ../examples/remove_bot.py


"Prevent changes"-Bot
Expand All @@ -53,4 +52,4 @@ This will remove a user from a group if they write the message `Remove me!`
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
.. literalinclude:: ../examples/keep_bot.py
2 changes: 0 additions & 2 deletions docs/faq.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.. highlight:: python
.. module:: fbchat
.. _faq:

FAQ
Expand Down
4 changes: 1 addition & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.. highlight:: python
.. module:: fbchat
.. fbchat documentation master file, created by
sphinx-quickstart on Thu May 25 15:43:01 2017.
You can adapt this file completely to your liking, but it should at least
Expand Down Expand Up @@ -61,6 +59,6 @@ Overview
intro
examples
testing
api
api/index
todo
faq
2 changes: 0 additions & 2 deletions docs/intro.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.. highlight:: python
.. module:: fbchat
.. _intro:

Introduction
Expand Down
1 change: 0 additions & 1 deletion docs/testing.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.. highlight:: sh
.. module:: fbchat
.. _testing:

Testing
Expand Down
2 changes: 0 additions & 2 deletions docs/todo.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.. highlight:: python
.. module:: fbchat
.. _todo:

Todo
Expand Down
69 changes: 69 additions & 0 deletions examples/advanced_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: UTF-8 -*-

from fbchat import Client, Group, Message


class Bot(Client):

def on_message(self, message):
thread = message.thread

# Prevent the bot from answering the bot's own messages
if message in self.sent_messages:
return

# If the message-text contains the letters 'admin'
if 'admin' in message.text.lower():
# Send various messages, based on the thread and the admin-status
if not isinstance(thread, Group):
self.send_text(thread, "This isn't a group, no admins here!")
elif self in thread.admins:
self.send_text(thread, "Yup, I'm an admin")
else:
self.send_text(thread, "Nope :'(")

# If the message-text contains the letters 'like'
if 'like' in message.text.lower():
# React to the message with a thumbs up
self.set_reaction(message, reaction='👍')

# If the message contains any images
if message.images:
# Send a message with the same images
self.send(thread, Message(images=message.images,
text='Here, have your images back!'))

# If the message contains a video
if message.video:
print(message.video, dict(message.video))

# If the message contains a file
if message.file:
print(message.file, dict(message.file))

# If you're mentioned
if self in (mention.thread for mention in message.mentions):
print('{.name} tagged me!'.format(message.author))

def on_user_removed(self, thread, actor, subject):
# If you're the subject or the actor
if self in [subject, actor]:
return

# If the subject is one of your friends
if subject.is_friend:
self.send_text(thread, 'Aww, this person was my friend!')

def on_users_added(self, thread, actor, subject):
# If you've been added to the thread
if subject == self:
self.send_text(thread, 'Thanks for adding me!')

def on_reaction_set(self, actor, message, old_reaction):
# If old_reaction is set, the reaction was changed
if old_reaction:
self.send_text(message.thread, 'Stop changing your reactions!')


bot = Bot("<email>", "<password>")
bot.listen()
14 changes: 9 additions & 5 deletions examples/basic_usage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# -*- coding: UTF-8 -*-

from fbchat import Client
from fbchat.models import *
# Imports Client, Thread, Group, Page, User and Message
from fbchat import *

# Login, using your email and credentials
client = Client('<email>', '<password>')

print('Own id: {}'.format(client.uid))
# Display data about you
print(client, vars(client))

client.send(Message(text='Hi me!'), thread_id=client.uid, thread_type=ThreadType.USER)
# Send a message to yourself
message = client.send_text(client, 'Hi me!')

client.logout()
# Display data about the sent message
print(message, vars(message))
22 changes: 22 additions & 0 deletions examples/echo_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: UTF-8 -*-

from fbchat import *


# Subclass the Client
class EchoBot(Client):

# And override the on_message method
def on_message(self, message):
# If the author isn't you
if message.author != self:
# Send the message back to the thread
self.send(message.thread, message)


# Login and initialize
bot = EchoBot("<email>", "<password>")

# Start listening for messages, and when a message is recieved, on_message
# will be called
bot.listen()
18 changes: 0 additions & 18 deletions examples/echobot.py

This file was deleted.

Loading