Added baseline for sphinx documentation and on2FACode
event
The docs are still very WIP, but they should be functional. Just execute `make html` in the docs folder, and you should be able to navigate to `/docs/_build/html` and view it in your browser
This commit is contained in:
18
examples/echobot.py
Normal file
18
examples/echobot.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from fbchat import log, Client
|
||||
|
||||
# Subclass fbchat.Client and override required methods
|
||||
class EchoBot(Client):
|
||||
def onMessage(self, mid, author_id, message, thread_id, thread_type, ts, metadata, msg):
|
||||
self.markAsDelivered(author_id, thread_id)
|
||||
self.markAsRead(author_id)
|
||||
|
||||
log.info("Message from {} in {} ({}): {}".format(author_id, thread_id, thread_type.name, message)))
|
||||
|
||||
# If you're not the author, echo
|
||||
if author_id != self.uid:
|
||||
self.sendMessage(message, thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
client = EchoBot("<email>", "<password>")
|
||||
client.listen()
|
8
examples/get.py
Normal file
8
examples/get.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# -*- 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
|
56
examples/keepbot.py
Normal file
56
examples/keepbot.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from fbchat import log, Client
|
||||
from fbchat.models import *
|
||||
|
||||
# Change this to your group id
|
||||
old_thread_id = '1234567890'
|
||||
|
||||
# Change these to match your liking
|
||||
old_color = ThreadColor.MESSENGER_BLUE
|
||||
old_emoji = '👍'
|
||||
old_title = 'Old school'
|
||||
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'
|
||||
}
|
||||
|
||||
class KeepBot(Client):
|
||||
def onColorChange(self, mid, author_id, new_color, thread_id, thread_type, ts, metadata, msg):
|
||||
if old_thread_id == thread_id and old_color != new_color:
|
||||
log.info("{} changed the thread color. It will be changed back".format(author_id))
|
||||
self.changeThreadColor(old_color, thread_id=thread_id)
|
||||
|
||||
def onEmojiChange(self, mid, author_id, new_emoji, thread_id, thread_type, ts, metadata, msg):
|
||||
if old_thread_id == thread_id and new_emoji != old_emoji:
|
||||
log.info("{} changed the thread emoji. It will be changed back".format(author_id))
|
||||
# Not currently possible in `fbchat`
|
||||
# self.changeThreadEmoji(old_emoji, thread_id=thread_id)
|
||||
|
||||
def onPeopleAdded(self, added_ids, author_id, thread_id, msg):
|
||||
if old_thread_id == thread_id and author_id != self.uid:
|
||||
log.info("{} got added. They will be removed".format(added_ids))
|
||||
for added_id in added_ids:
|
||||
self.removeUserFromGroup(added_id, thread_id=thread_id)
|
||||
|
||||
def onPersonRemoved(self, removed_id, author_id, thread_id, msg):
|
||||
# No point in trying to add ourself
|
||||
if old_thread_id == thread_id and removed_id != self.uid and author_id != self.uid:
|
||||
log.info("{} got removed. They will be re-added".format(removed_id))
|
||||
self.addUsersToGroup(removed_id, thread_id=thread_id)
|
||||
|
||||
def onTitleChange(self, mid, author_id, new_title, thread_id, thread_type, ts, metadata, msg):
|
||||
if old_thread_id == thread_id and old_title != new_title:
|
||||
log.info("{} changed the thread title. It will be changed back".format(author_id))
|
||||
self.changeGroupTitle(old_title, thread_id=thread_id)
|
||||
|
||||
def onNicknameChange(self, mid, author_id, changed_for, new_nickname, thread_id, thread_type, ts, metadata, msg):
|
||||
if old_thread_id == thread_id and changed_for in old_nicknames:
|
||||
log.info("{} changed {}'s' nickname. It will be changed back".format(author_id, changed_for))
|
||||
# Not currently possible in `fbchat`
|
||||
# self.changeNickname(old_nicknames[changed_for], changed_for, thread_id=thread_id, thread_type=thread_type)
|
||||
|
||||
client = KeepBot("<email>", "<password>")
|
||||
client.listen()
|
16
examples/removebot.py
Normal file
16
examples/removebot.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from fbchat import log, Client
|
||||
from fbchat.models import *
|
||||
|
||||
class RemoveBot(Client):
|
||||
def onMessage(self, mid, author_id, message, thread_id, thread_type, ts, metadata, msg):
|
||||
# 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)))
|
||||
self.removeUserFromGroup(user_id, thread_id=thread_id)
|
||||
else:
|
||||
log.info("Message from {} in {} ({}): {}".format(author_id, thread_id, thread_type.name, message)))
|
||||
|
||||
client = RemoveBot("<email>", "<password>")
|
||||
client.listen()
|
25
examples/send.py
Normal file
25
examples/send.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- 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