More documentation work, changed addUsersToGroup
back to taking a list of user IDs
Created new README, and finished `intro`
This commit is contained in:
50
examples/fetch.py
Normal file
50
examples/fetch.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from fbchat import Client
|
||||
from fbchat.models import *
|
||||
|
||||
client = Client("<email>", "<password>")
|
||||
|
||||
# Fetches a list of all users you're currently chatting with, as `User` objects
|
||||
users = client.getAllUsers()
|
||||
|
||||
print('user IDs: {}'.format(user.uid for user in users))
|
||||
print("user's 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>')
|
||||
# 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>')
|
||||
|
||||
print('User INFO: {}'.format(user))
|
||||
print("User's INFO: {}".format(users))
|
||||
|
||||
|
||||
# `getUsers` 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]
|
||||
|
||||
print('user ID: {}'.format(user.uid))
|
||||
print("user's name: {}".format(user.name))
|
||||
|
||||
|
||||
# Fetches a list of all threads you're currently chatting with
|
||||
threads = client.getThreadList()
|
||||
# Fetches the next 10 threads
|
||||
threads += client.getThreadList(start=20, length=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)
|
||||
# Since the message come in reversed order, reverse them
|
||||
messages.reverse()
|
||||
|
||||
# Prints the content of all the messages
|
||||
for message in messages:
|
||||
print(message.body)
|
||||
|
||||
|
||||
# Here should be an example of `getUnread`
|
@@ -1,8 +0,0 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from fbchat import Client
|
||||
from fbchat.models import *
|
||||
|
||||
client = Client("<email>", "<password>")
|
||||
|
||||
# This should show example usage of getAllUsers, getUsers, getUserInfo, getThreadInfo, getThreadList and getUnread
|
55
examples/interract.py
Normal file
55
examples/interract.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from fbchat import Client
|
||||
from fbchat.models import *
|
||||
|
||||
client = Client("<email>", "<password>")
|
||||
|
||||
thread_id = '1234567890'
|
||||
thread_type = ThreadType.GROUP
|
||||
|
||||
# Will send a message to the thread
|
||||
client.sendMessage('<message>', thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# Will send the default `like` emoji
|
||||
client.sendEmoji(emoji=None, size=EmojiSize.LARGE, thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# Will send the emoji `👍`
|
||||
client.sendEmoji(emoji='👍', size=EmojiSize.LARGE, thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# Will send the image located at `<image path>`
|
||||
client.sendLocalImage('<image path>', message='This is a local image', thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# Will download the image at the url `<image url>`, and then send it
|
||||
client.sendRemoteImage('<image url>', message='This is a remote image', thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
|
||||
# Only do these actions if the thread is a group
|
||||
if thread_type == ThreadType.GROUP:
|
||||
# Will remove the user with ID `<user id>` from the thread
|
||||
client.removeUserFromGroup('<user id>', thread_id=thread_id)
|
||||
|
||||
# Will add the user with ID `<user id>` to the thread
|
||||
client.addUsersToGroup('<user id>', thread_id=thread_id)
|
||||
|
||||
# Will add the users with IDs `<1st user id>`, `<2nd user id>` and `<3th user id>` to the thread
|
||||
client.addUsersToGroup(['<1st user id>', '<2nd user id>', '<3rd user id>'], thread_id=thread_id)
|
||||
|
||||
|
||||
# Will change the nickname of the user `<user_id>` to `<new nickname>`
|
||||
client.changeNickname('<new nickname>', '<user id>', thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# Will change the title of the thread to `<title>`
|
||||
client.changeThreadTitle('<title>', thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# Will set the typing status of the thread to `TYPING`
|
||||
client.setTypingStatus(TypingStatus.TYPING, thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# Will change the thread color to `MESSENGER_BLUE`
|
||||
client.changeThreadColor(ThreadColor.MESSENGER_BLUE, thread_id=thread_id)
|
||||
|
||||
# Will change the thread emoji to `👍`
|
||||
client.changeThreadEmoji('👍', thread_id=thread_id)
|
||||
|
||||
# Will react to a message with a 😍 emoji
|
||||
client.reactToMessage('<message id>', MessageReaction.LOVE)
|
@@ -9,12 +9,12 @@ old_thread_id = '1234567890'
|
||||
# Change these to match your liking
|
||||
old_color = ThreadColor.MESSENGER_BLUE
|
||||
old_emoji = '👍'
|
||||
old_title = 'Old school'
|
||||
old_title = 'Old group chat name'
|
||||
old_nicknames = {
|
||||
'12345678901': 'Old School user nr. 1',
|
||||
'12345678902': 'Old School user nr. 2',
|
||||
'12345678903': 'Old School user nr. 3',
|
||||
'12345678904': 'Old School user nr. 4'
|
||||
'12345678901': "User nr. 1's nickname",
|
||||
'12345678902': "User nr. 2's nickname",
|
||||
'12345678903': "User nr. 3's nickname",
|
||||
'12345678904': "User nr. 4's nickname"
|
||||
}
|
||||
|
||||
class KeepBot(Client):
|
||||
|
@@ -1,25 +0,0 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from fbchat import Client
|
||||
from fbchat.models import *
|
||||
|
||||
client = Client("<email>", "<password>")
|
||||
|
||||
# Change these to match your thread
|
||||
thread_id = '1234567890'
|
||||
thread_type = ThreadType.GROUP # Or ThreadType.USER
|
||||
|
||||
# This will send a message to the thread
|
||||
client.sendMessage('Hey there', thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# This will send the default emoji
|
||||
client.sendEmoji(emoji=None, size=EmojiSize.LARGE, thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# This will send the emoji `👍`
|
||||
client.sendEmoji(emoji='👍', size=EmojiSize.LARGE, thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# This will send the image called `image.png`
|
||||
client.sendLocalImage('image.png', message='This is a local image', thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# This will send the image at the url `https://example.com/image.png`
|
||||
client.sendRemoteImage('https://example.com/image.png', message='This is a remote image', thread_id=thread_id, thread_type=thread_type)
|
Reference in New Issue
Block a user