Removed deprecations and new event system, improved other things
Removed deprecations Removed new event system Added documentation for all events Added FAQ Changed Client.uid to Client.id Improved User model Prepared for support of pages
This commit is contained in:
12
examples/basic_usage.py
Normal file
12
examples/basic_usage.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from fbchat import Client
|
||||
from fbchat.models import *
|
||||
|
||||
client = Client('<email>', '<password>')
|
||||
|
||||
print('Own id: {}'.format(client.id))
|
||||
|
||||
client.sendMessage('Hi me!', thread_id=self.id, thread_type=ThreadType.USER)
|
||||
|
||||
client.logout()
|
@@ -3,42 +3,44 @@
|
||||
from fbchat import Client
|
||||
from fbchat.models import *
|
||||
|
||||
client = Client("<email>", "<password>")
|
||||
client = Client('<email>', '<password>')
|
||||
|
||||
# Fetches a list of all users you're currently chatting with, as `User` objects
|
||||
users = client.getAllUsers()
|
||||
users = client.fetchAllUsers()
|
||||
|
||||
print('user IDs: {}'.format(user.uid for user in users))
|
||||
print("user's names: {}".format(user.name for user in users))
|
||||
print("users' IDs: {}".format(user.uid for user in users))
|
||||
print("users' names: {}".format(user.name for user in users))
|
||||
|
||||
|
||||
# If we have a user id, we can use `getUserInfo` to fetch a `User` object
|
||||
user = client.getUserInfo('<user id>')
|
||||
user = client.fetchUserInfo('<user id>')['<user id>']
|
||||
# We can also query both mutiple users together, which returns list of `User` objects
|
||||
users = client.getUserInfo('<1st user id>', '<2nd user id>', '<3rd user id>')
|
||||
users = client.fetchUserInfo('<1st user id>', '<2nd user id>', '<3rd user id>')
|
||||
|
||||
print('User INFO: {}'.format(user))
|
||||
print("User's INFO: {}".format(users))
|
||||
print("user's name: {}".format(user.name))
|
||||
print("users' names: {}".format(users[k].name for k in users))
|
||||
|
||||
|
||||
# `getUsers` searches for the user and gives us a list of the results,
|
||||
# `searchForUsers` searches for the user and gives us a list of the results,
|
||||
# and then we just take the first one, aka. the most likely one:
|
||||
user = client.getUsers('<name of user>')[0]
|
||||
user = client.searchForUsers('<name of user>')[0]
|
||||
|
||||
print('user ID: {}'.format(user.uid))
|
||||
print("user's name: {}".format(user.name))
|
||||
print("user's photo: {}".format(user.photo))
|
||||
print("Is user client's friend: {}".format(user.is_friend))
|
||||
|
||||
|
||||
# Fetches a list of all threads you're currently chatting with
|
||||
threads = client.getThreadList()
|
||||
# Fetches a list of the 20 top threads you're currently chatting with
|
||||
threads = client.fetchThreadList()
|
||||
# Fetches the next 10 threads
|
||||
threads += client.getThreadList(start=20, length=10)
|
||||
threads += client.fetchThreadList(offset=20, amount=10)
|
||||
|
||||
print("Thread's INFO: {}".format(threads))
|
||||
|
||||
|
||||
# Gets the last 10 messages sent to the thread
|
||||
messages = client.getThreadInfo(last_n=10, thread_id='<thread id>', thread_type=ThreadType)
|
||||
messages = client.fetchThreadMessages(offset=0, amount=10, thread_id='<thread id>', thread_type=ThreadType)
|
||||
# Since the message come in reversed order, reverse them
|
||||
messages.reverse()
|
||||
|
||||
|
@@ -7,10 +7,11 @@ class RemoveBot(Client):
|
||||
def onMessage(self, author_id, message, thread_id, thread_type, **kwargs):
|
||||
# We can only kick people from group chats, so no need to try if it's a user chat
|
||||
if message == 'Remove me!' and thread_type == ThreadType.GROUP:
|
||||
log.info("{} will be removed from {}".format(author_id, thread_id))
|
||||
log.info('{} will be removed from {}'.format(author_id, thread_id))
|
||||
self.removeUserFromGroup(author_id, thread_id=thread_id)
|
||||
else:
|
||||
log.info("Message from {} in {} ({}): {}".format(author_id, thread_id, thread_type.name, message))
|
||||
# Sends the data to the inherited onMessage, so that we can still see when a message is recieved
|
||||
super(type(self), self).onMessage(author_id=author_id, message=message, thread_id=thread_id, thread_type=thread_type, **kwargs)
|
||||
|
||||
client = RemoveBot("<email>", "<password>")
|
||||
client.listen()
|
||||
|
Reference in New Issue
Block a user