Format strings using black
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
from fbchat import Client
|
||||
from fbchat.models import *
|
||||
|
||||
client = Client('<email>', '<password>')
|
||||
client = Client("<email>", "<password>")
|
||||
|
||||
print('Own id: {}'.format(client.uid))
|
||||
print("Own id: {}".format(client.uid))
|
||||
|
||||
client.send(Message(text='Hi me!'), thread_id=client.uid, thread_type=ThreadType.USER)
|
||||
client.send(Message(text="Hi me!"), thread_id=client.uid, thread_type=ThreadType.USER)
|
||||
|
||||
client.logout()
|
||||
|
@@ -3,7 +3,7 @@
|
||||
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.fetchAllUsers()
|
||||
@@ -13,9 +13,9 @@ print("users' names: {}".format([user.name for user in users]))
|
||||
|
||||
|
||||
# If we have a user id, we can use `fetchUserInfo` to fetch a `User` object
|
||||
user = client.fetchUserInfo('<user id>')['<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.fetchUserInfo('<1st user id>', '<2nd user id>', '<3rd user id>')
|
||||
users = client.fetchUserInfo("<1st user id>", "<2nd user id>", "<3rd user id>")
|
||||
|
||||
print("user's name: {}".format(user.name))
|
||||
print("users' names: {}".format([users[k].name for k in users]))
|
||||
@@ -23,9 +23,9 @@ print("users' names: {}".format([users[k].name for k in users]))
|
||||
|
||||
# `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.searchForUsers('<name of user>')[0]
|
||||
user = client.searchForUsers("<name of user>")[0]
|
||||
|
||||
print('user ID: {}'.format(user.uid))
|
||||
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))
|
||||
@@ -40,7 +40,7 @@ print("Threads: {}".format(threads))
|
||||
|
||||
|
||||
# Gets the last 10 messages sent to the thread
|
||||
messages = client.fetchThreadMessages(thread_id='<thread id>', limit=10)
|
||||
messages = client.fetchThreadMessages(thread_id="<thread id>", limit=10)
|
||||
# Since the message come in reversed order, reverse them
|
||||
messages.reverse()
|
||||
|
||||
@@ -50,13 +50,13 @@ for message in messages:
|
||||
|
||||
|
||||
# If we have a thread id, we can use `fetchThreadInfo` to fetch a `Thread` object
|
||||
thread = client.fetchThreadInfo('<thread id>')['<thread id>']
|
||||
thread = client.fetchThreadInfo("<thread id>")["<thread id>"]
|
||||
print("thread's name: {}".format(thread.name))
|
||||
print("thread's type: {}".format(thread.type))
|
||||
|
||||
|
||||
# `searchForThreads` searches works like `searchForUsers`, but gives us a list of threads instead
|
||||
thread = client.searchForThreads('<name of thread>')[0]
|
||||
thread = client.searchForThreads("<name of thread>")[0]
|
||||
print("thread's name: {}".format(thread.name))
|
||||
print("thread's type: {}".format(thread.type))
|
||||
|
||||
|
@@ -5,11 +5,11 @@ from fbchat.models import *
|
||||
|
||||
client = Client("<email>", "<password>")
|
||||
|
||||
thread_id = '1234567890'
|
||||
thread_id = "1234567890"
|
||||
thread_type = ThreadType.GROUP
|
||||
|
||||
# Will send a message to the thread
|
||||
client.send(Message(text='<message>'), thread_id=thread_id, thread_type=thread_type)
|
||||
client.send(Message(text="<message>"), thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# Will send the default `like` emoji
|
||||
client.send(
|
||||
@@ -18,14 +18,14 @@ client.send(
|
||||
|
||||
# Will send the emoji `👍`
|
||||
client.send(
|
||||
Message(text='👍', emoji_size=EmojiSize.LARGE),
|
||||
Message(text="👍", emoji_size=EmojiSize.LARGE),
|
||||
thread_id=thread_id,
|
||||
thread_type=thread_type,
|
||||
)
|
||||
|
||||
# Will send the sticker with ID `767334476626295`
|
||||
client.send(
|
||||
Message(sticker=Sticker('767334476626295')),
|
||||
Message(sticker=Sticker("767334476626295")),
|
||||
thread_id=thread_id,
|
||||
thread_type=thread_type,
|
||||
)
|
||||
@@ -33,7 +33,7 @@ client.send(
|
||||
# Will send a message with a mention
|
||||
client.send(
|
||||
Message(
|
||||
text='This is a @mention', mentions=[Mention(thread_id, offset=10, length=8)]
|
||||
text="This is a @mention", mentions=[Mention(thread_id, offset=10, length=8)]
|
||||
),
|
||||
thread_id=thread_id,
|
||||
thread_type=thread_type,
|
||||
@@ -41,16 +41,16 @@ client.send(
|
||||
|
||||
# Will send the image located at `<image path>`
|
||||
client.sendLocalImage(
|
||||
'<image path>',
|
||||
message=Message(text='This is a local image'),
|
||||
"<image path>",
|
||||
message=Message(text="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=Message(text='This is a remote image'),
|
||||
"<image url>",
|
||||
message=Message(text="This is a remote image"),
|
||||
thread_id=thread_id,
|
||||
thread_type=thread_type,
|
||||
)
|
||||
@@ -59,24 +59,24 @@ client.sendRemoteImage(
|
||||
# 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)
|
||||
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)
|
||||
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
|
||||
["<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
|
||||
"<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)
|
||||
client.changeThreadTitle("<title>", thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
# Will set the typing status of the thread to `TYPING`
|
||||
client.setTypingStatus(
|
||||
@@ -87,7 +87,7 @@ client.setTypingStatus(
|
||||
client.changeThreadColor(ThreadColor.MESSENGER_BLUE, thread_id=thread_id)
|
||||
|
||||
# Will change the thread emoji to `👍`
|
||||
client.changeThreadEmoji('👍', thread_id=thread_id)
|
||||
client.changeThreadEmoji("👍", thread_id=thread_id)
|
||||
|
||||
# Will react to a message with a 😍 emoji
|
||||
client.reactToMessage('<message id>', MessageReaction.LOVE)
|
||||
client.reactToMessage("<message id>", MessageReaction.LOVE)
|
||||
|
@@ -4,17 +4,17 @@ from fbchat import log, Client
|
||||
from fbchat.models import *
|
||||
|
||||
# Change this to your group id
|
||||
old_thread_id = '1234567890'
|
||||
old_thread_id = "1234567890"
|
||||
|
||||
# Change these to match your liking
|
||||
old_color = ThreadColor.MESSENGER_BLUE
|
||||
old_emoji = '👍'
|
||||
old_title = 'Old group chat name'
|
||||
old_emoji = "👍"
|
||||
old_title = "Old group chat name"
|
||||
old_nicknames = {
|
||||
'12345678901': "User nr. 1's nickname",
|
||||
'12345678902': "User nr. 2's nickname",
|
||||
'12345678903': "User nr. 3's nickname",
|
||||
'12345678904': "User nr. 4's nickname",
|
||||
"12345678901": "User nr. 1's nickname",
|
||||
"12345678902": "User nr. 2's nickname",
|
||||
"12345678903": "User nr. 3's nickname",
|
||||
"12345678904": "User nr. 4's nickname",
|
||||
}
|
||||
|
||||
|
||||
|
@@ -7,8 +7,8 @@ from fbchat.models import *
|
||||
class RemoveBot(Client):
|
||||
def onMessage(self, author_id, message_object, 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_object.text == 'Remove me!' and thread_type == ThreadType.GROUP:
|
||||
log.info('{} will be removed from {}'.format(author_id, thread_id))
|
||||
if message_object.text == "Remove me!" and thread_type == ThreadType.GROUP:
|
||||
log.info("{} will be removed from {}".format(author_id, thread_id))
|
||||
self.removeUserFromGroup(author_id, thread_id=thread_id)
|
||||
else:
|
||||
# Sends the data to the inherited onMessage, so that we can still see when a message is recieved
|
||||
|
Reference in New Issue
Block a user