Fix logging
- Following advice here: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library - Renamed the logger: client -> fbchat - Remove logging_level init parameter from Client - Use print instead of log.info in examples
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from fbchat import log, Client
|
||||
from fbchat import Client
|
||||
|
||||
# Subclass fbchat.Client and override required methods
|
||||
class EchoBot(Client):
|
||||
@@ -6,7 +6,7 @@ class EchoBot(Client):
|
||||
self.markAsDelivered(thread_id, message_object.uid)
|
||||
self.markAsRead(thread_id)
|
||||
|
||||
log.info("{} from {} in {}".format(message_object, thread_id, thread_type.name))
|
||||
print("{} from {} in {}".format(message_object, thread_id, thread_type.name))
|
||||
|
||||
# If you're not the author, echo
|
||||
if author_id != self.uid:
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from fbchat import log, Client
|
||||
from fbchat import Client
|
||||
from fbchat.models import *
|
||||
|
||||
# Change this to your group id
|
||||
@@ -19,21 +19,21 @@ old_nicknames = {
|
||||
class KeepBot(Client):
|
||||
def onColorChange(self, author_id, new_color, thread_id, thread_type, **kwargs):
|
||||
if old_thread_id == thread_id and old_color != new_color:
|
||||
log.info(
|
||||
print(
|
||||
"{} changed the thread color. It will be changed back".format(author_id)
|
||||
)
|
||||
self.changeThreadColor(old_color, thread_id=thread_id)
|
||||
|
||||
def onEmojiChange(self, author_id, new_emoji, thread_id, thread_type, **kwargs):
|
||||
if old_thread_id == thread_id and new_emoji != old_emoji:
|
||||
log.info(
|
||||
print(
|
||||
"{} changed the thread emoji. It will be changed back".format(author_id)
|
||||
)
|
||||
self.changeThreadEmoji(old_emoji, thread_id=thread_id)
|
||||
|
||||
def onPeopleAdded(self, added_ids, author_id, thread_id, **kwargs):
|
||||
if old_thread_id == thread_id and author_id != self.uid:
|
||||
log.info("{} got added. They will be removed".format(added_ids))
|
||||
print("{} got added. They will be removed".format(added_ids))
|
||||
for added_id in added_ids:
|
||||
self.removeUserFromGroup(added_id, thread_id=thread_id)
|
||||
|
||||
@@ -44,12 +44,12 @@ class KeepBot(Client):
|
||||
and removed_id != self.uid
|
||||
and author_id != self.uid
|
||||
):
|
||||
log.info("{} got removed. They will be re-added".format(removed_id))
|
||||
print("{} got removed. They will be re-added".format(removed_id))
|
||||
self.addUsersToGroup(removed_id, thread_id=thread_id)
|
||||
|
||||
def onTitleChange(self, author_id, new_title, thread_id, thread_type, **kwargs):
|
||||
if old_thread_id == thread_id and old_title != new_title:
|
||||
log.info(
|
||||
print(
|
||||
"{} changed the thread title. It will be changed back".format(author_id)
|
||||
)
|
||||
self.changeThreadTitle(
|
||||
@@ -64,7 +64,7 @@ class KeepBot(Client):
|
||||
and changed_for in old_nicknames
|
||||
and old_nicknames[changed_for] != new_nickname
|
||||
):
|
||||
log.info(
|
||||
print(
|
||||
"{} changed {}'s' nickname. It will be changed back".format(
|
||||
author_id, changed_for
|
||||
)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from fbchat import log, Client
|
||||
from fbchat import Client
|
||||
from fbchat.models import *
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ 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))
|
||||
print("{} 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